Skip to content

Commit 8bb28f1

Browse files
committed
add some -> to pandas core
1 parent 27135a5 commit 8bb28f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+435
-413
lines changed

pandas/_config/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ def __init__(self, *args) -> None:
435435

436436
self.ops = list(zip(args[::2], args[1::2]))
437437

438-
def __enter__(self):
438+
def __enter__(self) -> None:
439439
self.undo = [(pat, _get_option(pat, silent=True)) for pat, val in self.ops]
440440

441441
for pat, val in self.ops:
442442
_set_option(pat, val, silent=True)
443443

444-
def __exit__(self, *args):
444+
def __exit__(self, *args) -> None:
445445
if self.undo:
446446
for pat, val in self.undo:
447447
_set_option(pat, val, silent=True)

pandas/_testing/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@
238238
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)
239239

240240

241-
def set_testing_mode():
241+
def set_testing_mode() -> None:
242242
# set the testing mode filters
243243
testing_mode = os.environ.get("PANDAS_TESTING_MODE", "None")
244244
if "deprecate" in testing_mode:
245245
for category in _testing_mode_warnings:
246246
warnings.simplefilter("always", category)
247247

248248

249-
def reset_testing_mode():
249+
def reset_testing_mode() -> None:
250250
# reset the testing mode filters
251251
testing_mode = os.environ.get("PANDAS_TESTING_MODE", "None")
252252
if "deprecate" in testing_mode:
@@ -257,7 +257,7 @@ def reset_testing_mode():
257257
set_testing_mode()
258258

259259

260-
def reset_display_options():
260+
def reset_display_options() -> None:
261261
"""
262262
Reset the display options for printing and representing objects.
263263
"""

pandas/_testing/_io.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def round_trip_localpath(writer, reader, path: str | None = None):
368368
return obj
369369

370370

371-
def write_to_compressed(compression, path, data, dest="test"):
371+
def write_to_compressed(compression, path, data, dest="test") -> None:
372372
"""
373373
Write data to a compressed file.
374374
@@ -424,7 +424,7 @@ def write_to_compressed(compression, path, data, dest="test"):
424424
# Plotting
425425

426426

427-
def close(fignum=None):
427+
def close(fignum=None) -> None:
428428
from matplotlib.pyplot import (
429429
close as _close,
430430
get_fignums,

pandas/_testing/asserters.py

+29-21
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def assert_almost_equal(
6868
rtol: float = 1.0e-5,
6969
atol: float = 1.0e-8,
7070
**kwargs,
71-
):
71+
) -> None:
7272
"""
7373
Check that the left and right objects are approximately equal.
7474
@@ -211,7 +211,7 @@ def _get_tol_from_less_precise(check_less_precise: bool | int) -> float:
211211
return 0.5 * 10**-check_less_precise
212212

213213

