-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF: implement _should_compare #38105
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 all commits
59c244d
701e7fe
4559d44
fbb4c6c
653ff96
7bb5929
dbfc820
df84891
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 |
---|---|---|
|
@@ -21,6 +21,28 @@ | |
) | ||
import pandas._testing as tm | ||
|
||
dti4 = date_range("2016-01-01", periods=4) | ||
dti = dti4[:-1] | ||
rng = pd.Index(range(3)) | ||
|
||
|
||
@pytest.fixture( | ||
params=[ | ||
dti, | ||
dti.tz_localize("UTC"), | ||
dti.to_period("W"), | ||
dti - dti[0], | ||
rng, | ||
pd.Index([1, 2, 3]), | ||
pd.Index([2.0, 3.0, 4.0]), | ||
pd.Index([4, 5, 6], dtype="u8"), | ||
pd.IntervalIndex.from_breaks(dti4), | ||
] | ||
) | ||
def non_comparable_idx(request): | ||
# All have length 3 | ||
return request.param | ||
|
||
|
||
class TestGetItem: | ||
def test_ellipsis(self): | ||
|
@@ -438,6 +460,37 @@ def test_get_indexer_mismatched_dtype(self): | |
result = pi.get_indexer_non_unique(pi2)[0] | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def test_get_indexer_mismatched_dtype_different_length(self, non_comparable_idx): | ||
# without method we arent checking inequalities, so get all-missing | ||
# but do not raise | ||
dti = date_range("2016-01-01", periods=3) | ||
pi = dti.to_period("D") | ||
|
||
other = non_comparable_idx | ||
|
||
res = pi[:-1].get_indexer(other) | ||
expected = -np.ones(other.shape, dtype=np.intp) | ||
tm.assert_numpy_array_equal(res, expected) | ||
|
||
@pytest.mark.parametrize("method", ["pad", "backfill", "nearest"]) | ||
def test_get_indexer_mismatched_dtype_with_method(self, non_comparable_idx, method): | ||
dti = date_range("2016-01-01", periods=3) | ||
pi = dti.to_period("D") | ||
|
||
other = non_comparable_idx | ||
|
||
msg = re.escape(f"Cannot compare dtypes {pi.dtype} and {other.dtype}") | ||
with pytest.raises(TypeError, match=msg): | ||
pi.get_indexer(other, method=method) | ||
|
||
for dtype in ["object", "category"]: | ||
other2 = other.astype(dtype) | ||
if dtype == "object" and isinstance(other, PeriodIndex): | ||
continue | ||
# For object dtype we are liable to get a different exception message | ||
with pytest.raises(TypeError): | ||
pi.get_indexer(other2, method=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. @jreback notice in these cases we are currently raising in master bc the scalar comparisons raise 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. is this new? get_indexer is not super public but i believe it will never raise 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 you're right that get_indexer with method=None should never raise (maybe with tzawareness corner cases), but with method="ffill" the following raises on master:
|
||
|
||
def test_get_indexer_non_unique(self): | ||
# GH 17717 | ||
p1 = Period("2017-09-02") | ||
|
Uh oh!
There was an error while loading. Please reload this page.