Skip to content

Commit c32eef4

Browse files
committed
SameFrameOrSeries -> FrameOrSeries
1 parent 48a5bb9 commit c32eef4

File tree

12 files changed

+79
-82
lines changed

12 files changed

+79
-82
lines changed

pandas/_typing.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
Dtype = Union[str, np.dtype, "ExtensionDtype"]
4444
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
4545

46-
# FrameOrSeries means either a DataFrame or a Series. E.g.
47-
# `def func(a: FrameOrSeries) -> FrameOrSeries: ...` means that if a Series is passed
48-
# in, either a Series or DataFrame is returned, and if a DataFrame is passed in, either
49-
# a DataFrame or a Series is returned.
50-
FrameOrSeries = Union["DataFrame", "Series"]
46+
# FrameOrSeriesUnion means either a DataFrame or a Series. E.g.
47+
# `def func(a: FrameOrSeriesUnion) -> FrameOrSeriesUnion: ...` means that if a Series
48+
# is passed in, either a Series or DataFrame is returned, and if a DataFrame is passed
49+
# in, either a DataFrame or a Series is returned.
50+
FrameOrSeriesUnion = Union["DataFrame", "Series"]
5151

52-
# SameFrameOrSeries is stricter and ensures that the same subclass of NDFrame always is
53-
# used. E.g. `def func(a: SameFrameOrSeries) -> SameFrameOrSeries: ...` means that if a
52+
# FrameOrSeries is stricter and ensures that the same subclass of NDFrame always is
53+
# used. E.g. `def func(a: FrameOrSeries) -> FrameOrSeries: ...` means that if a
5454
# Series is passed into a function, a Series is always returned and if a DataFrame is
5555
# passed in, a DataFrame is always returned.
56-
SameFrameOrSeries = TypeVar("SameFrameOrSeries", bound="NDFrame")
56+
FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame")
5757

5858
Axis = Union[str, int]
5959
Ordered = Optional[bool]

pandas/core/generic.py

+27-29
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from pandas._config import config
3131

3232
from pandas._libs import Timestamp, iNaT, lib, properties
33-
from pandas._typing import Dtype, FilePathOrBuffer, JSONSerializable, SameFrameOrSeries
33+
from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries, JSONSerializable
3434
from pandas.compat import set_function_name
3535
from pandas.compat._optional import import_optional_dependency
3636
from pandas.compat.numpy import function as nv
@@ -543,12 +543,12 @@ def size(self):
543543
return np.prod(self.shape)
544544

545545
@property
546-
def _selected_obj(self: SameFrameOrSeries) -> SameFrameOrSeries:
546+
def _selected_obj(self: FrameOrSeries) -> FrameOrSeries:
547547
""" internal compat with SelectionMixin """
548548
return self
549549

550550
@property
551-
def _obj_with_exclusions(self: SameFrameOrSeries) -> SameFrameOrSeries:
551+
def _obj_with_exclusions(self: FrameOrSeries) -> FrameOrSeries:
552552
""" internal compat with SelectionMixin """
553553
return self
554554

@@ -4653,7 +4653,7 @@ def f(x):
46534653
else:
46544654
raise TypeError("Must pass either `items`, `like`, or `regex`")
46554655

