-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Warn on ndarray[int] // timedelta #21036
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# cython: profile=False | ||
import collections | ||
import textwrap | ||
import warnings | ||
|
||
import sys | ||
cdef bint PY3 = (sys.version_info[0] >= 3) | ||
|
@@ -1188,6 +1190,15 @@ class Timedelta(_Timedelta): | |
if other.dtype.kind == 'm': | ||
# also timedelta-like | ||
return _broadcast_floordiv_td64(self.value, other, _rfloordiv) | ||
elif other.dtype.kind == 'i': | ||
# Backwards compatibility | ||
# GH-19761 | ||
msg = textwrap.dedent("""\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need the textwrap dedent if you put the string over multiple lines with implicit line continuation and string concatentation?
(I would personally find that a bit cleaner (also don't need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been burned so many times by implicit string concatenation across lines that I try to always avoid it in the hope that it'll be removed in Python 4 :) |
||
Floor division between integer array and Timedelta is | ||
deprecated. Use 'array // timedelta.value' instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you updated the example in the docs, maybe we should reflect this as well in the deprecation message? |
||
""") | ||
warnings.warn(msg, FutureWarning) | ||
return other // self.value | ||
raise TypeError('Invalid dtype {dtype} for ' | ||
'{op}'.format(dtype=other.dtype, | ||
op='__floordiv__')) | ||
|
@@ -1210,6 +1221,11 @@ class Timedelta(_Timedelta): | |
|
||
def __rmod__(self, other): | ||
# Naive implementation, room for optimization | ||
if hasattr(other, 'dtype') and other.dtype.kind == 'i': | ||
# TODO: Remove this check with backwards-compat shim | ||
# for integer / Timedelta is removed. | ||
raise TypeError("Invalid type {dtype} for " | ||
"{op}".format(dtype=other.dtype, op='__mod__')) | ||
return self.__rdivmod__(other)[1] | ||
|
||
def __divmod__(self, other): | ||
|
@@ -1219,6 +1235,11 @@ class Timedelta(_Timedelta): | |
|
||
def __rdivmod__(self, other): | ||
# Naive implementation, room for optimization | ||
if hasattr(other, 'dtype') and other.dtype.kind == 'i': | ||
# TODO: Remove this check with backwards-compat shim | ||
# for integer / Timedelta is removed. | ||
raise TypeError("Invalid type {dtype} for " | ||
"{op}".format(dtype=other.dtype, op='__mod__')) | ||
div = other // self | ||
return div, other - div * self | ||
|
||
|
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 would prob change this example to
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.
That makes sense for now (till
to_epoch
is ready).