Open czpmango opened 4 years ago
Reproduce Pandas Version: v1.0.3 Here is a simplified code to reproduce it.
import pandas as pd
from arctern import GeoSeries
geo_s = GeoSeries(["POINT (9 0)","POLYGON ((1 1,1 2,2 2,1 1))"])
geo_df=pd.DataFrame({'val':geo_s})
from sqlalchemy import create_engine
engine = create_engine('sqlite://', echo=False)
geo_res1 = geo_df.to_sql('users', con=engine, if_exists='replace', index_label='id')
And it will crash at
File "pandas/_libs/lib.pyx", line 1127, in pandas._libs.lib._try_infer_map AttributeError: 'GeoDtype' object has no attribute 'base'
I check out pandas source code.
https://github.com/pandas-dev/pandas/blob/3adf3340453d6704d4a2cb47058214cc697a7d29/pandas/_libs/lib.pyx#L1120-L1130
The reason is pandas tries to infer data type for our GeoDtype
, by getattr('name' or 'kind' or 'base'). But class GeoDtype
does not have attribute 'base', then it crashed with AttributeError.
Describe the bug GeoSeries did not behave as expected when call to_sql.
To Reproduce My test code:
Expected behavior Expect the same results as the panda series when call to_sql.(pandas API : https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.htmll)