Skip to content

CLN: remove _AXIS_REVERSED #44330

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

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,9 +1686,7 @@ def to_numpy(
self._consolidate_inplace()
if dtype is not None:
dtype = np.dtype(dtype)
result = self._mgr.as_array(
transpose=self._AXIS_REVERSED, dtype=dtype, copy=copy, na_value=na_value
)
result = self._mgr.as_array(dtype=dtype, copy=copy, na_value=na_value)
if result.dtype is not dtype:
result = np.array(result, dtype=dtype, copy=False)

Expand Down Expand Up @@ -10715,7 +10713,6 @@ def isin(self, values) -> DataFrame:
1: 1,
"columns": 1,
}
_AXIS_REVERSED = True
_AXIS_LEN = len(_AXIS_ORDERS)
_info_axis_number = 1
_info_axis_name = "columns"
Expand Down Expand Up @@ -10840,7 +10837,7 @@ def values(self) -> np.ndarray:
['monkey', nan, None]], dtype=object)
"""
self._consolidate_inplace()
return self._mgr.as_array(transpose=True)
return self._mgr.as_array()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def ffill(
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def _data(self):
_stat_axis_name = "index"
_AXIS_ORDERS: list[str]
_AXIS_TO_AXIS_NUMBER: dict[Axis, int] = {0: 0, "index": 0, "rows": 0}
_AXIS_REVERSED: bool_t
_info_axis_number: int
_info_axis_name: str
_AXIS_LEN: int
Expand Down Expand Up @@ -566,9 +565,10 @@ def _get_axis(self, axis: Axis) -> Index:
def _get_block_manager_axis(cls, axis: Axis) -> int:
"""Map the axis to the block_manager axis."""
axis = cls._get_axis_number(axis)
if cls._AXIS_REVERSED:
m = cls._AXIS_LEN - 1
return m - axis
ndim = cls._AXIS_LEN
if ndim == 2:
# i.e. DataFrame
return 1 - axis
return axis

@final
Expand Down
7 changes: 1 addition & 6 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,6 @@ def unstack(self, unstacker, fill_value) -> ArrayManager:

def as_array(
self,
transpose: bool = False,
dtype=None,
copy: bool = False,
na_value=lib.no_default,
Expand All @@ -1092,8 +1091,6 @@ def as_array(

Parameters
----------
transpose : bool, default False
If True, transpose the return array.
dtype : object, default None
Data type of the return array.
copy : bool, default False
Expand All @@ -1109,7 +1106,7 @@ def as_array(
"""
if len(self.arrays) == 0:
empty_arr = np.empty(self.shape, dtype=float)
return empty_arr.transpose() if transpose else empty_arr
return empty_arr.transpose()

# We want to copy when na_value is provided to avoid
# mutating the original object
Expand Down Expand Up @@ -1137,8 +1134,6 @@ def as_array(
result[isna(result)] = na_value

return result
# FIXME: don't leave commented-out
# return arr.transpose() if transpose else arr


class SingleArrayManager(BaseArrayManager, SingleDataManager):
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,6 @@ def to_dict(self, copy: bool = True):

def as_array(
self,
transpose: bool = False,
dtype: np.dtype | None = None,
copy: bool = False,
na_value=lib.no_default,
Expand All @@ -1475,8 +1474,6 @@ def as_array(

Parameters
----------
transpose : bool, default False
If True, transpose the return array.
dtype : np.dtype or None, default None
Data type of the return array.
copy : bool, default False
Expand All @@ -1492,7 +1489,7 @@ def as_array(
"""
if len(self.blocks) == 0:
arr = np.empty(self.shape, dtype=float)
return arr.transpose() if transpose else arr
return arr.transpose()

# We want to copy when na_value is provided to avoid
# mutating the original object
Expand Down Expand Up @@ -1524,7 +1521,7 @@ def as_array(
if na_value is not lib.no_default:
arr[isna(arr)] = na_value

return arr.transpose() if transpose else arr
return arr.transpose()

def _interleave(
self,
Expand Down
1 change: 0 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5498,7 +5498,6 @@ def mask(
# ----------------------------------------------------------------------
# Add index
_AXIS_ORDERS = ["index"]
_AXIS_REVERSED = False
_AXIS_LEN = len(_AXIS_ORDERS)
_info_axis_number = 0
_info_axis_name = "index"
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ def test_validate_bool_args(self, value):
def _as_array(mgr):
if mgr.ndim == 1:
return mgr.external_values()
return mgr.as_array()
return mgr.as_array().T


class TestIndexing:
Expand Down