214-
def _check_isinstance(left, right, cls):
214+
def _check_isinstance(left, right, cls) -> None:
215215
"""
216216
Helper method for our assert_* methods that ensures that
217217
the two objects being compared have the right type before
@@ -239,7 +239,7 @@ def _check_isinstance(left, right, cls):
239239
)
240240

241241

242-
def assert_dict_equal(left, right, compare_keys: bool = True):
242+
def assert_dict_equal(left, right, compare_keys: bool = True) -> None:
243243

244244
_check_isinstance(left, right, dict)
245245
_testing.assert_dict_equal(left, right, compare_keys=compare_keys)
@@ -497,7 +497,7 @@ def assert_attr_equal(attr: str, left, right, obj: str = "Attributes"):
497497
raise_assert_detail(obj, msg, left_attr, right_attr)
498498

499499

500-
def assert_is_valid_plot_return_object(objs):
500+
def assert_is_valid_plot_return_object(objs) -> None:
501501
import matplotlib.pyplot as plt
502502

503503
if isinstance(objs, (Series, np.ndarray)):
@@ -516,7 +516,7 @@ def assert_is_valid_plot_return_object(objs):
516516
assert isinstance(objs, (plt.Artist, tuple, dict)), msg
517517

518518

519-
def assert_is_sorted(seq):
519+
def assert_is_sorted(seq) -> None:
520520
"""Assert that the sequence is sorted."""
521521
if isinstance(seq, (Index, Series)):
522522
seq = seq.values
@@ -526,7 +526,7 @@ def assert_is_sorted(seq):
526526

527527
def assert_categorical_equal(
528528
left, right, check_dtype=True, check_category_order=True, obj="Categorical"
529-
):
529+
) -> None:
530530
"""
531531
Test that Categoricals are equivalent.
532532
@@ -581,7 +581,9 @@ def assert_categorical_equal(
581581
assert_attr_equal("ordered", left, right, obj=obj)
582582

583583

584-
def assert_interval_array_equal(left, right, exact="equiv", obj="IntervalArray"):
584+
def assert_interval_array_equal(
585+
left, right, exact="equiv", obj="IntervalArray"
586+
) -> None:
585587
"""
586588
Test that two IntervalArrays are equivalent.
587589
@@ -610,14 +612,16 @@ def assert_interval_array_equal(left, right, exact="equiv", obj="IntervalArray")
610612
assert_attr_equal("inclusive", left, right, obj=obj)
611613

612614

613-
def assert_period_array_equal(left, right, obj="PeriodArray"):
615+
def assert_period_array_equal(left, right, obj="PeriodArray") -> None:
614616
_check_isinstance(left, right, PeriodArray)
615617

616618
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
617619
assert_attr_equal("freq", left, right, obj=obj)
618620

619621

620-
def assert_datetime_array_equal(left, right, obj="DatetimeArray", check_freq=True):
622+
def assert_datetime_array_equal(
623+
left, right, obj="DatetimeArray", check_freq=True
624+
) -> None:
621625
__tracebackhide__ = True
622626
_check_isinstance(left, right, DatetimeArray)
623627

@@ -627,15 +631,19 @@ def assert_datetime_array_equal(left, right, obj="DatetimeArray", check_freq=Tru
627631
assert_attr_equal("tz", left, right, obj=obj)
628632

629633

630-
def assert_timedelta_array_equal(left, right, obj="TimedeltaArray", check_freq=True):
634+
def assert_timedelta_array_equal(
635+
left, right, obj="TimedeltaArray", check_freq=True
636+
) -> None:
631637
__tracebackhide__ = True
632638
_check_isinstance(left, right, TimedeltaArray)
633639
assert_numpy_array_equal(left._data, right._data, obj=f"{obj}._data")
634640
if check_freq:
635641
assert_attr_equal("freq", left, right, obj=obj)
636642

637643

638-
def raise_assert_detail(obj, message, left, right, diff=None, index_values=None):
644+
def raise_assert_detail(
645+
obj, message, left, right, diff=None, index_values=None
646+
) -> None:
639647
__tracebackhide__ = True
640648

641649
msg = f"""{obj} are different
@@ -725,7 +733,7 @@ def _get_base(obj):
725733
if left_base is right_base:
726734
raise AssertionError(f"{repr(left_base)} is {repr(right_base)}")
727735

728-
def _raise(left, right, err_msg):
736+
def _raise(left, right, err_msg) -> None:
729737
if err_msg is None:
730738
if left.shape != right.shape:
731739
raise_assert_detail(
@@ -762,7 +770,7 @@ def assert_extension_array_equal(
762770
check_exact=False,
763771
rtol: float = 1.0e-5,
764772
atol: float = 1.0e-8,
765-
):
773+
) -> None:
766774
"""
767775
Check that left and right ExtensionArrays are equal.
768776
@@ -878,7 +886,7 @@ def assert_series_equal(
878886
*,
879887
check_index=True,
880888
check_like=False,
881-
):
889+
) -> None:
882890
"""
883891
Check that left and right Series are equal.
884892
@@ -1145,7 +1153,7 @@ def assert_frame_equal(
11451153
rtol=1.0e-5,
11461154
atol=1.0e-8,
11471155
obj="DataFrame",
1148-
):
1156+
) -> None:
11491157
"""
11501158
Check that left and right DataFrame are equal.
11511159
@@ -1352,7 +1360,7 @@ def assert_frame_equal(
13521360
)
13531361

13541362

1355-
def assert_equal(left, right, **kwargs):
1363+
def assert_equal(left, right, **kwargs) -> None:
13561364
"""
13571365
Wrapper for tm.assert_*_equal to dispatch to the appropriate test function.
13581366
@@ -1393,7 +1401,7 @@ def assert_equal(left, right, **kwargs):
13931401
assert_almost_equal(left, right)
13941402

