-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
FIX BUG: Timestamp __add__/__sub__ DateOffset with nanoseconds lost. #43968
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 28 commits
2208507
ee19a4d
3e38ab2
5718e4f
e1ae149
326790b
83453da
ae4b133
a43030d
22cadbf
1c89c03
a2ad274
9bc6e97
c9ddf14
4780316
1fecfa6
e92c1a9
006c073
ab064b4
8e42c64
5ca3472
37d19b5
5acad37
9cda54a
0ee9a6f
860a62b
4600a64
8cf5746
a210baf
98646cd
e899fbe
906f546
24fe768
209ba9e
f56f52b
3f49876
b7297ef
5cbae96
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 |
---|---|---|
|
@@ -669,14 +669,6 @@ def test_rule_code(self): | |
assert alias == (_get_offset(alias) * 5).rule_code | ||
|
||
|
||
def test_dateoffset_misc(): | ||
oset = offsets.DateOffset(months=2, days=4) | ||
# it works | ||
oset.freqstr | ||
|
||
assert not offsets.DateOffset(months=2) == 2 | ||
|
||
|
||
def test_freq_offsets(): | ||
off = BDay(1, offset=timedelta(0, 1800)) | ||
assert off.freqstr == "B+30Min" | ||
|
@@ -792,6 +784,43 @@ def test_tick_normalize_raises(tick_classes): | |
cls(n=3, normalize=True) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"offset_kwargs, ts_arg, expected_arg", | ||
[ | ||
({"nanoseconds": 1}, 0, "1970-01-01 00:00:00.000000001"), | ||
({"nanoseconds": 5}, 0, "1970-01-01 00:00:00.000000005"), | ||
({"nanoseconds": -1}, 0, "1969-12-31 23:59:59.999999999"), | ||
({"microseconds": 1}, 0, "1970-01-01 00:00:00.000001"), | ||
({"microseconds": -1}, 0, "1969-12-31 23:59:59.999999"), | ||
({"seconds": 1}, 0, "1970-01-01 00:00:01"), | ||
({"seconds": -1}, 0, "1969-12-31 23:59:59"), | ||
({"minutes": 1}, 0, "1970-01-01 00:01:00"), | ||
({"minutes": -1}, 0, "1969-12-31 23:59:00"), | ||
({"hours": 1}, 0, "1970-01-01 01:00:00"), | ||
({"hours": -1}, 0, "1969-12-31 23:00:00"), | ||
({"days": 1}, 0, "1970-01-02 00:00:00"), | ||
({"days": -1}, 0, "1969-12-31 00:00:00"), | ||
({"weeks": 1}, 0, "1970-01-08 00:00:00"), | ||
({"weeks": -1}, 0, "1969-12-25 00:00:00"), | ||
({"months": 1}, 0, "1970-02-01 00:00:00"), | ||
({"months": -1}, 0, "1969-12-01 00:00:00"), | ||
({"years": 1}, 0, "1971-01-01 00:00:00"), | ||
({"years": -1}, 0, "1969-01-01 00:00:00"), | ||
({"minutes": 2, "nanoseconds": 9}, 4, "1970-01-01 00:02:00.000000013"), | ||
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. @jbrockmendel Here is the test case you suggest. The test can be passed in my local machine, but the travis is too slow, will look at the result later. 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. nitpick: id make a separate test for this specific case (could have useful name/comment) and avoid the extra clutter in the parametrize here 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. That makes sense, just done. |
||
], | ||
) | ||
def test_dateoffset_add_sub(offset_kwargs, ts_arg, expected_arg): | ||
offset = DateOffset(**offset_kwargs) | ||
ts = Timestamp(ts_arg) | ||
result = ts + offset | ||
expected = Timestamp(expected_arg) | ||
assert result == expected | ||
result -= offset | ||
assert result == ts | ||
result = offset + ts | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"attribute", | ||
[ | ||
|
@@ -807,3 +836,11 @@ def test_dateoffset_immutable(attribute): | |
msg = "DateOffset objects are immutable" | ||
with pytest.raises(AttributeError, match=msg): | ||
setattr(offset, attribute, 5) | ||
|
||
|
||
def test_dateoffset_misc(): | ||
oset = offsets.DateOffset(months=2, days=4) | ||
# it works | ||
oset.freqstr | ||
|
||
assert not offsets.DateOffset(months=2) == 2 |
Uh oh!
There was an error while loading. Please reload this page.