Skip to content

Commit ea706b3

Browse files
authored
TYP: make more internal funcs keyword-only (#37688)
1 parent 188258b commit ea706b3

File tree

20 files changed

+71
-39
lines changed

20 files changed

+71
-39
lines changed

pandas/core/array_algos/masked_reductions.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def _sumprod(
1717
func: Callable,
1818
values: np.ndarray,
1919
mask: np.ndarray,
20+
*,
2021
skipna: bool = True,
2122
min_count: int = 0,
2223
):
@@ -52,19 +53,25 @@ def _sumprod(
5253
return func(values, where=~mask)
5354

5455

55-
def sum(values: np.ndarray, mask: np.ndarray, skipna: bool = True, min_count: int = 0):
56+
def sum(
57+
values: np.ndarray, mask: np.ndarray, *, skipna: bool = True, min_count: int = 0
58+
):
5659
return _sumprod(
5760
np.sum, values=values, mask=mask, skipna=skipna, min_count=min_count
5861
)
5962

6063

61-
def prod(values: np.ndarray, mask: np.ndarray, skipna: bool = True, min_count: int = 0):
64+
def prod(
65+
values: np.ndarray, mask: np.ndarray, *, skipna: bool = True, min_count: int = 0
66+
):
6267
return _sumprod(
6368
np.prod, values=values, mask=mask, skipna=skipna, min_count=min_count
6469
)
6570

6671

67-
def _minmax(func: Callable, values: np.ndarray, mask: np.ndarray, skipna: bool = True):
72+
def _minmax(
73+
func: Callable, values: np.ndarray, mask: np.ndarray, *, skipna: bool = True
74+
):
6875
"""
6976
Reduction for 1D masked array.
7077
@@ -94,9 +101,9 @@ def _minmax(func: Callable, values: np.ndarray, mask: np.ndarray, skipna: bool =
94101
return libmissing.NA
95102

96103

97-
def min(values: np.ndarray, mask: np.ndarray, skipna: bool = True):
104+
def min(values: np.ndarray, mask: np.ndarray, *, skipna: bool = True):
98105
return _minmax(np.min, values=values, mask=mask, skipna=skipna)
99106

100107

101-
def max(values: np.ndarray, mask: np.ndarray, skipna: bool = True):
108+
def max(values: np.ndarray, mask: np.ndarray, *, skipna: bool = True):
102109
return _minmax(np.max, values=values, mask=mask, skipna=skipna)

pandas/core/arrays/_mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _validate_scalar(self, value):
5454
def take(
5555
self: _T,
5656
indices: Sequence[int],
57+
*,
5758
allow_fill: bool = False,
5859
fill_value: Any = None,
5960
axis: int = 0,
@@ -246,7 +247,7 @@ def fillna(self: _T, value=None, method=None, limit=None) -> _T:
246247
# ------------------------------------------------------------------------
247248
# Reductions
248249

249-
def _reduce(self, name: str, skipna: bool = True, **kwargs):
250+
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
250251
meth = getattr(self, name, None)
251252
if meth:
252253
return meth(skipna=skipna, **kwargs)

pandas/core/arrays/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class ExtensionArray:
173173
# ------------------------------------------------------------------------
174174

175175
@classmethod
176-
def _from_sequence(cls, scalars, dtype=None, copy=False):
176+
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
177177
"""
178178
Construct a new ExtensionArray from a sequence of scalars.
179179
@@ -195,7 +195,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
195195
raise AbstractMethodError(cls)
196196

197197
@classmethod
198-
def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
198+
def _from_sequence_of_strings(cls, strings, *, dtype=None, copy=False):
199199
"""
200200
Construct a new ExtensionArray from a sequence of strings.
201201
@@ -922,7 +922,11 @@ def repeat(self, repeats, axis=None):
922922
# ------------------------------------------------------------------------
923923

924924
def take(
925-
self, indices: Sequence[int], allow_fill: bool = False, fill_value: Any = None
925+
self,
926+
indices: Sequence[int],
927+
*,
928+
allow_fill: bool = False,
929+
fill_value: Any = None,
926930
) -> "ExtensionArray":
927931
"""
928932
Take elements from an array.
@@ -1153,7 +1157,7 @@ def _concat_same_type(
11531157
# of objects
11541158
_can_hold_na = True
11551159

1156-
def _reduce(self, name: str, skipna: bool = True, **kwargs):
1160+
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
11571161
"""
11581162
Return a scalar result of performing the reduction operation.
11591163

pandas/core/arrays/boolean.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,17 @@ def dtype(self) -> BooleanDtype:
273273
return self._dtype
274274

275275
@classmethod
276-
def _from_sequence(cls, scalars, dtype=None, copy: bool = False) -> "BooleanArray":
276+
def _from_sequence(
277+
cls, scalars, *, dtype=None, copy: bool = False
278+
) -> "BooleanArray":
277279
if dtype:
278280
assert dtype == "boolean"
279281
values, mask = coerce_to_array(scalars, copy=copy)
280282
return BooleanArray(values, mask)
281283

282284
@classmethod
283285
def _from_sequence_of_strings(
284-
cls, strings: List[str], dtype=None, copy: bool = False
286+
cls, strings: List[str], *, dtype=None, copy: bool = False
285287
) -> "BooleanArray":
286288
def map_string(s):
287289
if isna(s):
@@ -294,7 +296,7 @@ def map_string(s):
294296
raise ValueError(f"{s} cannot be cast to bool")
295297

296298
scalars = [map_string(x) for x in strings]
297-
return cls._from_sequence(scalars, dtype, copy)
299+
return cls._from_sequence(scalars, dtype=dtype, copy=copy)
298300

299301
_HANDLED_TYPES = (np.ndarray, numbers.Number, bool, np.bool_)
300302

@@ -682,12 +684,12 @@ def _arith_method(self, other, op):
682684

683685
return self._maybe_mask_result(result, mask, other, op_name)
684686

685-
def _reduce(self, name: str, skipna: bool = True, **kwargs):
687+
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
686688

687689
if name in {"any", "all"}:
688690
return getattr(self, name)(skipna=skipna, **kwargs)
689691

690-
return super()._reduce(name, skipna, **kwargs)
692+
return super()._reduce(name, skipna=skipna, **kwargs)
691693

692694
def _maybe_mask_result(self, result, mask, other, op_name: str):
693695
"""

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _constructor(self) -> Type["Categorical"]:
385385
return Categorical
386386

387387
@classmethod
388-
def _from_sequence(cls, scalars, dtype=None, copy=False):
388+
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
389389
return Categorical(scalars, dtype=dtype)
390390

391391
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike:

pandas/core/arrays/datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def _simple_new(
301301
return result
302302

303303
@classmethod
304-
def _from_sequence(cls, scalars, dtype=None, copy: bool = False):
304+
def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False):
305305
return cls._from_sequence_not_strict(scalars, dtype=dtype, copy=copy)
306306

307307
@classmethod

pandas/core/arrays/floating.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,18 @@ def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False):
275275
super().__init__(values, mask, copy=copy)
276276

277277
@classmethod
278-
def _from_sequence(cls, scalars, dtype=None, copy: bool = False) -> "FloatingArray":
278+
def _from_sequence(
279+
cls, scalars, *, dtype=None, copy: bool = False
280+
) -> "FloatingArray":
279281
values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
280282
return FloatingArray(values, mask)
281283

282284
@classmethod
283285
def _from_sequence_of_strings(
284-
cls, strings, dtype=None, copy: bool = False
286+
cls, strings, *, dtype=None, copy: bool = False
285287
) -> "FloatingArray":
286288
scalars = to_numeric(strings, errors="raise")
287-
return cls._from_sequence(scalars, dtype, copy)
289+
return cls._from_sequence(scalars, dtype=dtype, copy=copy)
288290

289291
_HANDLED_TYPES = (np.ndarray, numbers.Number)
290292

pandas/core/arrays/integer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,17 @@ def __abs__(self):
358358
return type(self)(np.abs(self._data), self._mask)
359359

360360
@classmethod
361-
def _from_sequence(cls, scalars, dtype=None, copy: bool = False) -> "IntegerArray":
361+
def _from_sequence(
362+
cls, scalars, *, dtype=None, copy: bool = False
363+
) -> "IntegerArray":
362364
return integer_array(scalars, dtype=dtype, copy=copy)
363365

364366
@classmethod
365367
def _from_sequence_of_strings(
366-
cls, strings, dtype=None, copy: bool = False
368+
cls, strings, *, dtype=None, copy: bool = False
367369
) -> "IntegerArray":
368370
scalars = to_numeric(strings, errors="raise")
369-
return cls._from_sequence(scalars, dtype, copy)
371+
return cls._from_sequence(scalars, dtype=dtype, copy=copy)
370372

371373
_HANDLED_TYPES = (np.ndarray, numbers.Number)
372374

pandas/core/arrays/interval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _simple_new(cls, data, closed="right"):
227227
return result
228228

229229
@classmethod
230-
def _from_sequence(cls, scalars, dtype=None, copy=False):
230+
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
231231
return cls(scalars, dtype=dtype, copy=copy)
232232

233233
@classmethod
@@ -788,7 +788,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> "IntervalArray":
788788
b = empty
789789
return self._concat_same_type([a, b])
790790

791-
def take(self, indices, allow_fill=False, fill_value=None, axis=None, **kwargs):
791+
def take(self, indices, *, allow_fill=False, fill_value=None, axis=None, **kwargs):
792792
"""
793793
Take elements from the IntervalArray.
794794

pandas/core/arrays/masked.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def _concat_same_type(cls: Type[BaseMaskedArrayT], to_concat) -> BaseMaskedArray
269269
def take(
270270
self: BaseMaskedArrayT,
271271
indexer,
272+
*,
272273
allow_fill: bool = False,
273274
fill_value: Optional[Scalar] = None,
274275
) -> BaseMaskedArrayT:
@@ -357,7 +358,7 @@ def value_counts(self, dropna: bool = True) -> "Series":
357358

358359
return Series(counts, index=index)
359360

360-
def _reduce(self, name: str, skipna: bool = True, **kwargs):
361+
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
361362
data = self._data
362363
mask = self._mask
363364

0 commit comments

Comments
 (0)