13951403

1396-
def assert_sp_array_equal(left, right):
1404+
def assert_sp_array_equal(left, right) -> None:
13971405
"""
13981406
Check that the left and right SparseArray are equal.
13991407
@@ -1426,12 +1434,12 @@ def assert_sp_array_equal(left, right):
14261434
assert_numpy_array_equal(left.to_dense(), right.to_dense())
14271435

14281436

1429-
def assert_contains_all(iterable, dic):
1437+
def assert_contains_all(iterable, dic) -> None:
14301438
for k in iterable:
14311439
assert k in dic, f"Did not contain item: {repr(k)}"
14321440

14331441

1434-
def assert_copy(iter1, iter2, **eql_kwargs):
1442+
def assert_copy(iter1, iter2, **eql_kwargs) -> None:
14351443
"""
14361444
iter1, iter2: iterables that produce elements
14371445
comparable with assert_almost_equal
@@ -1463,7 +1471,7 @@ def is_extension_array_dtype_and_needs_i8_conversion(left_dtype, right_dtype) ->
14631471
return is_extension_array_dtype(left_dtype) and needs_i8_conversion(right_dtype)
14641472

14651473

1466-
def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice):
1474+
def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice) -> None:
14671475
"""
14681476
Check that ser.iloc[i_slc] matches ser.loc[l_slc] and, if applicable,
14691477
ser[l_slc].
@@ -1477,7 +1485,7 @@ def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice):
14771485
assert_series_equal(ser[l_slc], expected)
14781486

14791487

1480-
def assert_metadata_equivalent(left, right):
1488+
def assert_metadata_equivalent(left, right) -> None:
14811489
"""
14821490
Check that ._metadata attributes are equivalent.
14831491
"""

pandas/_testing/contexts.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def set_timezone(tz: str):
6464
import os
6565
import time
6666

67-
def setTZ(tz):
67+
def setTZ(tz) -> None:
6868
if tz is None:
6969
try:
7070
del os.environ["TZ"]
@@ -231,11 +231,11 @@ class RNGContext:
231231
def __init__(self, seed) -> None:
232232
self.seed = seed
233233

234-
def __enter__(self):
234+
def __enter__(self) -> None:
235235

236236
self.start_state = np.random.get_state()
237237
np.random.seed(self.seed)
238238

239-
def __exit__(self, exc_type, exc_value, traceback):
239+
def __exit__(self, exc_type, exc_value, traceback) -> None:
240240

241241
np.random.set_state(self.start_state)

pandas/compat/pickle_compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
)
3131

3232

33-
def load_reduce(self):
33+
def load_reduce(self) -> None:
3434
stack = self.stack
3535
args = stack.pop()
3636
func = stack[-1]
@@ -207,7 +207,7 @@ def find_class(self, module, name):
207207
Unpickler.dispatch[pkl.REDUCE[0]] = load_reduce
208208

209209

210-
def load_newobj(self):
210+
def load_newobj(self) -> None:
211211
args = self.stack.pop()
212212
cls = self.stack[-1]
213213

@@ -231,7 +231,7 @@ def load_newobj(self):
231231
Unpickler.dispatch[pkl.NEWOBJ[0]] = load_newobj
232232

233233

234-
def load_newobj_ex(self):
234+
def load_newobj_ex(self) -> None:
235235
kwargs = self.stack.pop()
236236
args = self.stack.pop()
237237
cls = self.stack.pop()

pandas/conftest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
# pytest
9191

9292

93-
def pytest_addoption(parser):
93+
def pytest_addoption(parser) -> None:
9494
parser.addoption("--skip-slow", action="store_true", help="skip slow tests")
9595
parser.addoption("--skip-network", action="store_true", help="skip network tests")
9696
parser.addoption("--skip-db", action="store_true", help="skip db tests")
@@ -123,7 +123,7 @@ def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None:
123123
item.add_marker(pytest.mark.filterwarnings(f"ignore:{message}"))
124124

125125

126-
def pytest_collection_modifyitems(items, config):
126+
def pytest_collection_modifyitems(items, config) -> None:
127127
skip_slow = config.getoption("--skip-slow")
128128
only_slow = config.getoption("--only-slow")
129129
skip_network = config.getoption("--skip-network")
@@ -231,7 +231,7 @@ def pytest_collection_modifyitems(items, config):
231231

232232

233233
@pytest.fixture
234-
def add_doctest_imports(doctest_namespace):
234+
def add_doctest_imports(doctest_namespace) -> None:
235235
"""
236236
Make `np` and `pd` names available for doctests.
237237
"""
@@ -243,7 +243,7 @@ def add_doctest_imports(doctest_namespace):
243243
# Autouse fixtures
244244
# ----------------------------------------------------------------
245245
@pytest.fixture(autouse=True)
246-
def configure_tests():
246+
def configure_tests() -> None:
247247
"""
248248
Configure settings for all tests and test modules.
249249
"""

pandas/core/array_algos/replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def compare_or_regex_search(
6767

6868
def _check_comparison_types(
6969
result: ArrayLike | bool, a: ArrayLike, b: Scalar | Pattern
70-
):
70+
) -> None:
7171
"""
7272
Raises an error if the two arrays (a,b) cannot be compared.
7373
Otherwise, returns the comparison result as expected.

