Skip to content

Commit 4988d6e

Browse files
authored
TYP: rename FrameOrSeries to NDFrameT (#43752)
1 parent 21c2991 commit 4988d6e

File tree

14 files changed

+164
-171
lines changed

14 files changed

+164
-171
lines changed

pandas/_typing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@
101101
]
102102
Timezone = Union[str, tzinfo]
103103

104-
# FrameOrSeries is stricter and ensures that the same subclass of NDFrame always is
105-
# used. E.g. `def func(a: FrameOrSeries) -> FrameOrSeries: ...` means that if a
104+
# NDFrameT is stricter and ensures that the same subclass of NDFrame always is
105+
# used. E.g. `def func(a: NDFrameT) -> NDFrameT: ...` means that if a
106106
# Series is passed into a function, a Series is always returned and if a DataFrame is
107107
# passed in, a DataFrame is always returned.
108-
FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame")
108+
NDFrameT = TypeVar("NDFrameT", bound="NDFrame")
109109

110110
Axis = Union[str, int]
111111
IndexLabel = Union[Hashable, Sequence[Hashable]]

pandas/core/apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
AggFuncTypeDict,
3131
AggObjType,
3232
Axis,
33-
FrameOrSeries,
33+
NDFrameT,
3434
)
3535
from pandas.util._decorators import cache_readonly
3636
from pandas.util._exceptions import find_stack_level
@@ -1120,7 +1120,7 @@ def apply_standard(self) -> DataFrame | Series:
11201120
class GroupByApply(Apply):
11211121
def __init__(
11221122
self,
1123-
obj: GroupBy[FrameOrSeries],
1123+
obj: GroupBy[NDFrameT],
11241124
func: AggFuncType,
11251125
args,
11261126
kwargs,

pandas/core/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from pandas._typing import (
2323
ArrayLike,
2424
DtypeObj,
25-
FrameOrSeries,
2625
IndexLabel,
26+
NDFrameT,
2727
Shape,
2828
npt,
2929
)
@@ -181,13 +181,13 @@ class SpecificationError(Exception):
181181
pass
182182

183183

184-
class SelectionMixin(Generic[FrameOrSeries]):
184+
class SelectionMixin(Generic[NDFrameT]):
185185
"""
186186
mixin implementing the selection & aggregation interface on a group-like
187187
object sub-classes need to define: obj, exclusions
188188
"""
189189

190-
obj: FrameOrSeries
190+
obj: NDFrameT
191191
_selection: IndexLabel | None = None
192192
exclusions: frozenset[Hashable]
193193
_internal_names = ["_cache", "__setstate__"]

pandas/core/computation/align.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import numpy as np
1717

18-
from pandas._typing import FrameOrSeries
1918
from pandas.errors import PerformanceWarning
2019

2120
from pandas.core.dtypes.generic import (
@@ -28,14 +27,15 @@
2827
from pandas.core.computation.common import result_type_many
2928

3029
if TYPE_CHECKING:
30+
from pandas.core.generic import NDFrame
3131
from pandas.core.indexes.api import Index
3232

3333

3434
def _align_core_single_unary_op(
3535
term,
36-
) -> tuple[partial | type[FrameOrSeries], dict[str, Index] | None]:
36+
) -> tuple[partial | type[NDFrame], dict[str, Index] | None]:
3737

38-
typ: partial | type[FrameOrSeries]
38+
typ: partial | type[NDFrame]
3939
axes: dict[str, Index] | None = None
4040

4141
if isinstance(term.value, np.ndarray):
@@ -49,7 +49,7 @@ def _align_core_single_unary_op(
4949

5050

5151
def _zip_axes_from_type(
52-
typ: type[FrameOrSeries], new_axes: Sequence[Index]
52+
typ: type[NDFrame], new_axes: Sequence[Index]
5353
) -> dict[str, Index]:
5454
return {name: new_axes[i] for i, name in enumerate(typ._AXIS_ORDERS)}
5555

pandas/core/describe.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import numpy as np
2323

2424
from pandas._libs.tslibs import Timestamp
25-
from pandas._typing import FrameOrSeries
25+
from pandas._typing import NDFrameT
2626
from pandas.util._validators import validate_percentile
2727

2828
from pandas.core.dtypes.common import (
@@ -45,12 +45,12 @@
4545

4646
def describe_ndframe(
4747
*,
48-
obj: FrameOrSeries,
48+
obj: NDFrameT,
4949
include: str | Sequence[str] | None,
5050
exclude: str | Sequence[str] | None,
5151
datetime_is_numeric: bool,
5252
percentiles: Sequence[float] | np.ndarray | None,
53-
) -> FrameOrSeries:
53+
) -> NDFrameT:
5454
"""Describe series or dataframe.
5555
5656
Called from pandas.core.generic.NDFrame.describe()
@@ -91,7 +91,7 @@ def describe_ndframe(
9191
)
9292

9393
result = describer.describe(percentiles=percentiles)
94-
return cast(FrameOrSeries, result)
94+
return cast(NDFrameT, result)
9595

9696

9797
class NDFrameDescriberAbstract(ABC):

0 commit comments

Comments
 (0)