Skip to content

Commit e9b49c6

Browse files
WIP
1 parent 5f3e80f commit e9b49c6

File tree

13 files changed

+44
-26
lines changed

13 files changed

+44
-26
lines changed

pandas/_typing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from pandas._libs import Period, Timedelta, Timestamp
3333

34-
from pandas.core.dtypes.dtypes import ExtensionDtype
34+
from pandas.core.dtypes.dtypes import DatetimeTZDtype, ExtensionDtype, IntervalDtype
3535

3636
from pandas import Interval
3737
from pandas.core.arrays.base import ExtensionArray # noqa: F401
@@ -95,7 +95,8 @@
9595

9696
# dtypes
9797
NpDtype = Union[str, np.dtype, Type[Union[str, float, int, complex, bool, object]]]
98-
Dtype = Union["ExtensionDtype", NpDtype]
98+
PandasDtype = Union[IntervalDtype, DatetimeTZDtype]
99+
Dtype = Union["ExtensionDtype", NpDtype, PandasDtype]
99100
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
100101
DtypeArg = Union[Dtype, Dict[Label, Dtype]]
101102
DtypeObj = Union[np.dtype, "ExtensionDtype"]

pandas/core/arrays/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class ExtensionArray:
189189
# ------------------------------------------------------------------------
190190

191191
@classmethod
192-
def _from_sequence(cls, scalars, *, dtype: Optional[Dtype] = None, copy=False):
192+
def _from_sequence(cls, scalars, *, dtype=None, copy=False):
193193
"""
194194
Construct a new ExtensionArray from a sequence of scalars.
195195
@@ -211,9 +211,7 @@ def _from_sequence(cls, scalars, *, dtype: Optional[Dtype] = None, copy=False):
211211
raise AbstractMethodError(cls)
212212

213213
@classmethod
214-
def _from_sequence_of_strings(
215-
cls, strings, *, dtype: Optional[Dtype] = None, copy=False
216-
):
214+
def _from_sequence_of_strings(cls, strings, *, dtype=None, copy=False):
217215
"""
218216
Construct a new ExtensionArray from a sequence of strings.
219217

pandas/core/arrays/categorical.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def __init__(
303303
values,
304304
categories=None,
305305
ordered=None,
306-
dtype: Optional[Dtype] = None,
306+
dtype: Optional["CategoricalDtype"] = None,
307307
fastpath=False,
308308
copy: bool = True,
309309
):
@@ -405,7 +405,9 @@ def _constructor(self) -> Type["Categorical"]:
405405
return Categorical
406406

407407
@classmethod
408-
def _from_sequence(cls, scalars, *, dtype: Optional[Dtype] = None, copy=False):
408+
def _from_sequence(
409+
cls, scalars, *, dtype: Optional["CategoricalDtype"] = None, copy=False
410+
):
409411
return Categorical(scalars, dtype=dtype, copy=copy)
410412