pandas/core/array_algos/take.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def _get_take_nd_function(
337337

338338
if func is None:
339339

340-
def func(arr, indexer, out, fill_value=np.nan):
340+
def func(arr, indexer, out, fill_value=np.nan) -> None:
341341
indexer = ensure_platform_int(indexer)
342342
_take_nd_object(
343343
arr, indexer, out, axis=axis, fill_value=fill_value, mask_info=mask_info
@@ -349,7 +349,7 @@ def func(arr, indexer, out, fill_value=np.nan):
349349
def _view_wrapper(f, arr_dtype=None, out_dtype=None, fill_wrap=None):
350350
def wrapper(
351351
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
352-
):
352+
) -> None:
353353
if arr_dtype is not None:
354354
arr = arr.view(arr_dtype)
355355
if out_dtype is not None:
@@ -364,7 +364,7 @@ def wrapper(
364364
def _convert_wrapper(f, conv_dtype):
365365
def wrapper(
366366
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
367-
):
367+
) -> None:
368368
if conv_dtype == object:
369369
# GH#39755 avoid casting dt64/td64 to integers
370370
arr = ensure_wrapped_if_datetimelike(arr)
@@ -506,7 +506,7 @@ def _take_nd_object(
506506
axis: int,
507507
fill_value,
508508
mask_info,
509-
):
509+
) -> None:
510510
if mask_info is not None:
511511
mask, needs_masking = mask_info
512512
else:

pandas/core/arrays/_mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def _validate_shift_value(self, fill_value):
259259
# we can remove this and use validate_fill_value directly
260260
return self._validate_scalar(fill_value)
261261

262-
def __setitem__(self, key, value):
262+
def __setitem__(self, key, value) -> None:
263263
key = check_array_indexer(self, key)
264264
value = self._validate_setitem_value(value)
265265
self._ndarray[key] = value

0 commit comments

Comments
 (0)