-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP, MAINT: upstream timedelta64 changes #25826
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25826 +/- ##
==========================================
- Coverage 91.3% 91.3% -0.01%
==========================================
Files 173 173
Lines 53004 53004
==========================================
- Hits 48397 48396 -1
- Misses 4607 4608 +1
Continue to review full report at Codecov.
|
This is great. We’ve had to implement patches to get the behavior you’re describing. Having that in numpy would let us rip out a bunch of code. |
80fbb63
to
34a2599
Compare
Just to summarize the only non-trivial change here: arr = np.array([0, 1, 2], dtype='m8[s]')
np.sum(arr) # works
arr[0] + arr[1] + arr[2] # works
# The following doesn't work--CPython must
# try to work with ints and cast back?
sum(arr)
# numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'add' input 0 from dtype('int64') to dtype('<m8[s]') with casting rule 'same_kind' I'll mirror that code block in the cognate NumPy casting PR to see if there are any concerns on their end. Not sure much can be done about the built-in |
Ah, @eric-wieser noted this is because
|
* draft changes to allow pandas test suite to pass with upstream NumPy prohibition on integer -> m8 casting
34a2599
to
b0abd46
Compare
thanks @tylerjereddy |
Background: In NumPy, I've been working to expand the operations supported for
np.timedelta64
(m8
) operands, adding support for modulus, floordiv and divmod operations. Historically, we've allowed casting from integer and bool types tom8
, which may seem innocent enough, but is arguably sloppy from a units perspective.Furthermore, with the introduction of new
m8
operation support, signed and unsigned integers are now able to interconvert in undesirable ways by sneaking through casts tom8
. So, core devs have suggested prohibiting casts from int / bool types tom8
. A prime concern here for me is the effect on downstream libraries that are known to heavily use datetime operations, likepandas
.Feedback: It would be great to get some feedback here from the
pandas
perspective. To get the discussion started, I've opened this PR with some perhaps crude changes that allow thepandas
master branch test suite to pass for me locally (via./test_fash.sh
anyway) with the NumPy feature branch linked above.How disruptive is this for you? Will we need to issue warnings / deprecate? Should we just not do this at all?