Skip to content

Commit ee7c7aa

Browse files
committed
Use annotations from the standard library
1 parent 51187b3 commit ee7c7aa

File tree

8 files changed

+38
-43
lines changed

8 files changed

+38
-43
lines changed

pandas/_typing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Literal,
2323
Optional,
2424
Protocol,
25-
Type as type_t,
2625
TypeVar,
2726
Union,
2827
overload,
@@ -208,7 +207,7 @@ def __reversed__(self) -> Iterator[_T_co]: ...
208207
]
209208

210209
# dtypes
211-
NpDtype = Union[str, np.dtype, type_t[Union[str, complex, bool, object]]]
210+
NpDtype = Union[str, np.dtype, type[Union[str, complex, bool, object]]]
212211
Dtype = Union["ExtensionDtype", NpDtype]
213212
AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"]
214213
# DtypeArg specifies all allowable dtypes in a functions its dtype argument

pandas/core/dtypes/generic.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from typing import (
66
TYPE_CHECKING,
7-
Type,
87
cast,
98
)
109

@@ -59,35 +58,35 @@ def _subclasscheck(cls, inst) -> bool:
5958

6059

6160
ABCRangeIndex = cast(
62-
"Type[RangeIndex]",
61+
"type[RangeIndex]",
6362
create_pandas_abc_type("ABCRangeIndex", "_typ", ("rangeindex",)),
6463
)
6564
ABCMultiIndex = cast(
66-
"Type[MultiIndex]",
65+
"type[MultiIndex]",
6766
create_pandas_abc_type("ABCMultiIndex", "_typ", ("multiindex",)),
6867
)
6968
ABCDatetimeIndex = cast(
70-
"Type[DatetimeIndex]",
69+
"type[DatetimeIndex]",
7170
create_pandas_abc_type("ABCDatetimeIndex", "_typ", ("datetimeindex",)),
7271
)
7372
ABCTimedeltaIndex = cast(
74-
"Type[TimedeltaIndex]",
73+
"type[TimedeltaIndex]",
7574
create_pandas_abc_type("ABCTimedeltaIndex", "_typ", ("timedeltaindex",)),
7675
)
7776
ABCPeriodIndex = cast(
78-
"Type[PeriodIndex]",
77+
"type[PeriodIndex]",
7978
create_pandas_abc_type("ABCPeriodIndex", "_typ", ("periodindex",)),
8079
)
8180
ABCCategoricalIndex = cast(
82-
"Type[CategoricalIndex]",
81+
"type[CategoricalIndex]",
8382
create_pandas_abc_type("ABCCategoricalIndex", "_typ", ("categoricalindex",)),
8483
)
8584
ABCIntervalIndex = cast(
86-
"Type[IntervalIndex]",
85+
"type[IntervalIndex]",
8786
create_pandas_abc_type("ABCIntervalIndex", "_typ", ("intervalindex",)),
8887
)
8988
ABCIndex = cast(
90-
"Type[Index]",
89+
"type[Index]",
9190
create_pandas_abc_type(
9291
"ABCIndex",
9392
"_typ",
@@ -106,35 +105,35 @@ def _subclasscheck(cls, inst) -> bool:
106105

107106

108107
ABCNDFrame = cast(
109-
"Type[NDFrame]",
108+
"type[NDFrame]",
110109
create_pandas_abc_type("ABCNDFrame", "_typ", ("series", "dataframe")),
111110
)
112111
ABCSeries = cast(
113-
"Type[Series]",
112+
"type[Series]",
114113
create_pandas_abc_type("ABCSeries", "_typ", ("series",)),
115114
)
116115
ABCDataFrame = cast(
117-
"Type[DataFrame]", create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",))
116+
"type[DataFrame]", create_pandas_abc_type("ABCDataFrame", "_typ", ("dataframe",))
118117
)
119118

120119
ABCCategorical = cast(
121-
"Type[Categorical]",
120+
"type[Categorical]",
122121
create_pandas_abc_type("ABCCategorical", "_typ", ("categorical")),
123122
)
124123
ABCDatetimeArray = cast(
125-
"Type[DatetimeArray]",
124+
"type[DatetimeArray]",
126125
create_pandas_abc_type("ABCDatetimeArray", "_typ", ("datetimearray")),
127126
)
128127
ABCTimedeltaArray = cast(
129-
"Type[TimedeltaArray]",
128+
"type[TimedeltaArray]",
130129
create_pandas_abc_type("ABCTimedeltaArray", "_typ", ("timedeltaarray")),
131130
)
132131
ABCPeriodArray = cast(
133-
"Type[PeriodArray]",
132+
"type[PeriodArray]",
134133
create_pandas_abc_type("ABCPeriodArray", "_typ", ("periodarray",)),
135134
)
136135
ABCExtensionArray = cast(
137-
"Type[ExtensionArray]",
136+
"type[ExtensionArray]",
138137
create_pandas_abc_type(
139138
"ABCExtensionArray",
140139
"_typ",
@@ -143,6 +142,6 @@ def _subclasscheck(cls, inst) -> bool:
143142
),
144143
)
145144
ABCNumpyExtensionArray = cast(
146-
"Type[NumpyExtensionArray]",
145+
"type[NumpyExtensionArray]",
147146
create_pandas_abc_type("ABCNumpyExtensionArray", "_typ", ("npy_extension",)),
148147
)

pandas/io/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
TYPE_CHECKING,
3535
Any,
3636
AnyStr,
37-
DefaultDict,
3837
Generic,
3938
Literal,
4039
TypeVar,
@@ -1262,7 +1261,7 @@ def dedup_names(
12621261
['x', 'y', 'x.1', 'x.2']
12631262
"""
12641263
names = list(names) # so we can index
1265-
counts: DefaultDict[Hashable, int] = defaultdict(int)
1264+
counts: defaultdict[Hashable, int] = defaultdict(int)
12661265

12671266
for i, col in enumerate(names):
12681267
cur_count = counts[col]

pandas/io/excel/_odswriter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import (
77
TYPE_CHECKING,
88
Any,
9-
DefaultDict,
109
cast,
1110
overload,
1211
)
@@ -126,8 +125,8 @@ def _write_cells(
126125
for _ in range(startrow):
127126
wks.addElement(TableRow())
128127

129-
rows: DefaultDict = defaultdict(TableRow)
130-
col_count: DefaultDict = defaultdict(int)
128+
rows: defaultdict = defaultdict(TableRow)
129+
col_count: defaultdict = defaultdict(int)
131130

132131
for cell in sorted(cells, key=lambda cell: (cell.row, cell.col)):
133132
# only add empty cells if the row is still empty

pandas/io/formats/style_render.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import (
1111
TYPE_CHECKING,
1212
Any,
13-
DefaultDict,
1413
Optional,
1514
TypedDict,
1615
Union,
@@ -128,28 +127,28 @@ def __init__(
128127
self.hide_columns_: list = [False] * self.columns.nlevels
129128
self.hidden_rows: Sequence[int] = [] # sequence for specific hidden rows/cols
130129
self.hidden_columns: Sequence[int] = []
131-
self.ctx: DefaultDict[tuple[int, int], CSSList] = defaultdict(list)
132-
self.ctx_index: DefaultDict[tuple[int, int], CSSList] = defaultdict(list)
133-
self.ctx_columns: DefaultDict[tuple[int, int], CSSList] = defaultdict(list)
134-
self.cell_context: DefaultDict[tuple[int, int], str] = defaultdict(str)
130+
self.ctx: defaultdict[tuple[int, int], CSSList] = defaultdict(list)
131+
self.ctx_index: defaultdict[tuple[int, int], CSSList] = defaultdict(list)
132+
self.ctx_columns: defaultdict[tuple[int, int], CSSList] = defaultdict(list)
133+
self.cell_context: defaultdict[tuple[int, int], str] = defaultdict(str)
135134
self._todo: list[tuple[Callable, tuple, dict]] = []
136135
self.tooltips: Tooltips | None = None
137136
precision = (
138137
get_option("styler.format.precision") if precision is None else precision
139138
)
140-
self._display_funcs: DefaultDict[ # maps (row, col) -> format func
139+
self._display_funcs: defaultdict[ # maps (row, col) -> format func
141140
tuple[int, int], Callable[[Any], str]
142141
] = defaultdict(lambda: partial(_default_formatter, precision=precision))
143-
self._display_funcs_index: DefaultDict[ # maps (row, level) -> format func
142+
self._display_funcs_index: defaultdict[ # maps (row, level) -> format func
144143
tuple[int, int], Callable[[Any], str]
145144
] = defaultdict(lambda: partial(_default_formatter, precision=precision))
146-
self._display_funcs_index_names: DefaultDict[ # maps index level -> format func
145+
self._display_funcs_index_names: defaultdict[ # maps index level -> format func
147146
int, Callable[[Any], str]
148147
] = defaultdict(lambda: partial(_default_formatter, precision=precision))
149-
self._display_funcs_columns: DefaultDict[ # maps (level, col) -> format func
148+
self._display_funcs_columns: defaultdict[ # maps (level, col) -> format func
150149
tuple[int, int], Callable[[Any], str]
151150
] = defaultdict(lambda: partial(_default_formatter, precision=precision))
152-
self._display_funcs_column_names: DefaultDict[ # maps col level -> format func
151+
self._display_funcs_column_names: defaultdict[ # maps col level -> format func
153152
int, Callable[[Any], str]
154153
] = defaultdict(lambda: partial(_default_formatter, precision=precision))
155154

@@ -338,7 +337,7 @@ def _translate(
338337
max_cols,
339338
)
340339

341-
self.cellstyle_map_columns: DefaultDict[tuple[CSSPair, ...], list[str]] = (
340+
self.cellstyle_map_columns: defaultdict[tuple[CSSPair, ...], list[str]] = (
342341
defaultdict(list)
343342
)
344343
head = self._translate_header(sparse_cols, max_cols)
@@ -350,10 +349,10 @@ def _translate(
350349
)
351350
d.update({"index_lengths": idx_lengths})
352351

353-
self.cellstyle_map: DefaultDict[tuple[CSSPair, ...], list[str]] = defaultdict(
352+
self.cellstyle_map: defaultdict[tuple[CSSPair, ...], list[str]] = defaultdict(
354353
list
355354
)
356-
self.cellstyle_map_index: DefaultDict[tuple[CSSPair, ...], list[str]] = (
355+
self.cellstyle_map_index: defaultdict[tuple[CSSPair, ...], list[str]] = (
357356
defaultdict(list)
358357
)
359358
body: list = self._translate_body(idx_lengths, max_rows, max_cols)

pandas/io/json/_normalize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import (
1111
TYPE_CHECKING,
1212
Any,
13-
DefaultDict,
1413
overload,
1514
)
1615

@@ -539,7 +538,7 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list:
539538
records: list = []
540539
lengths = []
541540

542-
meta_vals: DefaultDict = defaultdict(list)
541+
meta_vals: defaultdict = defaultdict(list)
543542
meta_keys = [sep.join(val) for val in _meta]
544543

545544
def _recursive_extract(data, path, seen_meta, level: int = 0) -> None:

pandas/io/parsers/python_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
IO,
1212
TYPE_CHECKING,
1313
Any,
14-
DefaultDict,
1514
Literal,
1615
cast,
1716
final,
@@ -628,7 +627,7 @@ def _infer_columns(
628627
this_columns.append(c)
629628

630629
if not have_mi_columns:
631-
counts: DefaultDict = defaultdict(int)
630+
counts: defaultdict = defaultdict(int)
632631
# Ensure that regular columns are used before unnamed ones
633632
# to keep given names and mangle unnamed columns
634633
col_loop_order = [

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ select = [
259259
# flake8-slots
260260
"SLOT",
261261
# flake8-raise
262-
"RSE"
262+
"RSE",
263+
# pyupgrade - selected rules
264+
"UP006"
263265
]
264266

265267
ignore = [

0 commit comments

Comments
 (0)