Skip to content

BUG: read_csv now errors with non-dict dtype and same-name columns #42022

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

Closed
3 tasks done
fiendish opened this issue Jun 15, 2021 · 0 comments · Fixed by #42030
Closed
3 tasks done

BUG: read_csv now errors with non-dict dtype and same-name columns #42022

fiendish opened this issue Jun 15, 2021 · 0 comments · Fixed by #42030
Assignees
Labels
Bug IO CSV read_csv, to_csv Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@fiendish
Copy link
Contributor

fiendish commented Jun 15, 2021

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

with open("test.csv", "w") as cf:
    cf.write("A,B,B\n1,1,1")

pandas.read_csv("test.csv", engine="python", dtype=str)  # used to work, no longer works
pandas.read_csv("test.csv", engine="python", dtype="str")  # used to work, no longer works

Now produces

  File ".../pandas/io/parsers/python_parser.py", line 427, in _infer_columns
    and self.dtype.get(old_col) is not None
AttributeError: 'str' object has no attribute 'get'

Problem description

Documentation for read_csv says that dtype may be a "type name or dict", but the new parser behavior demands a dict in this scenario.

I believe the bug was introduced in 76792f1

Expected Output

A dataframe using str dtypes

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2dd9e9b
python : 3.9.5.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.0rc1
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 56.2.0
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 3.0.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.20
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None

@fiendish fiendish added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 15, 2021
@phofl phofl added IO CSV read_csv, to_csv and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 15, 2021
@phofl phofl added this to the 1.3 milestone Jun 15, 2021
@phofl phofl self-assigned this Jun 15, 2021
@phofl phofl added the Regression Functionality that used to work in a prior pandas version label Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants