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
BUG: Raise TypeError for float->timedelta promotion #16592
Conversation
@jorisvandenbossche in my branch on array-coercion, the one failure that is obviously related to the change (I expect most others are just due to the master branch/other issues), is a test like this:
Roughly, this test fails on my branch, because it currently promotes the other way around But, it also means you would get deprecation/future warnings in this type of array coercion... so the more general question is, whether we try to hack a more userfriendly warning (I did something similar in my start on string+numeric promotion), or whether we rather just rip off the band-aid here, considering that it is inconsistent and rather a bug to begin with. I am starting to favor that approach. With regard to array-coercion, it will just make things work (by returning object arrays), which does not seem terrible. And since it was an error previously, it seems unlikely that someone Edit: Ops, embarrassing, meant to ping @jbrockmendel on this one, since I think he is more into the datetime stuff... |
what are na_value and delta in the failing test(s)? |
Ah sorry, its |
Can you post a traceback? its hard to guess where lib.infer_dtype would go wrong here |
Oh, my bad again, but I guess that also proofs that pandas is just not dependend on NumPy here. The line that changes – that I am worried about – is the |
Sorry to be clear:
Is the current behaviour. This PR makes to always return |
This seems reasonable to me. It isnt obvious how that would break anything within pandas |
@anirudh2290 I think I would like to try and put this in. Maybe we should add a short release note just in case? |
6721d2a
to
657186b
Compare
@seberg done ! |
float->timedelta promotion will raise a TypeError | ||
------------------------------------------------- | ||
``np.promote_types("float32", "m8")`` and other float to timedelta promotion | ||
which used to return "m8" (timedelta) before, will now raise a TypeError. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we mention that it aligns it with np.promote_types("m8", "float32")
to ease peoples mind that it really should not be a large change. E.g. could also smuggle the word "consistently" in there ;). "Float and timedelta promotion consistently raises TypeError"?
But, this is also fine, so maybe I will just merge, or update myself later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks ! i have made a change to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Anirudh, lets put this in.
657186b
to
18f2008
Compare
Some strange test failure. I think they must be due to these changes being based on a not quite up-to-date branch. In any case nothing to worry about/unrelated to the change. |
Ehhh. My bad, I completely missed that this is also the (bad?) behaviour for all or some integers:
And I guess we can again simply change it without any real downstream impact, since ufuncs don't use promotion often to begin with, and even if, have the loops defined correctly for dtypes... |
aah, sure. let me open another pr for this ! |
Fixes #16566