Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecospold_to_Leontief throws error OperationalError: duplicate column name: id #16

Open
michaelweinold opened this issue Oct 27, 2022 · 0 comments

Comments

@michaelweinold
Copy link

Attempting to run ecospold2matrix like so:

parser = e2m.Ecospold2Matrix(
    sys_dir = path_dir_ecoinvent_input,
    lci_dir = os.path.join(path_dir_ecoinvent_input, 'datasets'),
    project_name = e2m_project_name,
    characterisation_file = path_file_ecoinvent_characterisation,
    out_dir = path_dir_databases_pickle,
    positive_waste = False,
    nan2null = True
)
parser.ecospold_to_Leontief(
    fileformats = 'Pandas',
    with_absolute_flows=True
)

with Ecoinvent 3.8 returns the following error:

---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
Cell In [29], line 1
----> 1 parser.ecospold_to_Leontief(
      2     fileformats = 'Pandas',
      3     with_absolute_flows=True
      4 )

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/ecospold2matrix/ecospold2matrix.py:425, in Ecospold2Matrix.ecospold_to_Leontief(self, fileformats, with_absolute_flows, lci_check, rtol, atol, imax, characterisation_file, ardaidmatching_file)
    423 else:
    424     self.prepare_matching_load_parameters()
--> 425     self.process_inventory_elementary_flows()
    426     self.read_characterisation()
    427     self.populate_complementary_tables()

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/ecospold2matrix/ecospold2matrix.py:2803, in Ecospold2Matrix.process_inventory_elementary_flows(self)
   2801 # export to tmp SQL table
   2802 c = self.conn.cursor()
-> 2803 self.STR.to_sql('dirty_inventory',
   2804                 self.conn,
   2805                 index_label='id',
   2806                 if_exists='replace')
   2807 c.execute( """
   2808 INSERT INTO raw_inventory(id, name, comp, subcomp, unit, cas)
   2809 SELECT DISTINCT id, name, comp, subcomp, unit, cas
   2810 FROM dirty_inventory;
   2811 """)
   2813 self.clean_label('raw_inventory')

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/pandas/core/generic.py:2987, in NDFrame.to_sql(self, name, con, schema, if_exists, index, index_label, chunksize, dtype, method)
   2830 """
   2831 Write records stored in a DataFrame to a SQL database.
   2832 
   (...)
   2983 [(1,), (None,), (2,)]
   2984 """  # noqa:E501
   2985 from pandas.io import sql
-> 2987 return sql.to_sql(
   2988     self,
   2989     name,
   2990     con,
   2991     schema=schema,
   2992     if_exists=if_exists,
   2993     index=index,
   2994     index_label=index_label,
   2995     chunksize=chunksize,
   2996     dtype=dtype,
   2997     method=method,
   2998 )


File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/pandas/io/sql.py:695, in to_sql(frame, name, con, schema, if_exists, index, index_label, chunksize, dtype, method, engine, **engine_kwargs)
    690 elif not isinstance(frame, DataFrame):
    691     raise NotImplementedError(
    692         "'frame' argument should be either a Series or a DataFrame"
    693     )
--> 695 return pandas_sql.to_sql(
    696     frame,
    697     name,
    698     if_exists=if_exists,
    699     index=index,
    700     index_label=index_label,
    701     schema=schema,
    702     chunksize=chunksize,
    703     dtype=dtype,
    704     method=method,
    705     engine=engine,
    706     **engine_kwargs,
    707 )

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/pandas/io/sql.py:2187, in SQLiteDatabase.to_sql(self, frame, name, if_exists, index, index_label, schema, chunksize, dtype, method, **kwargs)
   2176             raise ValueError(f"{col} ({my_type}) not a string")
   2178 table = SQLiteTable(
   2179     name,
   2180     self,
   (...)
   2185     dtype=dtype,
   2186 )
-> 2187 table.create()
   2188 return table.insert(chunksize, method)

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/pandas/io/sql.py:838, in SQLTable.create(self)
    836         raise ValueError(f"'{self.if_exists}' is not valid for if_exists")
    837 else:
--> 838     self._execute_create()

File ~/miniconda3/envs/hybridization_bw_241/lib/python3.9/site-packages/pandas/io/sql.py:1871, in SQLiteTable._execute_create(self)
   1869 with self.pd_sql.run_transaction() as conn:
   1870     for stmt in self.table:
-> 1871         conn.execute(stmt)

OperationalError: duplicate column name: id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant