Comments (8)
I did some debugging. The below format is also failing and working fine in pandas < 2.0 versions.
csv_error = """ REF_DATE, VAL 20-05-2024, 120 20-May-2024, 100 """
When we pass
format='mixed'
it works as expected. I guess this would be the solution.
df_error = pd.read_csv(StringIO(csv_error)) df_error['REF_DATE'] = pd.to_datetime(df_error['REF_DATE'],format='mixed') df_error['NEXT_DATE'] = df_error['REF_DATE'] + pd.Timedelta(days=1)
Thanks, passing format='mixed' works fine.
I still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.
from pandas.
from pandas.
It is working fine for me. I am using the installed versions.
And the installed version is above 2.0?
from pandas.
Yes
My bad. I can reproduce the error. I am using pandas 2.2.0 Now.
from pandas.
I did some debugging. The below format is also failing and working fine in pandas < 2.0 versions.
csv_error = """
REF_DATE, VAL
20-05-2024, 120
20-May-2024, 100
"""
When we pass format='mixed'
it works as expected. I guess this would be the solution.
df_error = pd.read_csv(StringIO(csv_error)) df_error['REF_DATE'] = pd.to_datetime(df_error['REF_DATE'],format='mixed') df_error['NEXT_DATE'] = df_error['REF_DATE'] + pd.Timedelta(days=1)
from pandas.
Thanks for the report!
pandas should infer the datetime format correctly, using several entries when the format is ambiguous.
How many? And if they are all "May"?
I still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.
The breaking change was announced here: https://pandas.pydata.org/docs/dev/whatsnew/v2.0.0.html#datetimes-are-now-parsed-with-a-consistent-format
Thanks, passing format='mixed' works fine.
I'd recommend format="%d-%b-%Y"
instead, if the format is indeed not mixed.
It seems to me that inference is a guess, and sometimes guesses can be wrong. I'd recommend not relying on inference when possible.
from pandas.
Thanks for the report!
pandas should infer the datetime format correctly, using several entries when the format is ambiguous.
How many? And if they are all "May"?
I still think it is a bug or a regression though, possibly breaking old code bases, since the format really isn't mixed in this case.
The breaking change was announced here:
I'd recommendformat="%d-%b-%Y"
instead, if the format is indeed not mixed.It seems to me that inference is a guess, and sometimes guesses can be wrong. I'd recommend not relying on inference when possible.
Thanks, definitely not a bug then. I think your viewpoint as reasonable and this can be closed.
from pandas.
Not a bug.
from pandas.
Related Issues (20)
- BUG: Error when exporting empty DataFrame with MultiIndex on both axes to xlsx file
- BUG: inconsisntent construction results between `pd.array` and `pd.Series` for dtype=str HOT 9
- BUG: Boxplot does not apply colors set by Matplotlib rcParams for certain plot elements HOT 2
- Potential regression induced by PR #57588 HOT 1
- Pandas Extension: Drop Duplicated Columns HOT 2
- BUILD: error: metadata-generation-failed; ninja: build stopped: subcommand failed. HOT 5
- BUG: Pytest Version >=8.1 HOT 2
- BUG: Circle CI deprecates images
- DOC: SQL-style join conditions HOT 10
- BUG: fillna() doesn't work with `value=None` without method specified, but method is deprecated HOT 6
- BUG: to_sql does not get the correct dialect HOT 5
- ENH: interleave_columns function HOT 3
- QST: How to solve pandas (2.2.0) "FutureWarning: Downcasting behavior in `replace` is deprecated" on a Series? HOT 12
- BUG: ValueError with loc[] = (Regression 2.1.0) HOT 3
- ENH: Assign for pandas Series HOT 4
- BUG: Convertion fails for columns with datetime64[ms] HOT 3
- COMPAT: Utilize `copy` keyword in `__array__` HOT 1
- DEPR: groupby.idxmin/idxmax will all NA values HOT 2
- ENH: No longer always show hour, minute and second components for pd.Interval HOT 2
- BUG: `Timestamp.unit` should reflect changes in components after `Timestamp.replace` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandas.