BUG: DTI/TDI/PI get_indexer_non_unique with incompatible dtype by jbrockmendel · Pull Request #32650 · pandas-dev/pandas (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
I'm pretty sure we can share more code here, but PeriodEngine needs some work first.
lgtm. needs a rebase. is this user visible at a high level? e.g. in .loc or someting?
is this user visible at a high level? e.g. in .loc or someting?
Yes, will update the test introduced in #30446
hmm this should probably raise a KeyError instead of a TypeError?
df = pd.DataFrame(
np.random.randn(5, 3),
columns=["a", "b", "c"],
index=pd.date_range("2012", freq="H", periods=5),
)
df = df.iloc[[0, 2, 2, 3]].copy()
dti = df.index
tdi = pd.TimedeltaIndex(dti.asi8) # matching i8 values
with pytest.raises(TypeError, match="is not convertible to datetime"):
df.loc[tdi]
with pytest.raises(TypeError, match="is not convertible to datetime"):
df["a"].loc[tdi]
hmm this should probably raise a KeyError instead of a TypeError?
df = pd.DataFrame( np.random.randn(5, 3), columns=["a", "b", "c"], index=pd.date_range("2012", freq="H", periods=5), ) df = df.iloc[[0, 2, 2, 3]].copy() dti = df.index tdi = pd.TimedeltaIndex(dti.asi8) # matching i8 values with pytest.raises(TypeError, match="is not convertible to datetime"): df.loc[tdi] with pytest.raises(TypeError, match="is not convertible to datetime"): df["a"].loc[tdi]
hmm, yep sounds right
| with pytest.raises(KeyError, match=msg): |
|---|
| df.loc[tdi] |
| with pytest.raises(KeyError, match=msg): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would test the reverse as well (e.g. TDI is the index with a DTI as indexer). This should also raise for Period, I think? (these can be handled as followons)
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request
Labels
Related to indexing on series/frames, not to indexes themselves