-
-
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
[ArrayManager] TST: run (+fix/skip) pandas/tests/frame/indexing tests #40323
[ArrayManager] TST: run (+fix/skip) pandas/tests/frame/indexing tests #40323
Conversation
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
i guess what we really care about here is np.shares_memory(result._values, df.iloc[:, 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.
Added the np.shares_memory
check. And turned out that also with ArrayManager this actually gives a view. But it's the iloc
modifying the parent that doesn't result in modifying the child result, when using ArrayManager, but also when using a mixed DataFrame. So added that as an explicit test case as well.
@@ -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 comment
The 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 comment
The 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 __setitem__
, for "B" it's actually a TODO to have .loc[: "col"]
not overwrite)
@@ -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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
In the end was easy to rewrite using .arrays
so it works for both
pandas/core/internals/managers.py
Outdated
@@ -1617,6 +1617,15 @@ def get_slice(self, slobj: slice, axis: int = 0) -> SingleBlockManager: | |||
def index(self) -> Index: | |||
return self.axes[0] | |||
|
|||
@property | |||
def array(self) -> ArrayLike: |
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)
@jbrockmendel ready to merge here? |
LGTM cc @jreback |
thanks @jorisvandenbossche |
xref #39146
Extracting part of the test changes of #39578. This PR is doing
pandas/tests/frame/indexing
. Thepandas/tests/indexing
tests are handled in #40323.