4656-
def head(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
4656+
def head(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
46574657
"""
46584658
Return the first `n` rows.
46594659
@@ -4726,7 +4726,7 @@ def head(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
47264726

47274727
return self.iloc[:n]
47284728

4729-
def tail(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
4729+
def tail(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
47304730
"""
47314731
Return the last `n` rows.
47324732
@@ -5171,8 +5171,8 @@ def pipe(self, func, *args, **kwargs):
51715171
# Attribute access
51725172

51735173
def __finalize__(
5174-
self: SameFrameOrSeries, other, method=None, **kwargs
5175-
) -> SameFrameOrSeries:
5174+
self: FrameOrSeries, other, method=None, **kwargs
5175+
) -> FrameOrSeries:
51765176
"""
51775177
Propagate metadata from other to self.
51785178
@@ -5641,7 +5641,7 @@ def astype(
56415641
result.columns = self.columns
56425642
return result
56435643

5644-
def copy(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
5644+
def copy(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries:
56455645
"""
56465646
Make a copy of this object's indices and data.
56475647
@@ -5749,10 +5749,10 @@ def copy(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
57495749
data = self._data.copy(deep=deep)
57505750
return self._constructor(data).__finalize__(self)
57515751

5752-
def __copy__(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
5752+
def __copy__(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries:
57535753
return self.copy(deep=deep)
57545754

5755-
def __deepcopy__(self: SameFrameOrSeries, memo=None) -> SameFrameOrSeries:
5755+
def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries:
57565756
"""
57575757
Parameters
57585758
----------
@@ -5762,13 +5762,13 @@ def __deepcopy__(self: SameFrameOrSeries, memo=None) -> SameFrameOrSeries:
57625762
return self.copy(deep=True)
57635763

57645764
def _convert(
5765-
self: SameFrameOrSeries,
5765+
self: FrameOrSeries,
57665766
datetime: bool_t = False,
57675767
numeric: bool_t = False,
57685768
timedelta: bool_t = False,
57695769
coerce: bool_t = False,
57705770
copy: bool_t = True,
5771-
) -> SameFrameOrSeries:
5771+
) -> FrameOrSeries:
57725772
"""
57735773
Attempt to infer better dtype for object columns
57745774
@@ -5860,14 +5860,14 @@ def infer_objects(self: FrameOrSeries) -> FrameOrSeries:
58605860
# Filling NA's
58615861

58625862
def fillna(
5863-
self: SameFrameOrSeries,
5863+
self: FrameOrSeries,
58645864
value=None,
58655865
method=None,
58665866
axis=None,
58675867
inplace: bool_t = False,
58685868
limit=None,
58695869
downcast=None,
5870-
) -> Optional[SameFrameOrSeries]:
5870+
) -> Optional[FrameOrSeries]:
58715871
"""
58725872
Fill NA/NaN values using the specified method.
58735873
@@ -6049,12 +6049,12 @@ def fillna(
60496049
return self._constructor(new_data).__finalize__(self)
60506050

60516051
def ffill(
6052-
self: SameFrameOrSeries,
6052+
self: FrameOrSeries,
60536053
axis=None,
60546054
inplace: bool_t = False,
60556055
limit=None,
60566056
downcast=None,
6057-
) -> Optional[SameFrameOrSeries]:
6057+
) -> Optional[FrameOrSeries]:
60586058
"""
60596059
Synonym for :meth:`DataFrame.fillna` with ``method='ffill'``.
60606060
@@ -6068,12 +6068,12 @@ def ffill(
60686068
)
60696069

60706070
def bfill(
6071-
self: SameFrameOrSeries,
6071+
self: FrameOrSeries,
60726072
axis=None,
60736073
inplace: bool_t = False,
60746074
limit=None,
60756075
downcast=None,
6076-
) -> Optional[SameFrameOrSeries]:
6076+
) -> Optional[FrameOrSeries]:
60776077
"""
60786078
Synonym for :meth:`DataFrame.fillna` with ``method='bfill'``.
60796079
@@ -8038,14 +8038,14 @@ def last(self: FrameOrSeries, offset) -> FrameOrSeries:
80388038
return self.iloc[start:]
80398039

80408040
def rank(
8041-
self: SameFrameOrSeries,
8041+
self: FrameOrSeries,
80428042
axis=0,
80438043
method: str = "average",
80448044
numeric_only: Optional[bool_t] = None,
80458045
na_option: str = "keep",
80468046
ascending: bool_t = True,
80478047
pct: bool_t = False,
8048-
) -> SameFrameOrSeries:
8048+
) -> FrameOrSeries:
80498049
"""
80508050
Compute numerical data ranks (1 through n) along axis.
80518051
@@ -8853,9 +8853,7 @@ def shift(
88538853

88548854
return self._constructor(new_data).__finalize__(self)
88558855

8856-
def slice_shift(
8857-
self: SameFrameOrSeries, periods: int = 1, axis=0
8858-
) -> SameFrameOrSeries:
8856+
def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
88598857
"""
88608858
Equivalent to `shift` without copying data.
88618859
@@ -8955,8 +8953,8 @@ def tshift(
89558953
return self._constructor(new_data).__finalize__(self)
89568954

89578955
def truncate(
8958-
self: SameFrameOrSeries, before=None, after=None, axis=None, copy: bool_t = True
8959-
) -> SameFrameOrSeries:
8956+
self: FrameOrSeries, before=None, after=None, axis=None, copy: bool_t = True
8957+
) -> FrameOrSeries:
89608958
"""
89618959
Truncate a Series or DataFrame before and after some index value.
89628960
@@ -9109,8 +9107,8 @@ def truncate(
91099107
return result
91109108

91119109
def tz_convert(
9112-
self: SameFrameOrSeries, tz, axis=0, level=None, copy: bool_t = True
9113-
) -> SameFrameOrSeries:
9110+
self: FrameOrSeries, tz, axis=0, level=None, copy: bool_t = True
9111+
) -> FrameOrSeries:
91149112
"""
91159113
Convert tz-aware axis to target time zone.
91169114
@@ -9166,14 +9164,14 @@ def _tz_convert(ax, tz):
91669164
return result.__finalize__(self)
91679165

91689166
def tz_localize(
9169-
self: SameFrameOrSeries,
9167+
self: FrameOrSeries,
91709168
tz,
91719169
axis=0,
91729170
level=None,
91739171
copy: bool_t = True,
91749172
ambiguous="raise",
91759173
nonexistent: str = "raise",
9176-
) -> SameFrameOrSeries:
9174+
) -> FrameOrSeries:
91779175
"""
91789176
Localize tz-naive index of a Series or DataFrame to target time zone.
91799177

pandas/core/groupby/generic.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import numpy as np
3131

3232
from pandas._libs import Timestamp, lib
33-
from pandas._typing import SameFrameOrSeries
33+
from pandas._typing import FrameOrSeries
3434
from pandas.util._decorators import Appender, Substitution
3535

3636
from pandas.core.dtypes.cast import (
@@ -86,7 +86,7 @@
8686
ScalarResult = typing.TypeVar("ScalarResult")
8787

8888

89-
def generate_property(name: str, klass: Type[SameFrameOrSeries]):
89+
def generate_property(name: str, klass: Type[FrameOrSeries]):
9090
"""
9191
Create a property for a GroupBy subclass to dispatch to DataFrame/Series.
9292
@@ -109,9 +109,7 @@ def prop(self):
109109
return property(prop)
110110

111111

112-
def pin_whitelisted_properties(
113-
klass: Type[SameFrameOrSeries], whitelist: FrozenSet[str]
114-
):
112+
def pin_whitelisted_properties(klass: Type[FrameOrSeries], whitelist: FrozenSet[str]):
115113
"""
116114
Create GroupBy member defs for DataFrame/Series names in a whitelist.
117115

pandas/core/groupby/groupby.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class providing the base-class of operations.
3333

3434
from pandas._libs import Timestamp
3535
import pandas._libs.groupby as libgroupby
36-
from pandas._typing import SameFrameOrSeries, Scalar
36+
from pandas._typing import FrameOrSeries, Scalar
3737
from pandas.compat import set_function_name
3838
from pandas.compat.numpy import function as nv
3939
from pandas.errors import AbstractMethodError
@@ -2439,8 +2439,8 @@ def tail(self, n=5):
24392439
return self._selected_obj[mask]
24402440

24412441
def _reindex_output(
2442-
self, output: SameFrameOrSeries, fill_value: Scalar = np.NaN
2443-
) -> SameFrameOrSeries:
2442+
self, output: FrameOrSeries, fill_value: Scalar = np.NaN
2443+
) -> FrameOrSeries:
24442444
"""
24452445
If we have categorical groupers, then we might want to make sure that
24462446
we have a fully re-indexed output to the levels. This means expanding

pandas/core/groupby/grouper.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from pandas._typing import SameFrameOrSeries
10+
from pandas._typing import FrameOrSeries
1111
from pandas.util._decorators import cache_readonly
1212

1313
from pandas.core.dtypes.common import (
@@ -141,7 +141,7 @@ def _get_grouper(self, obj, validate: bool = True):
141141
)
142142
return self.binner, self.grouper, self.obj
143143

144-
def _set_grouper(self, obj: SameFrameOrSeries, sort: bool = False):
144+
def _set_grouper(self, obj: FrameOrSeries, sort: bool = False):
145145
"""
146146
given an object and the specifications, setup the internal grouper
147147
for this particular specification
@@ -244,7 +244,7 @@ def __init__(
244244
self,
245245
index: Index,
246246
grouper=None,
247-
obj: Optional[SameFrameOrSeries] = None,
247+
obj: Optional[FrameOrSeries] = None,
248248
name=None,
249249
level=None,
250250
sort: bool = True,
@@ -424,15 +424,15 @@ def groups(self) -> Dict[Hashable, np.ndarray]:
424424

425425

426426
def get_grouper(
427-
obj: SameFrameOrSeries,
427+
obj: FrameOrSeries,
428428
key=None,
429429
axis: int = 0,
430430
level=None,
431431
sort: bool = True,
432432
observed: bool = False,
433433
mutated: bool = False,
434434
validate: bool = True,
435-
) -> "Tuple[ops.BaseGrouper, List[Hashable], SameFrameOrSeries]":
435+
) -> "Tuple[ops.BaseGrouper, List[Hashable], FrameOrSeries]":
436436
"""
437437
Create and return a BaseGrouper, which is an internal
438438
mapping of how to create the grouper indexers.

0 commit comments

Comments
 (0)