|
67 | 67 | is_dict_like, |
68 | 68 | is_extension_array_dtype, |
69 | 69 | is_float, |
70 | | - is_integer, |
71 | 70 | is_list_like, |
72 | 71 | is_number, |
73 | 72 | is_numeric_dtype, |
@@ -302,19 +301,32 @@ def _data(self): |
302 | 301 |
|
303 | 302 | # ---------------------------------------------------------------------- |
304 | 303 | # Axis |
305 | | - _AXIS_ALIASES = {"rows": 0} |
306 | | - _AXIS_IALIASES = {0: "rows"} |
307 | 304 | _stat_axis_number = 0 |
308 | 305 | _stat_axis_name = "index" |
309 | 306 | _ix = None |
310 | 307 | _AXIS_ORDERS: List[str] |
311 | | - _AXIS_NUMBERS: Dict[str, int] |
312 | | - _AXIS_NAMES: Dict[int, str] |
| 308 | + _AXIS_TO_AXIS_NUMBER: Dict[Axis, int] = {0: 0, "index": 0, "rows": 0} |
313 | 309 | _AXIS_REVERSED: bool |
314 | 310 | _info_axis_number: int |
315 | 311 | _info_axis_name: str |
316 | 312 | _AXIS_LEN: int |
317 | 313 |
|
| 314 | + @property |
| 315 | + def _AXIS_NUMBERS(self) -> Dict[str, int]: |
| 316 | + """.. deprecated:: 1.1.0""" |
| 317 | + warnings.warn( |
| 318 | + "_AXIS_NUMBERS has been deprecated.", FutureWarning, stacklevel=3, |
| 319 | + ) |
| 320 | + return {"index": 0} |
| 321 | + |
| 322 | + @property |
| 323 | + def _AXIS_NAMES(self) -> Dict[int, str]: |
| 324 | + """.. deprecated:: 1.1.0""" |
| 325 | + warnings.warn( |
| 326 | + "_AXIS_NAMES has been deprecated.", FutureWarning, stacklevel=3, |
| 327 | + ) |
| 328 | + return {0: "index"} |
| 329 | + |
318 | 330 | def _construct_axes_dict(self, axes=None, **kwargs): |
319 | 331 | """Return an axes dictionary for myself.""" |
320 | 332 | d = {a: self._get_axis(a) for a in (axes or self._AXIS_ORDERS)} |
@@ -353,37 +365,24 @@ def _construct_axes_from_arguments( |
353 | 365 | return axes, kwargs |
354 | 366 |
|
355 | 367 | @classmethod |
356 | | - def _get_axis_number(cls, axis) -> int: |
357 | | - axis = cls._AXIS_ALIASES.get(axis, axis) |
358 | | - if is_integer(axis): |
359 | | - if axis in cls._AXIS_NAMES: |
360 | | - return axis |
361 | | - else: |
362 | | - try: |
363 | | - return cls._AXIS_NUMBERS[axis] |
364 | | - except KeyError: |
365 | | - pass |
366 | | - raise ValueError(f"No axis named {axis} for object type {cls.__name__}") |
| 368 | + def _get_axis_number(cls, axis: Axis) -> int: |
| 369 | + try: |
| 370 | + return cls._AXIS_TO_AXIS_NUMBER[axis] |
| 371 | + except KeyError: |
| 372 | + raise ValueError(f"No axis named {axis} for object type {cls.__name__}") |
367 | 373 |
|
368 | 374 | @classmethod |
369 | | - def _get_axis_name(cls, axis) -> str: |
370 | | - axis = cls._AXIS_ALIASES.get(axis, axis) |
371 | | - if isinstance(axis, str): |
372 | | - if axis in cls._AXIS_NUMBERS: |
373 | | - return axis |
374 | | - else: |
375 | | - try: |
376 | | - return cls._AXIS_NAMES[axis] |
377 | | - except KeyError: |
378 | | - pass |
379 | | - raise ValueError(f"No axis named {axis} for object type {cls.__name__}") |
| 375 | + def _get_axis_name(cls, axis: Axis) -> str: |
| 376 | + axis_number = cls._get_axis_number(axis) |
| 377 | + return cls._AXIS_ORDERS[axis_number] |
380 | 378 |
|
381 | | - def _get_axis(self, axis) -> Index: |
382 | | - name = self._get_axis_name(axis) |
383 | | - return getattr(self, name) |
| 379 | + def _get_axis(self, axis: Axis) -> Index: |
| 380 | + axis_number = self._get_axis_number(axis) |
| 381 | + assert axis_number in {0, 1} |
| 382 | + return self.index if axis_number == 0 else self.columns |
384 | 383 |
|
385 | 384 | @classmethod |
386 | | - def _get_block_manager_axis(cls, axis) -> int: |
| 385 | + def _get_block_manager_axis(cls, axis: Axis) -> int: |
387 | 386 | """Map the axis to the block_manager axis.""" |
388 | 387 | axis = cls._get_axis_number(axis) |
389 | 388 | if cls._AXIS_REVERSED: |
@@ -448,11 +447,11 @@ def _get_cleaned_column_resolvers(self) -> Dict[str, ABCSeries]: |
448 | 447 | } |
449 | 448 |
|
450 | 449 | @property |
451 | | - def _info_axis(self): |
| 450 | + def _info_axis(self) -> Index: |
452 | 451 | return getattr(self, self._info_axis_name) |
453 | 452 |
|
454 | 453 | @property |
455 | | - def _stat_axis(self): |
| 454 | + def _stat_axis(self) -> Index: |
456 | 455 | return getattr(self, self._stat_axis_name) |
457 | 456 |
|
458 | 457 | @property |
@@ -813,7 +812,7 @@ def squeeze(self, axis=None): |
813 | 812 | >>> df_0a.squeeze() |
814 | 813 | 1 |
815 | 814 | """ |
816 | | - axis = self._AXIS_NAMES if axis is None else (self._get_axis_number(axis),) |
| 815 | + axis = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),) |
817 | 816 | return self.iloc[ |
818 | 817 | tuple( |
819 | 818 | 0 if i in axis and len(a) == 1 else slice(None) |
@@ -1156,7 +1155,7 @@ class name |
1156 | 1155 | result = self if inplace else self.copy(deep=copy) |
1157 | 1156 |
|
1158 | 1157 | for axis in range(self._AXIS_LEN): |
1159 | | - v = axes.get(self._AXIS_NAMES[axis]) |
| 1158 | + v = axes.get(self._get_axis_name(axis)) |
1160 | 1159 | if v is lib.no_default: |
1161 | 1160 | continue |
1162 | 1161 | non_mapper = is_scalar(v) or (is_list_like(v) and not is_dict_like(v)) |
|
0 commit comments