Skip to content

Commit 0b4bac7

Browse files
ShaharNavehsimonjayhawkins
authored andcommitted
TYP: typing annotations (#30901)
1 parent 03cdcb6 commit 0b4bac7

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

pandas/_config/display.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Unopinionated display configuration.
33
"""
4+
45
import locale
56
import sys
67

@@ -11,7 +12,7 @@
1112
_initial_defencoding = None
1213

1314

14-
def detect_console_encoding():
15+
def detect_console_encoding() -> str:
1516
"""
1617
Try to find the most capable encoding supported by the console.
1718
slightly modified from the way IPython handles the same issue.

pandas/_config/localization.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
@contextmanager
15-
def set_locale(new_locale, lc_var=locale.LC_ALL):
15+
def set_locale(new_locale, lc_var: int = locale.LC_ALL):
1616
"""
1717
Context manager for temporarily setting a locale.
1818
@@ -44,7 +44,7 @@ def set_locale(new_locale, lc_var=locale.LC_ALL):
4444
locale.setlocale(lc_var, current_locale)
4545

4646

47-
def can_set_locale(lc, lc_var=locale.LC_ALL):
47+
def can_set_locale(lc: str, lc_var: int = locale.LC_ALL) -> bool:
4848
"""
4949
Check to see if we can set a locale, and subsequently get the locale,
5050
without raising an Exception.
@@ -58,7 +58,7 @@ def can_set_locale(lc, lc_var=locale.LC_ALL):
5858
5959
Returns
6060
-------
61-
is_valid : bool
61+
bool
6262
Whether the passed locale can be set
6363
"""
6464

pandas/compat/numpy/function.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@
3333

3434

3535
class CompatValidator:
36-
def __init__(self, defaults, fname=None, method=None, max_fname_arg_count=None):
36+
def __init__(
37+
self,
38+
defaults,
39+
fname=None,
40+
method: Optional[str] = None,
41+
max_fname_arg_count=None,
42+
):
3743
self.fname = fname
3844
self.method = method
3945
self.defaults = defaults
4046
self.max_fname_arg_count = max_fname_arg_count
4147

42-
def __call__(self, args, kwargs, fname=None, max_fname_arg_count=None, method=None):
48+
def __call__(
49+
self,
50+
args,
51+
kwargs,
52+
fname=None,
53+
max_fname_arg_count=None,
54+
method: Optional[str] = None,
55+
) -> None:
4356
if args or kwargs:
4457
fname = self.fname if fname is None else fname
4558
max_fname_arg_count = (
@@ -300,7 +313,7 @@ def validate_take_with_convert(convert, args, kwargs):
300313
)
301314

302315

303-
def validate_window_func(name, args, kwargs):
316+
def validate_window_func(name, args, kwargs) -> None:
304317
numpy_args = ("axis", "dtype", "out")
305318
msg = (
306319
f"numpy operations are not valid with window objects. "
@@ -315,7 +328,7 @@ def validate_window_func(name, args, kwargs):
315328
raise UnsupportedFunctionCall(msg)
316329

317330

318-
def validate_rolling_func(name, args, kwargs):
331+
def validate_rolling_func(name, args, kwargs) -> None:
319332
numpy_args = ("axis", "dtype", "out")
320333
msg = (
321334
f"numpy operations are not valid with window objects. "
@@ -330,7 +343,7 @@ def validate_rolling_func(name, args, kwargs):
330343
raise UnsupportedFunctionCall(msg)
331344

332345

333-
def validate_expanding_func(name, args, kwargs):
346+
def validate_expanding_func(name, args, kwargs) -> None:
334347
numpy_args = ("axis", "dtype", "out")
335348
msg = (
336349
f"numpy operations are not valid with window objects. "
@@ -345,7 +358,7 @@ def validate_expanding_func(name, args, kwargs):
345358
raise UnsupportedFunctionCall(msg)
346359

347360

348-
def validate_groupby_func(name, args, kwargs, allowed=None):
361+
def validate_groupby_func(name, args, kwargs, allowed=None) -> None:
349362
"""
350363
'args' and 'kwargs' should be empty, except for allowed
351364
kwargs because all of
@@ -359,16 +372,15 @@ def validate_groupby_func(name, args, kwargs, allowed=None):
359372

360373
if len(args) + len(kwargs) > 0:
361374
raise UnsupportedFunctionCall(
362-
f"numpy operations are not valid with "
363-
f"groupby. Use .groupby(...).{name}() "
364-
f"instead"
375+
"numpy operations are not valid with groupby. "
376+
f"Use .groupby(...).{name}() instead"
365377
)
366378

367379

368380
RESAMPLER_NUMPY_OPS = ("min", "max", "sum", "prod", "mean", "std", "var")
369381

370382

371-
def validate_resampler_func(method, args, kwargs):
383+
def validate_resampler_func(method: str, args, kwargs) -> None:
372384
"""
373385
'args' and 'kwargs' should be empty because all of
374386
their necessary parameters are explicitly listed in
@@ -385,7 +397,7 @@ def validate_resampler_func(method, args, kwargs):
385397
raise TypeError("too many arguments passed in")
386398

387399

388-
def validate_minmax_axis(axis):
400+
def validate_minmax_axis(axis: Optional[int]) -> None:
389401
"""
390402
Ensure that the axis argument passed to min, max, argmin, or argmax is
391403
zero or None, as otherwise it will be incorrectly ignored.

0 commit comments

Comments
 (0)