simonw / csvs-to-sqlite

Convert CSV files into a SQLite database
Apache License 2.0
878 stars 69 forks source link

Deprecated `iteritems()` attribute for Series #93

Open LuighiV opened 1 year ago

LuighiV commented 1 year ago

Executing with recent version of pandas (2.0.0), released on April 3, 2023, returns this error:

Loaded 1 dataframes
Traceback (most recent call last):
  File "/usr/local/bin/csvs-to-sqlite", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/csvs_to_sqlite/cli.py", line 253, in cli
    to_sql_with_foreign_keys(
  File "/usr/local/lib/python3.9/site-packages/csvs_to_sqlite/utils.py", line 330, in to_sql_with_foreign_keys
    create_sql, columns = get_create_table_sql(
  File "/usr/local/lib/python3.9/site-packages/csvs_to_sqlite/utils.py", line 287, in get_create_table_sql
    columns_and_types = df.dtypes.iteritems()
  File "/usr/local/lib/python3.9/site-packages/pandas/core/generic.py", line 5989, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'iteritems'

This is because a removed method for Series.

Removed deprecated Series.iteritems(), DataFrame.iteritems(), use obj.items instead (GH45321)

Reference: https://pandas.pydata.org/docs/whatsnew/v2.0.0.html#removal-of-prior-version-deprecations-changes

hcarter333 commented 1 year ago

We ran into both of these problems this morning as well. After trying unsuccessfully to change the code, (didn't see this issue till just now), we finally did

pip install pandas==1.5.0

and everything worked like a charm. Would an easier fix be to change the requieqments list for install from pandas>=1.0 to a version that is also <=1.5.0 ?

so... in setup.py we could have

"pandas>=1.0,<=1.5.0",