You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: add option to disable field type inferencing #351
By now, you can force the type for a given column to be rows.fields.TextField. Add force_types parameter to the import function: rows.import_from_html(..., force_types={"field_name": rows.fields.TextField}).
Regarding to CLI: unfortunately not all CLI commands support forcing types. Some of them (csv2sqlite, pgimport) support passing a schema file via --schema, but this way you need specify all field types.
But there's a hack you could do: convert CSV to SQLite forcing text (or integer or whatever type you want) and then back to CSV. Like this:
Let's say you have a file test.csv with the following contents:
@aborruso if you think the field is being detected incorrectly (it was detected as float while you think it should be detected as int, for example), please open a new issue with data I can reproduce.
The last field is a string and it becomes a float.
I'm not able to create a PR and help you. But rows is really a great tool to convert almost everything to a usable table; my suggestion, my feature request is to add to the cli, an option like -I that disable every kind of field inferencing, that force all field to be text fields. Then it will be the user, after the first import, to apply the right casting.
Activity
turicas commentedon May 25, 2020
By now, you can force the type for a given column to be
rows.fields.TextField. Addforce_typesparameter to the import function:rows.import_from_html(..., force_types={"field_name": rows.fields.TextField}).aborruso commentedon May 26, 2020
Turicas thank you.
My request is related to command line use.
Is it possible to do it via cli?
Best regards
turicas commentedon May 26, 2020
Oh, sorry. Let's reopen it.
turicas commentedon May 26, 2020
Regarding to CLI: unfortunately not all CLI commands support forcing types. Some of them (
csv2sqlite,pgimport) support passing a schema file via--schema, but this way you need specify all field types.But there's a hack you could do: convert CSV to SQLite forcing text (or integer or whatever type you want) and then back to CSV. Like this:
Let's say you have a file
test.csvwith the following contents:Create the file
schema.csvwith:Then, execute the commands:
rows csv2sqlite --schemas=schema.csv test.csv test-temp.sqlite rows sqlite2csv test-temp.sqlite test test2.csv rm test-temp.sqliteand use
test2.csv.turicas commentedon May 26, 2020
@aborruso if you think the field is being detected incorrectly (it was detected as
floatwhile you think it should be detected asint, for example), please open a new issue with data I can reproduce.aborruso commentedon May 26, 2020
hi @turicas my input is this example HTML
If I run
rows convert input.html output.csvI haveThe last field is a string and it becomes a float.
I'm not able to create a PR and help you. But rows is really a great tool to convert almost everything to a usable table; my suggestion, my feature request is to add to the cli, an option like
-Ithat disable every kind of field inferencing, that force all field to be text fields. Then it will be the user, after the first import, to apply the right casting.Thank you