-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Period comparisons with mismatched freq use py3 behavior #39274
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 1 commit
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 |
---|---|---|
|
@@ -278,32 +278,32 @@ def test_parr_cmp_pi_mismatched_freq_raises(self, freq, box_with_array): | |
base = PeriodIndex(["2011-01", "2011-02", "2011-03", "2011-04"], freq=freq) | ||
base = tm.box_expected(base, box_with_array) | ||
|
||
msg = "Input has different freq=A-DEC from " | ||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
msg = rf"Invalid comparison between dtype=period\[{freq}\] and Period" | ||
with pytest.raises(TypeError, match=msg): | ||
base <= Period("2011", freq="A") | ||
|
||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
with pytest.raises(TypeError, match=msg): | ||
Period("2011", freq="A") >= base | ||
|
||
# TODO: Could parametrize over boxes for idx? | ||
idx = PeriodIndex(["2011", "2012", "2013", "2014"], freq="A") | ||
rev_msg = r"Input has different freq=(M|2M|3M) from PeriodArray\(freq=A-DEC\)" | ||
rev_msg = r"Invalid comparison between dtype=period\[A-DEC\] and PeriodArray" | ||
idx_msg = rev_msg if box_with_array in [tm.to_array, pd.array] else msg | ||
with pytest.raises(IncompatibleFrequency, match=idx_msg): | ||
with pytest.raises(TypeError, match=idx_msg): | ||
base <= idx | ||
|
||
# Different frequency | ||
msg = "Input has different freq=4M from " | ||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
msg = rf"Invalid comparison between dtype=period\[{freq}\] and Period" | ||
with pytest.raises(TypeError, match=msg): | ||
base <= Period("2011", freq="4M") | ||
|
||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
with pytest.raises(TypeError, match=msg): | ||
Period("2011", freq="4M") >= base | ||
|
||
idx = PeriodIndex(["2011", "2012", "2013", "2014"], freq="4M") | ||
rev_msg = r"Input has different freq=(M|2M|3M) from PeriodArray\(freq=4M\)" | ||
rev_msg = r"Invalid comparison between dtype=period\[4M\] and PeriodArray" | ||
idx_msg = rev_msg if box_with_array in [tm.to_array, pd.array] else msg | ||
with pytest.raises(IncompatibleFrequency, match=idx_msg): | ||
with pytest.raises(TypeError, match=idx_msg): | ||
base <= idx | ||
|
||
@pytest.mark.parametrize("freq", ["M", "2M", "3M"]) | ||
|
@@ -354,12 +354,13 @@ def test_pi_cmp_nat_mismatched_freq_raises(self, freq): | |
idx1 = PeriodIndex(["2011-01", "2011-02", "NaT", "2011-05"], freq=freq) | ||
|
||
diff = PeriodIndex(["2011-02", "2011-01", "2011-04", "NaT"], freq="4M") | ||
msg = "Input has different freq=4M from Period(Array|Index)" | ||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
msg = rf"Invalid comparison between dtype=period\[{freq}\] and PeriodArray" | ||
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. prob should either rename the tests slightly or separate out the == case (and test != as well) 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. will rename for now. i think we may be able to re-use a helper from the dt64 tests, will take a look before long |
||
with pytest.raises(TypeError, match=msg): | ||
idx1 > diff | ||
|
||
with pytest.raises(IncompatibleFrequency, match=msg): | ||
idx1 == diff | ||
result = idx1 == diff | ||
expected = np.array([False, False, False, False], dtype=bool) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
# TODO: De-duplicate with test_pi_cmp_nat | ||
@pytest.mark.parametrize("dtype", [object, None]) | ||
|
Uh oh!
There was an error while loading. Please reload this page.