|
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,36 @@ 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. Call ._get_axis_number instead", |
| 319 | + FutureWarning, |
| 320 | + stacklevel=3, |
| 321 | + ) |
| 322 | + return {"index": 0} |
| 323 | + |
| 324 | + @property |
| 325 | + def _AXIS_NAMES(self) -> Dict[int, str]: |
| 326 | + """.. deprecated:: 1.1.0""" |
| 327 | + warnings.warn( |
| 328 | + "_AXIS_NAMES has been deprecated. Call ._get_axis_name instead", |
| 329 | + FutureWarning, |
| 330 | + stacklevel=3, |
| 331 | + ) |
| 332 | + return {0: "index"} |
| 333 | + |
318 | 334 | def _construct_axes_dict(self, axes=None, **kwargs):
|
319 | 335 | """Return an axes dictionary for myself."""
|
320 | 336 | d = {a: self._get_axis(a) for a in (axes or self._AXIS_ORDERS)}
|
@@ -353,37 +369,24 @@ def _construct_axes_from_arguments(
|
353 | 369 | return axes, kwargs
|
354 | 370 |
|
355 | 371 | @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__}") |
| 372 | + def _get_axis_number(cls, axis: Axis) -> int: |
| 373 | + try: |
| 374 | + return cls._AXIS_TO_AXIS_NUMBER[axis] |
| 375 | + except KeyError: |
| 376 | + raise ValueError(f"No axis named {axis} for object type {cls.__name__}") |
367 | 377 |
|
368 | 378 | @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__}") |
| 379 | + def _get_axis_name(cls, axis: Axis) -> str: |
| 380 | + axis_number = cls._get_axis_number(axis) |
| 381 | + return cls._AXIS_ORDERS[axis_number] |
380 | 382 |
|
381 |
| - def _get_axis(self, axis) -> Index: |
382 |
| - name = self._get_axis_name(axis) |
383 |
| - return getattr(self, name) |
| 383 | + def _get_axis(self, axis: Axis) -> Index: |
| 384 | + axis_number = self._get_axis_number(axis) |
| 385 | + assert axis_number in {0, 1} |
| 386 | + return self.index if axis_number == 0 else self.columns |
384 | 387 |
|
385 | 388 | @classmethod
|
386 |
| - def _get_block_manager_axis(cls, axis) -> int: |
| 389 | + def _get_block_manager_axis(cls, axis: Axis) -> int: |
387 | 390 | """Map the axis to the block_manager axis."""
|
388 | 391 | axis = cls._get_axis_number(axis)
|
389 | 392 | if cls._AXIS_REVERSED:
|
@@ -448,11 +451,11 @@ def _get_cleaned_column_resolvers(self) -> Dict[str, ABCSeries]:
|
448 | 451 | }
|
449 | 452 |
|
450 | 453 | @property
|
451 |
| - def _info_axis(self): |
| 454 | + def _info_axis(self) -> Index: |
452 | 455 | return getattr(self, self._info_axis_name)
|
453 | 456 |
|
454 | 457 | @property
|
455 |
| - def _stat_axis(self): |
| 458 | + def _stat_axis(self) -> Index: |
456 | 459 | return getattr(self, self._stat_axis_name)
|
457 | 460 |
|
458 | 461 | @property
|
@@ -813,7 +816,7 @@ def squeeze(self, axis=None):
|
813 | 816 | >>> df_0a.squeeze()
|
814 | 817 | 1
|
815 | 818 | """
|
816 |
| - axis = self._AXIS_NAMES if axis is None else (self._get_axis_number(axis),) |
| 819 | + axis = range(self._AXIS_LEN) if axis is None else (self._get_axis_number(axis),) |
817 | 820 | return self.iloc[
|
818 | 821 | tuple(
|
819 | 822 | 0 if i in axis and len(a) == 1 else slice(None)
|
@@ -1156,7 +1159,7 @@ class name
|
1156 | 1159 | result = self if inplace else self.copy(deep=copy)
|
1157 | 1160 |
|
1158 | 1161 | for axis in range(self._AXIS_LEN):
|
1159 |
| - v = axes.get(self._AXIS_NAMES[axis]) |
| 1162 | + v = axes.get(self._get_axis_name(axis)) |
1160 | 1163 | if v is lib.no_default:
|
1161 | 1164 | continue
|
1162 | 1165 | non_mapper = is_scalar(v) or (is_list_like(v) and not is_dict_like(v))
|
|
0 commit comments