Skip to content

Commit 936b95b

Browse files
TYP: annotation of __init__ return type (PEP 484) (pandas/tests) (#46278)
1 parent c4dd0bd commit 936b95b

38 files changed

+51
-51
lines changed

pandas/tests/base/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def bar(self, *args, **kwargs):
5151
pass
5252

5353
class Delegate(PandasDelegate, PandasObject):
54-
def __init__(self, obj):
54+
def __init__(self, obj) -> None:
5555
self.obj = obj
5656

5757
def test_invalid_delegation(self):

pandas/tests/dtypes/test_inference.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class MockNumpyLikeArray:
9191
a scalar (`is_scalar(np.array(1)) == False`), but it is not list-like either.
9292
"""
9393

94-
def __init__(self, values):
94+
def __init__(self, values) -> None:
9595
self._values = values
9696

9797
def __iter__(self):
@@ -323,7 +323,7 @@ def test_is_dict_like_fails(ll):
323323
@pytest.mark.parametrize("has_contains", [True, False])
324324
def test_is_dict_like_duck_type(has_keys, has_getitem, has_contains):
325325
class DictLike:
326-
def __init__(self, d):
326+
def __init__(self, d) -> None:
327327
self.d = d
328328

329329
if has_keys:
@@ -1937,7 +1937,7 @@ def test_is_scalar_number(self):
19371937
# subclasses are.
19381938

19391939
class Numeric(Number):
1940-
def __init__(self, value):
1940+
def __init__(self, value) -> None:
19411941
self.value = value
19421942

19431943
def __int__(self):

pandas/tests/extension/arrow/arrays.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def all(self, axis=0, out=None):
179179

180180

181181
class ArrowBoolArray(ArrowExtensionArray):
182-
def __init__(self, values):
182+
def __init__(self, values) -> None:
183183
if not isinstance(values, pa.ChunkedArray):
184184
raise ValueError
185185

@@ -189,7 +189,7 @@ def __init__(self, values):
189189

190190

191191
class ArrowStringArray(ArrowExtensionArray):
192-
def __init__(self, values):
192+
def __init__(self, values) -> None:
193193
if not isinstance(values, pa.ChunkedArray):
194194
raise ValueError
195195

pandas/tests/extension/arrow/test_timestamp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def construct_array_type(cls) -> type_t[ArrowTimestampUSArray]:
4040

4141

4242
class ArrowTimestampUSArray(ArrowExtensionArray):
43-
def __init__(self, values):
43+
def __init__(self, values) -> None:
4444
if not isinstance(values, pa.ChunkedArray):
4545
raise ValueError
4646

pandas/tests/extension/decimal/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DecimalDtype(ExtensionDtype):
4141
na_value = decimal.Decimal("NaN")
4242
_metadata = ("context",)
4343

44-
def __init__(self, context=None):
44+
def __init__(self, context=None) -> None:
4545
self.context = context or decimal.getcontext()
4646

4747
def __repr__(self) -> str:
@@ -66,7 +66,7 @@ def _is_numeric(self) -> bool:
6666
class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray):
6767
__array_priority__ = 1000
6868

69-
def __init__(self, values, dtype=None, copy=False, context=None):
69+
def __init__(self, values, dtype=None, copy=False, context=None) -> None:
7070
for i, val in enumerate(values):
7171
if is_float(val):
7272
if np.isnan(val):

pandas/tests/extension/json/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class JSONArray(ExtensionArray):
6767
dtype = JSONDtype()
6868
__array_priority__ = 1000
6969

70-
def __init__(self, values, dtype=None, copy=False):
70+
def __init__(self, values, dtype=None, copy=False) -> None:
7171
for val in values:
7272
if not isinstance(val, self.dtype.type):
7373
raise TypeError("All values must be of type " + str(self.dtype.type))

pandas/tests/extension/list/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ListArray(ExtensionArray):
4444
dtype = ListDtype()
4545
__array_priority__ = 1000
4646

47-
def __init__(self, values, dtype=None, copy=False):
47+
def __init__(self, values, dtype=None, copy=False) -> None:
4848
if not isinstance(values, np.ndarray):
4949
raise TypeError("Need to pass a numpy array as values")
5050
for val in values:

pandas/tests/extension/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DummyDtype(dtypes.ExtensionDtype):
1414

1515

1616
class DummyArray(ExtensionArray):
17-
def __init__(self, data):
17+
def __init__(self, data) -> None:
1818
self.data = data
1919

2020
def __array__(self, dtype):

pandas/tests/extension/test_extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class MyEA(ExtensionArray):
11-
def __init__(self, values):
11+
def __init__(self, values) -> None:
1212
self._values = values
1313

1414

pandas/tests/frame/constructors/test_from_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_from_records_bad_index_column(self):
194194

195195
def test_from_records_non_tuple(self):
196196
class Record:
197-
def __init__(self, *args):
197+
def __init__(self, *args) -> None:
198198
self.args = args
199199

200200
def __getitem__(self, i):

pandas/tests/frame/methods/test_select_dtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class DummyDtype(ExtensionDtype):
1616
type = int
1717

18-
def __init__(self, numeric):
18+
def __init__(self, numeric) -> None:
1919
self._numeric = numeric
2020

2121
@property
@@ -28,7 +28,7 @@ def _is_numeric(self):
2828

2929

3030
class DummyArray(ExtensionArray):
31-
def __init__(self, data, dtype):
31+
def __init__(self, data, dtype) -> None:
3232
self.data = data
3333
self._dtype = dtype
3434

pandas/tests/frame/methods/test_set_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def test_set_index_custom_label_type(self):
595595
# GH#24969
596596

597597
class Thing:
598-
def __init__(self, name, color):
598+
def __init__(self, name, color) -> None:
599599
self.name = name
600600
self.color = color
601601

@@ -673,7 +673,7 @@ def test_set_index_custom_label_type_raises(self):
673673

674674
# purposefully inherit from something unhashable
675675
class Thing(set):
676-
def __init__(self, name, color):
676+
def __init__(self, name, color) -> None:
677677
self.name = name
678678
self.color = color
679679

pandas/tests/frame/methods/test_to_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def test_to_records_dtype_mi(self, df, kwargs, expected):
358358
def test_to_records_dict_like(self):
359359
# see GH#18146
360360
class DictLike:
361-
def __init__(self, **kwargs):
361+
def __init__(self, **kwargs) -> None:
362362
self.d = kwargs.copy()
363363

364364
def __getitem__(self, key):

pandas/tests/frame/test_arithmetic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def switch_numexpr_min_elements(request):
4141

4242

4343
class DummyElement:
44-
def __init__(self, value, dtype):
44+
def __init__(self, value, dtype) -> None:
4545
self.value = value
4646
self.dtype = np.dtype(dtype)
4747

pandas/tests/frame/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ def test_constructor_sequence_like(self):
13631363
# collections.Sequence like
13641364

13651365
class DummyContainer(abc.Sequence):
1366-
def __init__(self, lst):
1366+
def __init__(self, lst) -> None:
13671367
self._lst = lst
13681368

13691369
def __getitem__(self, n):

pandas/tests/frame/test_stack_unstack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ def test_unstack_number_of_levels_larger_than_int32(self, monkeypatch):
18611861
# GH 26314: Change ValueError to PerformanceWarning
18621862

18631863
class MockUnstacker(reshape_lib._Unstacker):
1864-
def __init__(self, *args, **kwargs):
1864+
def __init__(self, *args, **kwargs) -> None:
18651865
# __init__ will raise the warning
18661866
super().__init__(*args, **kwargs)
18671867
raise Exception("Don't compute final result.")

pandas/tests/frame/test_subclass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CustomDataFrame(DataFrame):
4242
custom plotting functions.
4343
"""
4444

45-
def __init__(self, *args, **kw):
45+
def __init__(self, *args, **kw) -> None:
4646
super().__init__(*args, **kw)
4747

4848
@property

pandas/tests/groupby/test_counting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class RaisingObjectException(Exception):
364364
pass
365365

366366
class RaisingObject:
367-
def __init__(self, msg="I will raise inside Cython"):
367+
def __init__(self, msg="I will raise inside Cython") -> None:
368368
super().__init__()
369369
self.msg = msg
370370

pandas/tests/indexes/datetimes/test_timezones.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class FixedOffset(tzinfo):
4141
"""Fixed offset in minutes east from UTC."""
4242

43-
def __init__(self, offset, name):
43+
def __init__(self, offset, name) -> None:
4444
self.__offset = timedelta(minutes=offset)
4545
self.__name = name
4646

pandas/tests/indexes/test_index_new.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_constructor_ndarray_like(self, array):
352352
# it should be possible to convert any object that satisfies the numpy
353353
# ndarray interface directly into an Index
354354
class ArrayLike:
355-
def __init__(self, array):
355+
def __init__(self, array) -> None:
356356
self.array = array
357357

358358
def __array__(self, dtype=None) -> np.ndarray:

pandas/tests/indexing/test_iloc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ def test_iloc_getitem_float_duplicates(self):
10721072
def test_iloc_setitem_custom_object(self):
10731073
# iloc with an object
10741074
class TO:
1075-
def __init__(self, value):
1075+
def __init__(self, value) -> None:
10761076
self.value = value
10771077

10781078
def __str__(self) -> str:

pandas/tests/io/formats/test_console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MockEncoding:
1212
side effect should be an exception that will be raised.
1313
"""
1414

15-
def __init__(self, encoding):
15+
def __init__(self, encoding) -> None:
1616
super().__init__()
1717
self.val = encoding
1818

pandas/tests/io/json/test_pandas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def test_frame_nonprintable_bytes(self):
585585
# GH14256: failing column caused segfaults, if it is not the last one
586586

587587
class BinaryThing:
588-
def __init__(self, hexed):
588+
def __init__(self, hexed) -> None:
589589
self.hexed = hexed
590590
self.binary = bytes.fromhex(hexed)
591591

@@ -1817,7 +1817,7 @@ def test_to_json_multiindex_escape(self):
18171817

18181818
def test_to_json_series_of_objects(self):
18191819
class _TestObject:
1820-
def __init__(self, a, b, _c, d):
1820+
def __init__(self, a, b, _c, d) -> None:
18211821
self.a = a
18221822
self.b = b
18231823
self._c = _c

pandas/tests/io/json/test_readlines.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_chunksize_is_incremental():
281281
)
282282

283283
class MyReader:
284-
def __init__(self, contents):
284+
def __init__(self, contents) -> None:
285285
self.read_count = 0
286286
self.stringio = StringIO(contents)
287287

pandas/tests/io/json/test_ujson.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def toDict(self):
660660

661661
def test_default_handler(self):
662662
class _TestObject:
663-
def __init__(self, val):
663+
def __init__(self, val) -> None:
664664
self.val = val
665665

666666
@property
@@ -714,7 +714,7 @@ def my_obj_handler(_):
714714

715715
def test_encode_object(self):
716716
class _TestObject:
717-
def __init__(self, a, b, _c, d):
717+
def __init__(self, a, b, _c, d) -> None:
718718
self.a = a
719719
self.b = b
720720
self._c = _c

pandas/tests/io/parser/common/test_common_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_override_set_noconvert_columns():
4141
# Usecols needs to be sorted in _set_noconvert_columns based
4242
# on the test_usecols_with_parse_dates test from test_usecols.py
4343
class MyTextFileReader(TextFileReader):
44-
def __init__(self):
44+
def __init__(self) -> None:
4545
self._currow = 0
4646
self.squeeze = False
4747

pandas/tests/io/parser/test_python_parser_only.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_python_engine_file_no_next(python_parser_only):
319319
parser = python_parser_only
320320

321321
class NoNextBuffer:
322-
def __init__(self, csv_data):
322+
def __init__(self, csv_data) -> None:
323323
self.data = csv_data
324324

325325
def __iter__(self):

pandas/tests/io/parser/test_unsupported.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_python_engine(self, python_engine):
114114
def test_python_engine_file_no_iter(self, python_engine):
115115
# see gh-16530
116116
class NoNextBuffer:
117-
def __init__(self, csv_data):
117+
def __init__(self, csv_data) -> None:
118118
self.data = csv_data
119119

120120
def __next__(self):

pandas/tests/io/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class CustomFSPath:
2929
"""For testing fspath on unknown objects"""
3030

31-
def __init__(self, path):
31+
def __init__(self, path) -> None:
3232
self.path = path
3333

3434
def __fspath__(self):

pandas/tests/io/test_html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def test_parse_failure_rewinds(self):
12431243
# Issue #17975
12441244

12451245
class MockFile:
1246-
def __init__(self, data):
1246+
def __init__(self, data) -> None:
12471247
self.data = data
12481248
self.at_end = False
12491249

pandas/tests/io/test_pickle.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ def python_pickler(obj, path):
436436
pickle.dump(obj, fh, protocol=-1)
437437

438438
class MockReadResponse:
439-
def __init__(self, path):
439+
def __init__(self, path) -> None:
440440
self.file = open(path, "rb")
441441
if "gzip" in path:
442442
self.headers = {"Content-Encoding": "gzip"}
443443
else:
444-
self.headers = {"Content-Encoding": None}
444+
self.headers = {"Content-Encoding": ""}
445445

446446
def __enter__(self):
447447
return self
@@ -478,7 +478,7 @@ def test_pickle_fsspec_roundtrip():
478478

479479

480480
class MyTz(datetime.tzinfo):
481-
def __init__(self):
481+
def __init__(self) -> None:
482482
pass
483483

484484

pandas/tests/io/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ def test_con_unknown_dbapi2_class_does_not_error_without_sql_alchemy_installed(
15381538
self,
15391539
):
15401540
class MockSqliteConnection:
1541-
def __init__(self, *args, **kwargs):
1541+
def __init__(self, *args, **kwargs) -> None:
15421542
self.conn = sqlite3.Connection(*args, **kwargs)
15431543

15441544
def __getattr__(self, name):

pandas/tests/reshape/test_pivot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ def test_pivot_number_of_levels_larger_than_int32(self, monkeypatch):
19991999
# GH 20601
20002000
# GH 26314: Change ValueError to PerformanceWarning
20012001
class MockUnstacker(reshape_lib._Unstacker):
2002-
def __init__(self, *args, **kwargs):
2002+
def __init__(self, *args, **kwargs) -> None:
20032003
# __init__ will raise the warning
20042004
super().__init__(*args, **kwargs)
20052005
raise Exception("Don't compute final result.")

pandas/tests/scalar/timedelta/test_arithmetic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def test_compare_custom_object(self):
988988
"""
989989

990990
class CustomClass:
991-
def __init__(self, cmp_result=None):
991+
def __init__(self, cmp_result=None) -> None:
992992
self.cmp_result = cmp_result
993993

994994
def generic_result(self):

0 commit comments

Comments
 (0)