-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: in read_excel for mangled columns only the original/first column dtype is correct, col.N is not parsed correctly #35211
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
Comments
Thanks @jeroenbrouwer for the report. without looking at the code, the coercion is probably being applied after the name mangling otherwise I would expected the following to raise
further investigation and PRs welcome. |
@simonjayhawkins can I check it out to see if I can fix? |
take |
Any luck so far @sharvanir ? |
hi @jeroenbrouwer looks like an issue with python's AST module, trying to find a workaround |
Simpler repro would be In [1]: import pandas as pd
In [2]: data = '''a,a\n1,1'''
In [3]: from io import StringIO
In [4]: df = pd.read_csv(StringIO(data), dtype={'a': str}, mangle_dupe_cols=True, engine='python')
In [9]: df
Out[9]:
a a.1
0 1 1
In [10]: df.dtypes
Out[10]:
a object
a.1 int64
dtype: object
If this behavior is changed at the PythonParser level, then I believe a corresponding change should happen in the CParserWrapper to remain consistent. |
sorry, got confused, it's not an ast issue. I will unassign this as I am unable to put in time due to professional commitments. |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
This requires setting up an excel file. Reproducible by setting 2 columns with equal headers like
a
and a row with values1
. Schematic:Then using:
Problem description
The problem is that column
a
is parsed as astr
and columna.1
is parsed as afloat64
.Expected Output
Both
a
anda.1
should be parsed asstr
, such that the assertion is passed.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 19.4.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.5
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 40.8.0
Cython : 0.29.20
pytest : 5.3.5
hypothesis : None
sphinx : 3.0.4
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : 4.5.1
html5lib : None
pymysql : None
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.1
IPython : 7.15.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.1
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : 1.2.9
numba : 0.50.0
The text was updated successfully, but these errors were encountered: