Skip to content

Commit 84d1c37

Browse files
committed
SameFrameOrSeries -> FrameOrSeries
1 parent 0d49daa commit 84d1c37

File tree

12 files changed

+79
-82
lines changed

12 files changed

+79
-82
lines changed

pandas/_testing.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
import pandas._libs.testing as _testing
25-
from pandas._typing import SameFrameOrSeries
25+
from pandas._typing import FrameOrSeries
2626
from pandas.compat import _get_lzma_file, _import_lzma
2727

2828
from pandas.core.dtypes.common import (
@@ -101,9 +101,7 @@ def reset_display_options():
101101
pd.reset_option("^display.", silent=True)
102102

103103

104-
def round_trip_pickle(
105-
obj: SameFrameOrSeries, path: Optional[str] = None
106-
) -> SameFrameOrSeries:
104+
def round_trip_pickle(obj: FrameOrSeries, path: Optional[str] = None) -> FrameOrSeries:
107105
"""
108106
Pickle an object and then read it again.
109107

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
@@ -552,12 +552,12 @@ def size(self):
552552
return np.prod(self.shape)
553553

554554
@property
555-
def _selected_obj(self: SameFrameOrSeries) -> SameFrameOrSeries:
555+
def _selected_obj(self: FrameOrSeries) -> FrameOrSeries:
556556
""" internal compat with SelectionMixin """
557557
return self
558558

559559
@property
560-
def _obj_with_exclusions(self: SameFrameOrSeries) -> SameFrameOrSeries:
560+
def _obj_with_exclusions(self: FrameOrSeries) -> FrameOrSeries:
561561
""" internal compat with SelectionMixin """
562562
return self
563563

@@ -4670,7 +4670,7 @@ def f(x):
46704670
else:
46714671
raise TypeError("Must pass either `items`, `like`, or `regex`")
46724672

4673-
def head(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
4673+
def head(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
46744674
"""
46754675
Return the first `n` rows.
46764676
@@ -4743,7 +4743,7 @@ def head(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
47434743

47444744
return self.iloc[:n]
47454745

4746-
def tail(self: SameFrameOrSeries, n: int = 5) -> SameFrameOrSeries:
4746+
def tail(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
47474747
"""
47484748
Return the last `n` rows.
47494749
@@ -5188,8 +5188,8 @@ def pipe(self, func, *args, **kwargs):
51885188
# Attribute access
51895189

51905190
def __finalize__(
5191-
self: SameFrameOrSeries, other, method=None, **kwargs
5192-
) -> SameFrameOrSeries:
5191+
self: FrameOrSeries, other, method=None, **kwargs
5192+
) -> FrameOrSeries:
51935193
"""
51945194
Propagate metadata from other to self.
51955195
@@ -5658,7 +5658,7 @@ def astype(
56585658
result.columns = self.columns
56595659
return result
56605660

5661-
def copy(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
5661+
def copy(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries:
56625662
"""
56635663
Make a copy of this object's indices and data.
56645664
@@ -5766,10 +5766,10 @@ def copy(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
57665766
data = self._data.copy(deep=deep)
57675767
return self._constructor(data).__finalize__(self)
57685768

5769-
def __copy__(self: SameFrameOrSeries, deep: bool_t = True) -> SameFrameOrSeries:
5769+
def __copy__(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries:
57705770
return self.copy(deep=deep)
57715771

5772-
def __deepcopy__(self: SameFrameOrSeries, memo=None) -> SameFrameOrSeries:
5772+
def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries:
57735773
"""
57745774
Parameters
57755775
----------
@@ -5779,13 +5779,13 @@ def __deepcopy__(self: SameFrameOrSeries, memo=None) -> SameFrameOrSeries:
57795779
return self.copy(deep=True)
57805780

57815781
def _convert(
5782-
self: SameFrameOrSeries,
5782+
self: FrameOrSeries,
57835783
datetime: bool_t = False,
57845784
numeric: bool_t = False,
57855785
timedelta: bool_t = False,
57865786
coerce: bool_t = False,
57875787
copy: bool_t = True,
5788-
) -> SameFrameOrSeries:
5788+
) -> FrameOrSeries:
57895789
"""
57905790
Attempt to infer better dtype for object columns
57915791
@@ -5877,14 +5877,14 @@ def infer_objects(self: FrameOrSeries) -> FrameOrSeries:
58775877
# Filling NA's
58785878

58795879
def fillna(
5880-
self: SameFrameOrSeries,
5880+
self: FrameOrSeries,
58815881
value=None,
58825882
method=None,
58835883
axis=None,
58845884
inplace: bool_t = False,
58855885
limit=None,
58865886
downcast=None,
5887-
) -> Optional[SameFrameOrSeries]:
5887+
) -> Optional[FrameOrSeries]:
58885888
"""
58895889
Fill NA/NaN values using the specified method.
58905890
@@ -6066,12 +6066,12 @@ def fillna(
60666066
return self._constructor(new_data).__finalize__(self)
60676067

60686068
def ffill(
6069-
self: SameFrameOrSeries,
6069+
self: FrameOrSeries,
60706070
axis=None,
60716071
inplace: bool_t = False,
60726072
limit=None,
60736073
downcast=None,
6074-
) -> Optional[SameFrameOrSeries]:
6074+
) -> Optional[FrameOrSeries]:
60756075
"""
60766076
Synonym for :meth:`DataFrame.fillna` with ``method='ffill'``.
60776077
@@ -6085,12 +6085,12 @@ def ffill(
60856085
)
60866086

60876087
def bfill(
6088-
self: SameFrameOrSeries,
6088+
self: FrameOrSeries,
60896089
axis=None,
60906090
inplace: bool_t = False,
60916091
limit=None,
60926092
downcast=None,
6093-
) -> Optional[SameFrameOrSeries]:
6093+
) -> Optional[FrameOrSeries]:
60946094
"""
60956095
Synonym for :meth:`DataFrame.fillna` with ``method='bfill'``.
60966096
@@ -8055,14 +8055,14 @@ def last(self: FrameOrSeries, offset) -> FrameOrSeries:
80558055
return self.iloc[start:]
80568056

80578057
def rank(
8058-
self: SameFrameOrSeries,
8058+
self: FrameOrSeries,
80598059
axis=0,
80608060
method: str = "average",
80618061
numeric_only: Optional[bool_t] = None,
80628062
na_option: str = "keep",
80638063
ascending: bool_t = True,
80648064
pct: bool_t = False,
8065-
) -> SameFrameOrSeries:
8065+
) -> FrameOrSeries:
80668066
"""
80678067
Compute numerical data ranks (1 through n) along axis.
80688068
@@ -8870,9 +8870,7 @@ def shift(
88708870

88718871
return self._constructor(new_data).__finalize__(self)
88728872

8873-
def slice_shift(
8874-
self: SameFrameOrSeries, periods: int = 1, axis=0
8875-
) -> SameFrameOrSeries:
8873+
def slice_shift(self: FrameOrSeries, periods: int = 1, axis=0) -> FrameOrSeries:
88768874
"""
88778875
Equivalent to `shift` without copying data.
88788876
@@ -8972,8 +8970,8 @@ def tshift(
89728970
return self._constructor(new_data).__finalize__(self)
89738971

89748972
def truncate(
8975-
self: SameFrameOrSeries, before=None, after=None, axis=None, copy: bool_t = True
8976-
) -> SameFrameOrSeries:
8973+
self: FrameOrSeries, before=None, after=None, axis=None, copy: bool_t = True
8974+
) -> FrameOrSeries:
89778975
"""
89788976
Truncate a Series or DataFrame before and after some index value.
89798977
@@ -9126,8 +9124,8 @@ def truncate(
91269124
return result
91279125

91289126
def tz_convert(
9129-
self: SameFrameOrSeries, tz, axis=0, level=None, copy: bool_t = True
9130-
) -> SameFrameOrSeries:
9127+
self: FrameOrSeries, tz, axis=0, level=None, copy: bool_t = True
9128+
) -> FrameOrSeries:
91319129
"""
91329130
Convert tz-aware axis to target time zone.
91339131
@@ -9183,14 +9181,14 @@ def _tz_convert(ax, tz):
91839181
return result.__finalize__(self)
91849182

91859183
def tz_localize(
9186-
self: SameFrameOrSeries,
9184+
self: FrameOrSeries,
91879185
tz,
91889186
axis=0,
91899187
level=None,
91909188
copy: bool_t = True,
91919189
ambiguous="raise",
91929190
nonexistent: str = "raise",
9193-
) -> SameFrameOrSeries:
9191+
) -> FrameOrSeries:
91949192
"""
91959193
Localize tz-naive index of a Series or DataFrame to target time zone.
91969194

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)