-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: pd.DateOffset handle milliseconds #50020
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 8 commits
48d9dfa
65cd5da
f989674
b3a5ef1
37427dd
705d2d6
c1be7c6
1788491
ae0b529
64c9ee3
65015c8
ef7f118
b2b7473
c2cf081
3981b04
d80e780
27109a7
76fafe2
2ad8c60
2f913a8
8eb83d0
309e296
0d85a74
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 |
---|---|---|
|
@@ -314,7 +314,9 @@ cdef _determine_offset(kwds): | |
|
||
use_relativedelta = False | ||
if len(kwds_no_nanos) > 0: | ||
if any(k in _kwds_use_relativedelta for k in kwds_no_nanos): | ||
if "milliseconds" in kwds_no_nanos: | ||
offset = timedelta(**kwds_no_nanos) | ||
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 think this would still fail if a user passed 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. Yeah it fails. What should be done in cases like this? Both timedelta and relativedelta will throw an error. TBH I don't know how to fix this bug without trying to rework the entire function. Does it make sense to broaden up the scope of this issue? 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 think it would be okay to broaden the scope if all the existing tests pass. Generally I would imagine there should be checking that 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. This is what I had in mind. All tests in
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. Should I just open another PR with the rework linked above and close this one? 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 think it would be fine to just update this PR with your proposed refactor 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. could we do something like
(and something similar in the 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 added this code instead of the exception block (full code here) :
but it fails 2 tests in pandas/tests/tseries/offsets/test_offsets.py, both of which are meant to intentionally fail if we pass
However, I think the requirement is to have all the existing tests pass. There is still the case where we receive |
||
elif any(k in _kwds_use_relativedelta for k in kwds_no_nanos): | ||
if "millisecond" in kwds_no_nanos: | ||
raise NotImplementedError( | ||
"Using DateOffset to replace `millisecond` component in " | ||
|
@@ -1163,7 +1165,6 @@ cdef class RelativeDeltaOffset(BaseOffset): | |
|
||
def __init__(self, n=1, normalize=False, **kwds): | ||
BaseOffset.__init__(self, n, normalize) | ||
|
||
off, use_rd = _determine_offset(kwds) | ||
object.__setattr__(self, "_offset", off) | ||
object.__setattr__(self, "_use_relativedelta", use_rd) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -739,6 +739,10 @@ def test_eq(self): | |
|
||
assert DateOffset(milliseconds=3) != DateOffset(milliseconds=7) | ||
|
||
def test_milliseconds_combination(self): | ||
# 10525 | ||
DateOffset(days=1, milliseconds=1) | ||
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. Can you add an assertion that the object has been properly constructed? 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. fixed |
||
|
||
|
||
class TestOffsetNames: | ||
def test_get_offset_name(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.
can we be more specific? like
Bug in :class:
DateOffset` was throwing ``TypeError```..., or whatever it was