-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix wrong error in df drop with non unique datetime index and invalid keys #30446
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 6 commits
8bc6e08
2d747a0
0b3600b
d9f45e0
2c6638d
963caa3
90ea50c
ba25498
a6675e4
cf814e9
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 |
---|---|---|
|
@@ -139,3 +139,32 @@ def test_drop_not_lexsorted(): | |
tm.assert_index_equal(lexsorted_mi, not_lexsorted_mi) | ||
with tm.assert_produces_warning(PerformanceWarning): | ||
tm.assert_index_equal(lexsorted_mi.drop("a"), not_lexsorted_mi.drop("a")) | ||
|
||
|
||
def test_drop_with_non_unique_datetime_index_and_invalid_keys(): | ||
# GH 30399 | ||
|
||
# define dataframe with unique datetime index | ||
df_unique = pd.DataFrame( | ||
np.random.randn(5, 3), | ||
columns=["a", "b", "c"], | ||
index=pd.date_range("2012", freq="H", periods=5), | ||
) | ||
# create dataframe with non-unique datetime index | ||
df_nonunique = df_unique.copy().iloc[[0, 2, 2, 3]] | ||
|
||
try: | ||
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 the point of this is the raise a 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. Have updated the code as requested. Now the test specifically expects KeyError with string "not found in axis" within the message |
||
df_nonunique.drop(["a", "b"]) # Dropping with labels not exist in the index | ||
except Exception as e: | ||
result = e | ||
else: | ||
result = "df_nonunique.drop(['a', 'b']) should raise error but it didn't" | ||
|
||
try: | ||
df_unique.drop(["a", "b"]) # Dropping with labels not exist in the index | ||
except Exception as e: | ||
expected = e | ||
else: | ||
expected = "df_unique.drop(['a', 'b']) should raise error but it didn't" | ||
|
||
assert type(result) is type(expected) and result.args == expected.args |
Uh oh!
There was an error while loading. Please reload this page.