Skip to content

CLN: index related attributes on Series/DataFrame #31953

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 2 commits into from
Feb 14, 2020
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
15 changes: 8 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8569,6 +8569,14 @@ def isin(self, values) -> "DataFrame":

# ----------------------------------------------------------------------
# Add index and columns
_AXIS_ORDERS = ["index", "columns"]
_AXIS_NUMBERS = {"index": 0, "columns": 1}
_AXIS_NAMES = {0: "index", 1: "columns"}
_AXIS_REVERSED = True
_AXIS_LEN = len(_AXIS_ORDERS)
_info_axis_number = 1
_info_axis_name = "columns"

index: "Index" = properties.AxisProperty(
axis=1, doc="The index (row labels) of the DataFrame."
)
Expand All @@ -8584,13 +8592,6 @@ def isin(self, values) -> "DataFrame":
sparse = CachedAccessor("sparse", SparseFrameAccessor)


DataFrame._setup_axes(
["index", "columns"],
docs={
"index": "The index (row labels) of the DataFrame.",
"columns": "The column labels of the DataFrame.",
},
)
DataFrame._add_numeric_operations()
DataFrame._add_series_or_dataframe_operations()

Expand Down
22 changes: 0 additions & 22 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,6 @@ def _constructor_expanddim(self):
_info_axis_name: str
_AXIS_LEN: int

@classmethod
def _setup_axes(cls, axes: List[str], docs: Dict[str, str]) -> None:
"""
Provide axes setup for the major PandasObjects.

Parameters
----------
axes : the names of the axes in order (lowest to highest)
docs : docstrings for the axis properties
"""
info_axis = len(axes) - 1
axes_are_reversed = len(axes) > 1

cls._AXIS_ORDERS = axes
cls._AXIS_NUMBERS = {a: i for i, a in enumerate(axes)}
cls._AXIS_LEN = len(axes)
cls._AXIS_NAMES = dict(enumerate(axes))
cls._AXIS_REVERSED = axes_are_reversed

cls._info_axis_number = info_axis
cls._info_axis_name = axes[info_axis]

def _construct_axes_dict(self, axes=None, **kwargs):
"""Return an axes dictionary for myself."""
d = {a: self._get_axis(a) for a in (axes or self._AXIS_ORDERS)}
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4562,6 +4562,14 @@ def to_period(self, freq=None, copy=True) -> "Series":

# ----------------------------------------------------------------------
# Add index
_AXIS_ORDERS = ["index"]
_AXIS_NUMBERS = {"index": 0}
_AXIS_NAMES = {0: "index"}
_AXIS_REVERSED = False
_AXIS_LEN = len(_AXIS_ORDERS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

_info_axis_number = 0
_info_axis_name = "index"

index: "Index" = properties.AxisProperty(
axis=0, doc="The index (axis labels) of the Series."
)
Expand All @@ -4580,7 +4588,6 @@ def to_period(self, freq=None, copy=True) -> "Series":
hist = pandas.plotting.hist_series


Series._setup_axes(["index"], docs={"index": "The index (axis labels) of the Series."})
Series._add_numeric_operations()
Series._add_series_or_dataframe_operations()

Expand Down