-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
API: dont infer freq in DTA/TDA arithmetic ops #33487
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
a689bfe
1b7bca3
10a20d7
d2f093d
8ac2216
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 |
---|---|---|
|
@@ -57,7 +57,6 @@ | |
"std", | ||
"median", | ||
"_format_native_types", | ||
"freq", | ||
], | ||
TimedeltaArray, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -865,7 +865,7 @@ def test_dt64arr_add_sub_td64ndarray(self, tz_naive_fixture, box_with_array): | |
tdi = pd.TimedeltaIndex(["-1 Day", "-1 Day", "-1 Day"]) | ||
tdarr = tdi.values | ||
|
||
expected = pd.date_range("2015-12-31", periods=3, tz=tz) | ||
expected = pd.date_range("2015-12-31", periods=3, tz=tz)._with_freq(None) | ||
|
||
dtarr = tm.box_expected(dti, box_with_array) | ||
expected = tm.box_expected(expected, box_with_array) | ||
|
@@ -875,7 +875,7 @@ def test_dt64arr_add_sub_td64ndarray(self, tz_naive_fixture, box_with_array): | |
result = tdarr + dtarr | ||
tm.assert_equal(result, expected) | ||
|
||
expected = pd.date_range("2016-01-02", periods=3, tz=tz) | ||
expected = pd.date_range("2016-01-02", periods=3, tz=tz)._with_freq(None) | ||
expected = tm.box_expected(expected, box_with_array) | ||
|
||
result = dtarr - tdarr | ||
|
@@ -1385,13 +1385,13 @@ def test_dt64arr_add_sub_DateOffset(self, box_with_array): | |
s = tm.box_expected(s, box_with_array) | ||
result = s + pd.DateOffset(years=1) | ||
result2 = pd.DateOffset(years=1) + s | ||
exp = date_range("2001-01-01", "2001-01-31", name="a") | ||
exp = date_range("2001-01-01", "2001-01-31", name="a")._with_freq(None) | ||
exp = tm.box_expected(exp, box_with_array) | ||
tm.assert_equal(result, exp) | ||
tm.assert_equal(result2, exp) | ||
|
||
result = s - pd.DateOffset(years=1) | ||
exp = date_range("1999-01-01", "1999-01-31", name="a") | ||
exp = date_range("1999-01-01", "1999-01-31", name="a")._with_freq(None) | ||
exp = tm.box_expected(exp, box_with_array) | ||
tm.assert_equal(result, exp) | ||
|
||
|
@@ -1553,7 +1553,7 @@ def test_dti_add_sub_nonzero_mth_offset( | |
mth = getattr(date, op) | ||
result = mth(offset) | ||
|
||
expected = pd.DatetimeIndex(exp, tz=tz, freq=exp_freq) | ||
expected = pd.DatetimeIndex(exp, tz=tz) | ||
expected = tm.box_expected(expected, box_with_array, False) | ||
tm.assert_equal(result, expected) | ||
|
||
|
@@ -2344,29 +2344,29 @@ def test_ufunc_coercions(self): | |
assert result.freq == "2D" | ||
|
||
exp = date_range("2010-12-31", periods=3, freq="2D", name="x") | ||
|
||
for result in [idx - delta, np.subtract(idx, delta)]: | ||
assert isinstance(result, DatetimeIndex) | ||
tm.assert_index_equal(result, exp) | ||
assert result.freq == "2D" | ||
|
||
# When adding/subtracting an ndarray (which has no .freq), the result | ||
# does not infer freq | ||
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 u need to pass freq=None when constructing th index rather than using a private method 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. yah, first we need to fix the DTI constructor so that if you explicitly pass freq=None it wont override the arg's freq, ATM we get:
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 i guess freq should be a no_default arg s can handle None 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. yah. ill make a PR for that in the AM 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. working on 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. ok sure, yeah like to avoid using |
||
idx = idx._with_freq(None) | ||
delta = np.array( | ||
[np.timedelta64(1, "D"), np.timedelta64(2, "D"), np.timedelta64(3, "D")] | ||
) | ||
exp = DatetimeIndex( | ||
["2011-01-02", "2011-01-05", "2011-01-08"], freq="3D", name="x" | ||
) | ||
exp = DatetimeIndex(["2011-01-02", "2011-01-05", "2011-01-08"], name="x") | ||
|
||
for result in [idx + delta, np.add(idx, delta)]: | ||
assert isinstance(result, DatetimeIndex) | ||
tm.assert_index_equal(result, exp) | ||
assert result.freq == "3D" | ||
assert result.freq == exp.freq | ||
|
||
exp = DatetimeIndex( | ||
["2010-12-31", "2011-01-01", "2011-01-02"], freq="D", name="x" | ||
) | ||
exp = DatetimeIndex(["2010-12-31", "2011-01-01", "2011-01-02"], name="x") | ||
for result in [idx - delta, np.subtract(idx, delta)]: | ||
assert isinstance(result, DatetimeIndex) | ||
tm.assert_index_equal(result, exp) | ||
assert result.freq == "D" | ||
assert result.freq == exp.freq | ||
|
||
@pytest.mark.parametrize( | ||
"names", [("foo", None, None), ("baz", "bar", None), ("bar", "bar", "bar")] | ||
|
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 you not just pass
freq='None'
?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.
sure, will update
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.
updated+green