Skip to content

Commit fcf868d

Browse files
CLN: add typing for dtype arg in directories core/indexes and core/strings (GH38808) (#38890)
1 parent f6aec03 commit fcf868d

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

pandas/core/indexes/category.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pandas._libs import index as libindex
99
from pandas._libs.lib import no_default
10-
from pandas._typing import ArrayLike, Label
10+
from pandas._typing import ArrayLike, Dtype, Label
1111
from pandas.util._decorators import Appender, doc
1212

1313
from pandas.core.dtypes.common import (
@@ -180,7 +180,13 @@ def _engine_type(self):
180180
# Constructors
181181

182182
def __new__(
183-
cls, data=None, categories=None, ordered=None, dtype=None, copy=False, name=None
183+
cls,
184+
data=None,
185+
categories=None,
186+
ordered=None,
187+
dtype: Optional[Dtype] = None,
188+
copy=False,
189+
name=None,
184190
):
185191

186192
name = maybe_extract_name(name, data, cls)

pandas/core/indexes/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
to_offset,
1515
)
1616
from pandas._libs.tslibs.offsets import prefix_mapping
17-
from pandas._typing import DtypeObj
17+
from pandas._typing import Dtype, DtypeObj
1818
from pandas.errors import InvalidIndexError
1919
from pandas.util._decorators import cache_readonly, doc
2020

@@ -289,7 +289,7 @@ def __new__(
289289
ambiguous="raise",
290290
dayfirst=False,
291291
yearfirst=False,
292-
dtype=None,
292+
dtype: Optional[Dtype] = None,
293293
copy=False,
294294
name=None,
295295
):

pandas/core/indexes/interval.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pandas._libs import lib
1212
from pandas._libs.interval import Interval, IntervalMixin, IntervalTree
1313
from pandas._libs.tslibs import BaseOffset, Timedelta, Timestamp, to_offset
14-
from pandas._typing import DtypeObj, Label
14+
from pandas._typing import Dtype, DtypeObj, Label
1515
from pandas.errors import InvalidIndexError
1616
from pandas.util._decorators import Appender, cache_readonly
1717
from pandas.util._exceptions import rewrite_exception
@@ -192,7 +192,7 @@ def __new__(
192192
cls,
193193
data,
194194
closed=None,
195-
dtype=None,
195+
dtype: Optional[Dtype] = None,
196196
copy: bool = False,
197197
name=None,
198198
verify_integrity: bool = True,
@@ -249,7 +249,12 @@ def _simple_new(cls, array: IntervalArray, name: Label = None):
249249
}
250250
)
251251
def from_breaks(
252-
cls, breaks, closed: str = "right", name=None, copy: bool = False, dtype=None
252+
cls,
253+
breaks,
254+
closed: str = "right",
255+
name=None,
256+
copy: bool = False,
257+
dtype: Optional[Dtype] = None,
253258
):
254259
with rewrite_exception("IntervalArray", cls.__name__):
255260
array = IntervalArray.from_breaks(
@@ -281,7 +286,7 @@ def from_arrays(
281286
closed: str = "right",
282287
name=None,
283288
copy: bool = False,
284-
dtype=None,
289+
dtype: Optional[Dtype] = None,
285290
):
286291
with rewrite_exception("IntervalArray", cls.__name__):
287292
array = IntervalArray.from_arrays(
@@ -307,7 +312,12 @@ def from_arrays(
307312
}
308313
)
309314
def from_tuples(
310-
cls, data, closed: str = "right", name=None, copy: bool = False, dtype=None
315+
cls,
316+
data,
317+
closed: str = "right",
318+
name=None,
319+
copy: bool = False,
320+
dtype: Optional[Dtype] = None,
311321
):
312322
with rewrite_exception("IntervalArray", cls.__name__):
313323
arr = IntervalArray.from_tuples(data, closed=closed, copy=copy, dtype=dtype)

pandas/core/indexes/numeric.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Optional
22
import warnings
33

44
import numpy as np
@@ -45,7 +45,7 @@ class NumericIndex(Index):
4545
_is_numeric_dtype = True
4646
_can_hold_strings = False
4747

48-
def __new__(cls, data=None, dtype=None, copy=False, name=None):
48+
def __new__(cls, data=None, dtype: Optional[Dtype] = None, copy=False, name=None):
4949
name = maybe_extract_name(name, data, cls)
5050

5151
subarr = cls._ensure_array(data, dtype, copy)

pandas/core/indexes/period.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from datetime import datetime, timedelta
2-
from typing import Any
2+
from typing import Any, Optional
33
import warnings
44

55
import numpy as np
66

77
from pandas._libs import index as libindex, lib
88
from pandas._libs.tslibs import BaseOffset, Period, Resolution, Tick
99
from pandas._libs.tslibs.parsing import DateParseError, parse_time_string
10-
from pandas._typing import DtypeObj
10+
from pandas._typing import Dtype, DtypeObj
1111
from pandas.errors import InvalidIndexError
1212
from pandas.util._decorators import cache_readonly, doc
1313

@@ -190,7 +190,7 @@ def __new__(
190190
data=None,
191191
ordinal=None,
192192
freq=None,
193-
dtype=None,
193+
dtype: Optional[Dtype] = None,
194194
copy=False,
195195
name=None,
196196
**fields,

pandas/core/indexes/range.py

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

99
from pandas._libs import index as libindex
1010
from pandas._libs.lib import no_default
11-
from pandas._typing import Label
11+
from pandas._typing import Dtype, Label
1212
from pandas.compat.numpy import function as nv
1313
from pandas.util._decorators import cache_readonly, doc
1414

@@ -83,7 +83,13 @@ class RangeIndex(Int64Index):
8383
# Constructors
8484

8585
def __new__(
86-
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None
86+
cls,
87+
start=None,
88+
stop=None,
89+
step=None,
90+
dtype: Optional[Dtype] = None,
91+
copy=False,
92+
name=None,
8793
):
8894

8995
cls._validate_dtype(dtype)
@@ -113,7 +119,9 @@ def __new__(
113119
return cls._simple_new(rng, name=name)
114120

115121
@classmethod
116-
def from_range(cls, data: range, name=None, dtype=None) -> "RangeIndex":
122+
def from_range(
123+
cls, data: range, name=None, dtype: Optional[Dtype] = None
124+
) -> "RangeIndex":
117125
"""
118126
Create RangeIndex from a range object.
119127
@@ -405,7 +413,7 @@ def _shallow_copy(self, values=None, name: Label = no_default):
405413
return result
406414

407415
@doc(Int64Index.copy)
408-
def copy(self, name=None, deep=False, dtype=None, names=None):
416+
def copy(self, name=None, deep=False, dtype: Optional[Dtype] = None, names=None):
409417
name = self._validate_names(name=name, names=names, deep=deep)[0]
410418
new_index = self._shallow_copy(name=name)
411419

pandas/core/strings/object_array.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
import textwrap
3-
from typing import Pattern, Set, Union, cast
3+
from typing import Optional, Pattern, Set, Union, cast
44
import unicodedata
55
import warnings
66

@@ -9,7 +9,7 @@
99
import pandas._libs.lib as lib
1010
import pandas._libs.missing as libmissing
1111
import pandas._libs.ops as libops
12-
from pandas._typing import Scalar
12+
from pandas._typing import Dtype, Scalar
1313

1414
from pandas.core.dtypes.common import is_re, is_scalar
1515
from pandas.core.dtypes.missing import isna
@@ -28,7 +28,7 @@ def __len__(self):
2828
# For typing, _str_map relies on the object being sized.
2929
raise NotImplementedError
3030

31-
def _str_map(self, f, na_value=None, dtype=None):
31+
def _str_map(self, f, na_value=None, dtype: Optional[Dtype] = None):
3232
"""
3333
Map a callable over valid element of the array.
3434

0 commit comments

Comments
 (0)