-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: arguments dtype and parse_dates of read_csv does not work properly #57024
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
I confirm this on main branch >>> import pandas as pd
>>> print(pd.__version__)
3.0.0.dev0+163.g7281475054.dirty
>>> df = pd.DataFrame([{'name': 'foo','date': pd.Timestamp('2024-01-23T00:00:00Z')},
... {'name': 'bar','date': pd.Timestamp('2024-01-23T12:00:00Z')}])
>>> df.to_csv('test.csv', index=False)
>>> df_read = pd.read_csv('test.csv', dtype=str, parse_dates=['date'])
>>> print(df_read.dtypes)
name object
date object
dtype: object |
this looks like it's as-documented, you set a dtype for the entire dataframe and it was respected |
you can call closing then but thanks for the report |
Sure but The behavior has changed between 2.1.4 and 2.2.0, also parsing the date seem different (datetime vs date ?) import io
import pandas as pd
df = pd.read_csv(
io.StringIO("date,value\n2020-09-01,3\n"), dtype=object, parse_dates=["date"]
)
print(df)
print(df.dtypes) With pandas 2.1.4:
With pandas 2.2.0:
|
ah hadn't realised it was a regression, sorry - reopening then, running git bisect now |
this changed in #56047 |
I think this is correct to be honest, closing again then |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Reading a csv file and trying to specify both dtype and parse_dates will not parse the columns specified in parse_dates as dates, but strings instead
Expected Behavior
The code in the example should print:
name object
date datetime64[ns, UTC]
dtype: object
Installed Versions
INSTALLED VERSIONS
commit : f538741
python : 3.11.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Chinese (Simplified)_China.936
pandas : 2.2.0
numpy : 1.24.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.3
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.9.2
gcsfs : None
matplotlib : 3.7.2
numba : 0.58.0
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : 2.0.22
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: