-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Change of behavior in casting of datetime-like types in MultiIndex #43091
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 @jgmarcel for the report. first bad commit: [545a942] BUG: Index([date]).astype("category").astype(object) roundtrip (#38552) I'll mark as a regression for now pending further investigation. Note that the |
#38552 was about round-tripping faithfully, so im inclined to think that reset_index should also roundtrip. @jgmarcel support for date objects in generally is spotty. Your best bet is to use datetime or Timestamp objects |
Agreed. Thank you for the good advice. Problem is data objects are all over our code, since anytime a DATE column is read via |
Hi guys, Do you believe it will be possible to get this fixed on version 1.3.4? I ask so I can better plan the effort of adapting our whole code base. Thank you. |
@jgmarcel would likely take a community pull request core can provide review might be quite tricky as date have very little support |
changing milestone to 1.3.5 |
pls look at the 1.3.x release notes. IIRC this was changed on purpose in response to unforced conversion (e.g. to datetime times) it was desirable to keep |
Hi @jreback,
As initially stated, «I fail to find in the What’s new page the reason for that change of behavior». Would you mind pointing it out to me? Anyway, the version policy clearly states that «API breaking changes should only occur in major releases», and «a deprecation path will be provided rather than an outright breaking change». Wouldn’t that be the case here, since we are talking about a breaking change that occurred between versions 1.2.5 and 1.3.0? |
in 1.2.5..
gives
and using the DataFrame from the OP
gives
whereas for a MultiIndex
gives
So the Index and MultiIndex constructors were inconsistent in the handling of object dtype arrays containing datetime objects in pandas 1.2.5.
The change of behavior in casting of datetime-like types in MultiIndex was done in #38552. Looking at the code changes in that PR, it is clear from the changed tests and comments added that this change was intentional. Unfortunately the release note added did not refer to changes in MultiIndex construction.
The policy also states
So the change in behavior could be considered a bug fix, since the MultiIndex constructor was inconsistent with the Index constructor and no further action. However, the policy also states
and
So, as an alternative, we could maybe restore the old behavior for 1.3.5 and add a deprecation of this behavior in 1.4 The only code change in #38552 was removing I guess we could maybe pass a convert_dates parameter through to the Categorical constructor from the MultiIndex constructor. @jbrockmendel wdyt? |
-1 on any change here not adding more complexity |
Hi @simonjayhawkins, Your thorough explanation is very much appreciated. I see now how the change in behavior was more of a bug fix than an API-breaking change. If I may pick your brain here, what do you believe would be the best way to achieve the pre-1.3 behavior, i.e. having Thank you. |
It's possible. Though we'd then have a breaking change for anyone relying on the 1.3 behavior.
I'd check |
That would be a great addition, yes. Thank you for that! However, I would also have to check for an inferred type of |
removing this issue from the 1.3.5 milestone as I think the consensus is for no action. |
@jbrockmendel if you can repsond to #43091 (comment) we can probably close this issue. Thanks. |
I'd go for |
Thank you very much! I was not aware of that function. Much appreciated. |
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
[Edited to inform a much simpler example.]
Output
The output below has been generated with pandas 1.3.0 or higher.
Expected Output
The output below has been generated with pandas 1.2.5.
Problem description
Starting from pandas 1.3.0, the observed behavior changed: in a
MultiIndex
creation,datetime.date
objects are not cast todatetime64
anymore. I fail to find in the What’s new page the reason for that change of behavior. Is it by design or a bug?Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: