Giter Site home page Giter Site logo

Comments (8)

ffyring avatar ffyring commented on September 26, 2024 1

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.

santhoshbethi avatar santhoshbethi commented on September 26, 2024
Pandas_parse It is working fine for me. I am using the installed versions.

from pandas.

ffyring avatar ffyring commented on September 26, 2024

It is working fine for me. I am using the installed versions.

And the installed version is above 2.0?

from pandas.

santhoshbethi avatar santhoshbethi commented on September 26, 2024

Yes

My bad. I can reproduce the error. I am using pandas 2.2.0 Now.

from pandas.

santhoshbethi avatar santhoshbethi commented on September 26, 2024

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.

rhshadrach avatar rhshadrach commented on September 26, 2024

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.

cc @MarcoGorelli

from pandas.

ffyring avatar ffyring commented on September 26, 2024

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

cc @MarcoGorelli

Thanks, definitely not a bug then. I think your viewpoint as reasonable and this can be closed.

from pandas.

ffyring avatar ffyring commented on September 26, 2024

Not a bug.

from pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.