-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
TST: Add tests for old issues #41482
Changes from 9 commits
0a06f60
e1ca832
eed059e
3b71773
bfe95bd
77bed59
beb1836
8e4833e
2fcdc61
92a06a4
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 |
---|---|---|
|
@@ -1032,6 +1032,15 @@ def test_frame_single_columns_object_sum_axis_1(): | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("ts_value", [pd.Timestamp("2000-01-01"), pd.NaT]) | ||
def test_frame_mixed_numeric_object_with_timestamp(ts_value): | ||
# GH 13912 | ||
df = DataFrame({"a": [1], "b": [1.1], "c": ["foo"], "d": [ts_value]}) | ||
result = df.sum() | ||
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. test_frame_reductions i think |
||
expected = Series([1, 1.1, "foo"], index=list("abc")) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
# ------------------------------------------------------------------- | ||
# Unsorted | ||
# These arithmetic tests were previously in other files, eventually | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2018,3 +2018,18 @@ def test_stack_nan_level(self): | |
), | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_unstack_categorical(self): | ||
# GH 14018 | ||
idx = MultiIndex.from_product([["A"], [0, 1]]) | ||
df = DataFrame({"cat": pd.Categorical(["a", "b"])}, index=idx) | ||
result = df.unstack() | ||
expected = DataFrame( | ||
[ | ||
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. can you pass this as a dict or use from_arrays? IIRC the constructor is wonky specifically if the first listlike is a categorical |
||
pd.Categorical(["a"], categories=["a", "b"]), | ||
pd.Categorical(["b"], categories=["a", "b"]), | ||
], | ||
index=["A"], | ||
columns=MultiIndex.from_tuples([("cat", 0), ("cat", 1)]), | ||
) | ||
tm.assert_frame_equal(result, expected) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -788,3 +788,16 @@ def test_mi_columns_loc_list_label_order(): | |
columns=MultiIndex.from_tuples([("B", 1), ("B", 2), ("A", 1), ("A", 2)]), | ||
) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_mi_partial_indexing_list_raises(): | ||
# GH 13501 | ||
frame = DataFrame( | ||
np.arange(12).reshape((4, 3)), | ||
index=[["a", "a", "b", "b"], [1, 2, 1, 2]], | ||
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]], | ||
) | ||
frame.index.names = ["key1", "key2"] | ||
frame.columns.names = ["state", "color"] | ||
with pytest.raises(KeyError, match="\\[2\\] not in index"): | ||
frame.loc[["b", 2], "Colorado"] | ||
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. this is bc the user passed a list instead of a tuple? 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. Correct, as a tuple I think this should correctly select
|
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.
is it important that this is set here instead of being part of the constructor?