411413
def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike:
@@ -541,7 +543,11 @@ def _from_inferred_categories(
541543

542544
@classmethod
543545
def from_codes(
544-
cls, codes, categories=None, ordered=None, dtype: Optional[Dtype] = None
546+
cls,
547+
codes,
548+
categories=None,
549+
ordered=None,
550+
dtype: Optional["CategoricalDtype"] = None,
545551
):
546552
"""
547553
Make a Categorical type from codes and categories or dtype.

pandas/core/arrays/datetimes.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps):
218218
_freq = None
219219

220220
def __init__(
221-
self, values, dtype: Optional[Dtype] = DT64NS_DTYPE, freq=None, copy=False
221+
self,
222+
values,
223+
dtype: Optional[DatetimeTZDtype] = DT64NS_DTYPE,
224+
freq=None,
225+
copy=False,
222226
):
223227
if isinstance(values, (ABCSeries, ABCIndex)):
224228
values = values._values

pandas/core/arrays/interval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __new__(
170170
cls,
171171
data,
172172
closed=None,
173-
dtype: Optional[Dtype] = None,
173+
dtype: Optional[IntervalDtype] = None,
174174
copy: bool = False,
175175
verify_integrity: bool = True,
176176
):
@@ -217,7 +217,7 @@ def _simple_new(
217217
right,
218218
closed=None,
219219
copy=False,
220-
dtype: Optional[Dtype] = None,
220+
dtype: Optional[IntervalDtype] = None,
221221
verify_integrity=True,
222222
):
223223
result = IntervalMixin.__new__(cls)

pandas/core/arrays/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _from_sequence(
223223

224224
@classmethod
225225
def _from_sequence_of_strings(
226-
cls, strings, *, dtype: Optional[Dtype] = None, copy=False
226+
cls, strings, *, dtype: Optional[PeriodDtype] = None, copy=False
227227
) -> "PeriodArray":
228228
return cls._from_sequence(strings, dtype=dtype, copy=copy)
229229

pandas/core/indexes/category.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

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

1313
from pandas.core.dtypes.common import (
1414
ensure_platform_int,
1515
is_categorical_dtype,
1616
is_scalar,
1717
)
18+
from pandas.core.dtypes.dtypes import CategoricalDtype
1819
from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna, notna
1920

2021
from pandas.core import accessor
@@ -184,7 +185,7 @@ def __new__(
184185
data=None,
185186
categories=None,
186187
ordered=None,
187-
dtype: Optional[Dtype] = None,
188+
dtype: Optional["CategoricalDtype"] = None,
188189
copy=False,
189190
name=None,
190191
):

pandas/core/internals/concat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
from pandas._libs import NaT, internals as libinternals
8-
from pandas._typing import DtypeObj, Shape
8+
from pandas._typing import Dtype, DtypeObj, Shape
99
from pandas.util._decorators import cache_readonly
1010

1111
from pandas.core.dtypes.cast import maybe_promote
@@ -235,7 +235,7 @@ def is_na(self) -> bool:
235235

236236
return isna_all(values_flat)
237237

238-
def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na):
238+
def get_reindexed_values(self, empty_dtype: Dtype, upcasted_na):
239239
if upcasted_na is None:
240240
# No upcasting is necessary
241241
fill_value = self.block.fill_value

pandas/core/reshape/tile.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from pandas._libs import Timedelta, Timestamp
99
from pandas._libs.lib import infer_dtype
10-
from pandas._typing import Dtype
1110

1211
from pandas.core.dtypes.common import (
1312
DT64NS_DTYPE,
@@ -27,7 +26,14 @@
2726
from pandas.core.dtypes.generic import ABCSeries
2827
from pandas.core.dtypes.missing import isna
2928

30-
from pandas import Categorical, Index, IntervalIndex, to_datetime, to_timedelta
29+
from pandas import (
30+
Categorical,
31+
DatetimeTZDtype,
32+
Index,
33+
IntervalIndex,
34+
to_datetime,
35+
to_timedelta,
36+
)
3137
import pandas.core.algorithms as algos
3238
import pandas.core.nanops as nanops
3339

@@ -378,7 +384,7 @@ def _bins_to_cuts(
378384
labels=None,
379385
precision: int = 3,
380386
include_lowest: bool = False,
381-
dtype: Optional[Dtype] = None,
387+
dtype: Optional[DatetimeTZDtype] = None,
382388
duplicates: str = "raise",
383389
ordered: bool = True,
384390
):
@@ -543,7 +549,7 @@ def _format_labels(
543549
precision: int,
544550
right: bool = True,
545551
include_lowest: bool = False,
546-
dtype: Optional[Dtype] = None,
552+
dtype: Optional[DatetimeTZDtype] = None,
547553
):
548554
""" based on the dtype, return our labels """
549555
closed = "right" if right else "left"

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ def to_string(
13091309
header=True,
13101310
index=True,
13111311
length=False,
1312-
dtype: bool = False,
1312+
dtype: Dtype = False,
13131313
name=False,
13141314
max_rows=None,
13151315
min_rows=None,

pandas/io/formats/format.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
ColspaceArgType,
4343
ColspaceType,
4444
CompressionOptions,
45+
Dtype,
4546
FilePathOrBuffer,
4647
FloatFormatType,
4748
FormattersType,
@@ -244,7 +245,7 @@ def __init__(
244245
na_rep: str = "NaN",
245246
name: bool = False,
246247
float_format: Optional[str] = None,
247-
dtype: bool = True,
248+
dtype: Dtype = True,
248249
max_rows: Optional[int] = None,
249250
min_rows: Optional[int] = None,
250251
):

pandas/io/json/_json.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas._typing import (
1313
CompressionOptions,
1414
DtypeArg,
15+
FrameOrSeriesUnion,
1516
IndexLabel,
1617
JSONSerializable,
1718
StorageOptions,
@@ -810,7 +811,7 @@ def __init__(
810811
self.convert_dates = convert_dates
811812
self.date_unit = date_unit
812813
self.keep_default_dates = keep_default_dates
813-
self.obj = None
814+
self.obj: Optional[FrameOrSeriesUnion] = None
814815

815816
def check_keys_split(self, decoded):
816817
"""

pandas/io/sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ def _harmonize_columns(self, parse_dates=None):
11101110

11111111
def _sqlalchemy_type(self, col):
11121112

1113-
dtype = self.dtype or {}
1113+
dtype: Union[DtypeArg, Dict] = self.dtype or {}
11141114
if col.name in dtype:
11151115
return self.dtype[col.name]
11161116

@@ -1736,7 +1736,7 @@ def _create_table_setup(self):
17361736
return create_stmts
17371737

17381738
def _sql_type_name(self, col):
1739-
dtype = self.dtype or {}
1739+
dtype: Union[DtypeArg, Dict] = self.dtype or {}
17401740
if col.name in dtype:
17411741
return dtype[col.name]
17421742

0 commit comments

Comments
 (0)