-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF get-axis-number #43263
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
REF get-axis-number #43263
Changes from all commits
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import warnings | ||
import weakref | ||
|
||
|
||
import numpy as np | ||
|
||
from pandas._config import config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -995,7 +995,7 @@ def test_consistency_for_boxed(box, int_frame_const_col): | |
|
||
|
||
def test_agg_transform(axis, float_frame): | ||
other_axis = 1 if axis in {0, "index"} else 0 | ||
other_axis = 1 if DataFrame()._get_axis_number(axis)==0 else 0 | ||
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 issue has been revised to avoid fixing 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. So, no touching test files, then? 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. dont edit test files. 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. Aight. Won't. Thanks for telling. I'll revert the changes |
||
|
||
with np.errstate(all="ignore"): | ||
|
||
|
@@ -1010,7 +1010,8 @@ def test_agg_transform(axis, float_frame): | |
# list-like | ||
result = float_frame.apply([np.sqrt], axis=axis) | ||
expected = f_sqrt.copy() | ||
if axis in {0, "index"}: | ||
from pandas import DataFrame | ||
if DataFrame()._get_axis_number(axis)==0: | ||
expected.columns = MultiIndex.from_product([float_frame.columns, ["sqrt"]]) | ||
else: | ||
expected.index = MultiIndex.from_product([float_frame.index, ["sqrt"]]) | ||
|
@@ -1021,11 +1022,10 @@ def test_agg_transform(axis, float_frame): | |
# functions per series and then concatting | ||
result = float_frame.apply([np.abs, np.sqrt], axis=axis) | ||
expected = zip_frames([f_abs, f_sqrt], axis=other_axis) | ||
if axis in {0, "index"}: | ||
if DataFrame()._get_axis_number(axis)==0: | ||
expected.columns = MultiIndex.from_product( | ||
[float_frame.columns, ["absolute", "sqrt"]] | ||
) | ||
else: | ||
expected.index = MultiIndex.from_product( | ||
[float_frame.index, ["absolute", "sqrt"]] | ||
) | ||
|
@@ -1102,7 +1102,7 @@ def test_agg_multiple_mixed_no_warning(): | |
|
||
|
||
def test_agg_reduce(axis, float_frame): | ||
other_axis = 1 if axis in {0, "index"} else 0 | ||
other_axis = 1 if DataFrame()._get_axis_number(axis)==0 else 0 | ||
name1, name2 = float_frame.axes[other_axis].unique()[:2].sort_values() | ||
|
||
# all reducers | ||
|
@@ -1115,7 +1115,7 @@ def test_agg_reduce(axis, float_frame): | |
axis=1, | ||
) | ||
expected.columns = ["mean", "max", "sum"] | ||
expected = expected.T if axis in {0, "index"} else expected | ||
expected = expected.T if DataFrame()._get_axis_number(axis)==0 else expected | ||
|
||
result = float_frame.agg(["mean", "max", "sum"], axis=axis) | ||
tm.assert_frame_equal(result, expected) | ||
|
@@ -1141,7 +1141,7 @@ def test_agg_reduce(axis, float_frame): | |
name2: Series([float_frame.loc(other_axis)[name2].sum()], index=["sum"]), | ||
} | ||
) | ||
expected = expected.T if axis in {1, "columns"} else expected | ||
expected = expected.T if DataFrame()._get_axis_number(axis)==1 else expected | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# dict input with lists with multiple | ||
|
@@ -1166,7 +1166,7 @@ def test_agg_reduce(axis, float_frame): | |
}, | ||
axis=1, | ||
) | ||
expected = expected.T if axis in {1, "columns"} else expected | ||
expected = expected.T if DataFrame()._get_axis_number(axis)==1 else expected | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,7 +547,7 @@ def test_groupby_level_index_names(self, axis): | |
df = DataFrame({"exp": ["A"] * 3 + ["B"] * 3, "var1": range(6)}).set_index( | ||
"exp" | ||
) | ||
if axis in (1, "columns"): | ||
if DataFrame()._get_axis_number(axis)==0: | ||
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. you can do this here, but use existing objects such as 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. Ah. Thanks for point that out, I'll correct it and re-commit |
||
df = df.T | ||
df.groupby(level="exp", axis=axis) | ||
msg = f"level name foo is not the name of the {df._get_axis_name(axis)}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,7 +488,7 @@ def test_rolling_axis_count(axis_frame): | |
|
||
axis = df._get_axis_number(axis_frame) | ||
|
||
if axis in [0, "index"]: | ||
if DataFrame()._get_axis_number(axis)==0: | ||
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.
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. Ah. So, has this specific edit been rendered unnecessary? |
||
expected = DataFrame({"x": [1.0, 2.0, 2.0], "y": [1.0, 2.0, 2.0]}) | ||
else: | ||
expected = DataFrame({"x": [1.0, 1.0, 1.0], "y": [2.0, 2.0, 2.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.
why?
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.
don't make changes to
style.py
this already has PRs fixing this. please revert.Uh oh!
There was an error while loading. Please reload this page.
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.
aight. on it
just to confirm, though, were my changes correct? or were they unnecessary?