-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[ArrayManager] TST: run (+fix/skip) pandas/tests/frame/indexing tests #40323
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 2 commits
81eb983
23d2efd
9fbcb6e
fe96c6a
abbd245
3641337
495b5f5
173c100
4df48d0
78aeeda
3092e21
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import numpy as np | ||
import pytest | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
from pandas.core.dtypes.base import registry as ea_registry | ||
from pandas.core.dtypes.common import ( | ||
is_categorical_dtype, | ||
|
@@ -282,7 +284,7 @@ def test_frame_setitem_existing_datetime64_col_other_units(self, unit): | |
df["dates"] = vals | ||
assert (df["dates"].values == ex_vals).all() | ||
|
||
def test_setitem_dt64tz(self, timezone_frame): | ||
def test_setitem_dt64tz(self, timezone_frame, using_array_manager): | ||
|
||
df = timezone_frame | ||
idx = df["B"].rename("foo") | ||
|
@@ -296,6 +298,10 @@ def test_setitem_dt64tz(self, timezone_frame): | |
tm.assert_series_equal(df["D"], Series(idx, name="D")) | ||
del df["D"] | ||
|
||
if using_array_manager: | ||
# TODO(ArrayManager) rewrite test for ArrayManager | ||
return | ||
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. xfail/skip? 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. The first part of the test is still useful to run, so I would rather not skip it 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. if you skip/xfail at this point, then the part up to here will still run 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. In the end was easy to rewrite using |
||
|
||
# assert that A & C are not sharing the same base (e.g. they | ||
# are copies) | ||
b1 = df._mgr.blocks[1] | ||
|
@@ -366,7 +372,7 @@ def test_setitem_frame_length_0_str_key(self, indexer): | |
expected["A"] = expected["A"].astype("object") | ||
tm.assert_frame_equal(df, expected) | ||
|
||
def test_setitem_frame_duplicate_columns(self): | ||
def test_setitem_frame_duplicate_columns(self, using_array_manager): | ||
# GH#15695 | ||
cols = ["A", "B", "C"] * 2 | ||
df = DataFrame(index=range(3), columns=cols) | ||
|
@@ -382,6 +388,9 @@ def test_setitem_frame_duplicate_columns(self): | |
columns=cols, | ||
dtype="object", | ||
) | ||
if using_array_manager: | ||
expected["B"] = expected["B"].astype("int64") | ||
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. comment as to why the difference? 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. Yes, added a comment (for "C" it's expected, since it's a |
||
expected["C"] = expected["C"].astype("int64") | ||
tm.assert_frame_equal(df, expected) | ||
|
||
@pytest.mark.parametrize("cols", [["a", "b", "c"], ["a", "a", "a"]]) | ||
|
@@ -628,6 +637,8 @@ def test_setitem_object_array_of_tzaware_datetimes(self, idx, expected): | |
|
||
|
||
class TestDataFrameSetItemWithExpansion: | ||
# TODO(ArrayManager) update parent (_maybe_update_cacher) | ||
@td.skip_array_manager_not_yet_implemented | ||
def test_setitem_listlike_views(self): | ||
# GH#38148 | ||
df = DataFrame({"a": [1, 2, 3], "b": [4, 4, 6]}) | ||
|
@@ -699,7 +710,7 @@ def test_setitem_with_expansion_categorical_dtype(self): | |
|
||
result1 = df["D"] | ||
result2 = df["E"] | ||
tm.assert_categorical_equal(result1._mgr._block.values, cat) | ||
tm.assert_categorical_equal(result1._mgr.array, cat) | ||
|
||
# sorting | ||
ser.name = "E" | ||
|
@@ -767,6 +778,7 @@ def inc(x): | |
|
||
|
||
class TestDataFrameSetItemBooleanMask: | ||
@td.skip_array_manager_invalid_test # TODO(ArrayManager) rewrite not using .values | ||
@pytest.mark.parametrize( | ||
"mask_type", | ||
[lambda df: df > np.abs(df) / 2, lambda df: (df > np.abs(df) / 2).values], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import numpy as np | ||
import pytest | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
from pandas import ( | ||
DataFrame, | ||
Index, | ||
|
@@ -109,14 +111,22 @@ def test_xs_keep_level(self): | |
result = df.xs([2008, "sat"], level=["year", "day"], drop_level=False) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_xs_view(self): | ||
def test_xs_view(self, using_array_manager): | ||
# in 0.14 this will return a view if possible a copy otherwise, but | ||
# this is numpy dependent | ||
|
||
dm = DataFrame(np.arange(20.0).reshape(4, 5), index=range(4), columns=range(5)) | ||
|
||
dm.xs(2)[:] = 10 | ||
assert (dm.xs(2) == 10).all() | ||
if using_array_manager: | ||
# INFO(ArrayManager) with ArrayManager getting a row as a view is | ||
# not possible | ||
msg = r"\nA value is trying to be set on a copy of a slice from a DataFrame" | ||
with pytest.raises(com.SettingWithCopyError, match=msg): | ||
dm.xs(2)[:] = 20 | ||
assert not (dm.xs(2) == 20).any() | ||
else: | ||
dm.xs(2)[:] = 20 | ||
assert (dm.xs(2) == 20).all() | ||
|
||
|
||
class TestXSWithMultiIndex: | ||
|
@@ -327,10 +337,12 @@ def test_xs_droplevel_false(self): | |
expected = DataFrame({"a": [1]}) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# TODO(ArrayManager) xs with axis=1 can return view | ||
@td.skip_array_manager_not_yet_implemented | ||
def test_xs_droplevel_false_view(self): | ||
# GH#37832 | ||
df = DataFrame([[1, 2, 3]], columns=Index(["a", "b", "c"])) | ||
result = df.xs("a", axis=1, drop_level=False) | ||
df.values[0, 0] = 2 | ||
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 version feels much clearer as to whats going on 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. Do you have a suggestion for how to then do it? (we can't rely on .values to mutate) 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 guess what we really care about here is 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. Added the |
||
df.iloc[0, 0] = 2 | ||
expected = DataFrame({"a": [2]}) | ||
tm.assert_frame_equal(result, expected) |
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.
could put this on SingleDataManager and return
self.arrays[0]
?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.
Yes, moved it to the base class (note this will require some type ignoring, because
.arrays
is not exactly the same for both classes)