{"record":{"id":"75ddeafa94390f98","repo":"deeplearning4j/deeplearning4j","slug":"cannot-convert-non-string-type","errorCode":null,"errorMessage":"Cannot convert non-string type","messagePattern":"Cannot convert non-string type","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"datavec/datavec-api/src/main/java/org/datavec/api/transform/transform/string/StringListToCategoricalSetTransform.java","lineNumber":94,"sourceCode":"    public Schema transform(Schema inputSchema) {\n\n        int colIdx = inputSchema.getIndexOfColumn(columnName);\n\n        List<ColumnMetaData> oldMeta = inputSchema.getColumnMetaData();\n        List<ColumnMetaData> newMeta = new ArrayList<>(oldMeta.size() + newColumnNames.size() - 1);\n        List<String> oldNames = inputSchema.getColumnNames();\n\n        Iterator<ColumnMetaData> typesIter = oldMeta.iterator();\n        Iterator<String> namesIter = oldNames.iterator();\n\n        int i = 0;\n        while (typesIter.hasNext()) {\n            ColumnMetaData t = typesIter.next();\n            String name = namesIter.next();\n            if (i++ == colIdx) {\n                //Replace String column with a set of binary/categorical columns\n                if (t.getColumnType() != ColumnType.String)\n                    throw new IllegalStateException(\"Cannot convert non-string type\");\n\n                for (int j = 0; j < newColumnNames.size(); j++) {\n                    ColumnMetaData meta = new CategoricalMetaData(newColumnNames.get(j), \"true\", \"false\");\n                    newMeta.add(meta);\n                }\n            } else {\n                newMeta.add(t);\n            }\n        }\n\n        return inputSchema.newSchema(newMeta);\n\n    }\n\n    @Override\n    public void setInputSchema(Schema inputSchema) {\n        this.inputSchema = inputSchema;\n        this.columnIdx = inputSchema.getIndexOfColumn(columnName);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/datavec/datavec-api/src/main/java/org/datavec/api/transform/transform/string/StringListToCategoricalSetTransform.java#L76-L112","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the column is declared as String (ColumnType.String) in the schema before this transform","Reorder the pipeline so this transform runs before any transform that changes the column type","Force the column type to String with a schema builder when constructing the Schema"],"exampleFix":"// before\nSchema schema = new Schema.Builder().addColumnInteger(\"tags\").build();\n// after\nSchema schema = new Schema.Builder().addColumnString(\"tags\").build();","handlingStrategy":"validation","validationCode":"if (schema.getMetaData(columnName).getColumnType() != ColumnType.String) throw new IllegalStateException(\"column must be String before StringListToCategoricalSetTransform\");","typeGuard":null,"tryCatchPattern":"try { transform.transform(schema); } catch (IllegalStateException e) { /* ensure column type is String, then rebuild schema */ }","preventionTips":["Inspect Schema column types before applying string transforms","Order transforms so type-changing transforms come after this one","Explicitly declare string columns when building Schemas"],"tags":["java","datavec","schema","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}