deeplearning4j/deeplearning4j · error · java.lang.IllegalStateException

Cannot convert non-string type

Error message

Cannot convert non-string type

What it means

During transform(Schema), the source column being replaced must have ColumnType.String. The transform tokenizes a string into a set of categories, so it throws IllegalStateException when the schema declares the column as any other type (e.g. Integer, Categorical, NDArray).

Solutions

  1. Ensure the column is declared as String (ColumnType.String) in the schema before this transform
  2. Reorder the pipeline so this transform runs before any transform that changes the column type
  3. Force the column type to String with a schema builder when constructing the Schema

Example fix

// before
Schema schema = new Schema.Builder().addColumnInteger("tags").build();
// after
Schema schema = new Schema.Builder().addColumnString("tags").build();
Defensive patterns

Strategy: validation

Validate before calling

if (schema.getMetaData(columnName).getColumnType() != ColumnType.String) throw new IllegalStateException("column must be String before StringListToCategoricalSetTransform");

Try / catch

try { transform.transform(schema); } catch (IllegalStateException e) { /* ensure column type is String, then rebuild schema */ }

Prevention

When it happens

Trigger: Applying StringListToCategoricalSetTransform to a schema whose target column (at colIdx / columnName) is not a String column, e.g. after a prior transform already converted it to Categorical.

Common situations: Pipeline ordering mistakes where a CalculateSortedRank or CategoricalToIntegerTransform ran first and changed the column type; schema inferred from CSV mis-detecting the column as numeric.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/75ddeafa94390f98. Report an issue: GitHub.

Appendix: source

Thrown at datavec/datavec-api/src/main/java/org/datavec/api/transform/transform/string/StringListToCategoricalSetTransform.java:94

    public Schema transform(Schema inputSchema) {

        int colIdx = inputSchema.getIndexOfColumn(columnName);

        List<ColumnMetaData> oldMeta = inputSchema.getColumnMetaData();
        List<ColumnMetaData> newMeta = new ArrayList<>(oldMeta.size() + newColumnNames.size() - 1);
        List<String> oldNames = inputSchema.getColumnNames();

        Iterator<ColumnMetaData> typesIter = oldMeta.iterator();
        Iterator<String> namesIter = oldNames.iterator();

        int i = 0;
        while (typesIter.hasNext()) {
            ColumnMetaData t = typesIter.next();
            String name = namesIter.next();
            if (i++ == colIdx) {
                //Replace String column with a set of binary/categorical columns
                if (t.getColumnType() != ColumnType.String)
                    throw new IllegalStateException("Cannot convert non-string type");

                for (int j = 0; j < newColumnNames.size(); j++) {
                    ColumnMetaData meta = new CategoricalMetaData(newColumnNames.get(j), "true", "false");
                    newMeta.add(meta);
                }
            } else {
                newMeta.add(t);
            }
        }

        return inputSchema.newSchema(newMeta);

    }

    @Override
    public void setInputSchema(Schema inputSchema) {
        this.inputSchema = inputSchema;
        this.columnIdx = inputSchema.getIndexOfColumn(columnName);

View on GitHub (pinned to 4c22ac5fe4)