Skip to content

Commit 88f93f9

Browse files
committed
TYP: fix a few types
1 parent 53243e8 commit 88f93f9

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

pandas/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110

111111
from pandas.core.dtypes.dtypes import SparseDtype
112112

113+
from pandas import util
113114
from pandas.tseries.api import infer_freq
114115
from pandas.tseries import offsets
115116

@@ -348,6 +349,7 @@
348349
"to_timedelta",
349350
"tseries",
350351
"unique",
352+
"util",
351353
"value_counts",
352354
"wide_to_long",
353355
]

pandas/core/frame.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,11 +1926,17 @@ def to_dict(
19261926
self,
19271927
orient: Literal["dict", "list", "series", "split", "tight", "index"] = ...,
19281928
into: type[dict] = ...,
1929+
index: bool = ...,
19291930
) -> dict:
19301931
...
19311932

19321933
@overload
1933-
def to_dict(self, orient: Literal["records"], into: type[dict] = ...) -> list[dict]:
1934+
def to_dict(
1935+
self,
1936+
orient: Literal["records"],
1937+
into: type[dict] = ...,
1938+
index: bool = ...,
1939+
) -> list[dict]:
19341940
...
19351941

19361942
@deprecate_nonkeyword_arguments(
@@ -11297,7 +11303,7 @@ def _reduce_axis1(self, name: str, func, skipna: bool) -> Series:
1129711303
def any( # type: ignore[override]
1129811304
self,
1129911305
*,
11300-
axis: Axis = 0,
11306+
axis: Axis | None = 0,
1130111307
bool_only: bool = False,
1130211308
skipna: bool = True,
1130311309
**kwargs,
@@ -11312,7 +11318,7 @@ def any( # type: ignore[override]
1131211318
@doc(make_doc("all", ndim=2))
1131311319
def all(
1131411320
self,
11315-
axis: Axis = 0,
11321+
axis: Axis | None = 0,
1131611322
bool_only: bool = False,
1131711323
skipna: bool = True,
1131811324
**kwargs,
@@ -11711,6 +11717,7 @@ def quantile(
1171111717
axis: Axis = ...,
1171211718
numeric_only: bool = ...,
1171311719
interpolation: QuantileInterpolation = ...,
11720+
method: Literal["single", "table"] = ...,
1171411721
) -> Series:
1171511722
...
1171611723

@@ -11721,6 +11728,7 @@ def quantile(
1172111728
axis: Axis = ...,
1172211729
numeric_only: bool = ...,
1172311730
interpolation: QuantileInterpolation = ...,
11731+
method: Literal["single", "table"] = ...,
1172411732
) -> Series | DataFrame:
1172511733
...
1172611734

@@ -11731,6 +11739,7 @@ def quantile(
1173111739
axis: Axis = ...,
1173211740
numeric_only: bool = ...,
1173311741
interpolation: QuantileInterpolation = ...,
11742+
method: Literal["single", "table"] = ...,
1173411743
) -> Series | DataFrame:
1173511744
...
1173611745

@@ -11830,11 +11839,10 @@ def quantile(
1183011839

1183111840
if not is_list_like(q):
1183211841
# BlockManager.quantile expects listlike, so we wrap and unwrap here
11833-
# error: List item 0 has incompatible type "Union[float, Union[Union[
11834-
# ExtensionArray, ndarray[Any, Any]], Index, Series], Sequence[float]]";
11835-
# expected "float"
11836-
res_df = self.quantile( # type: ignore[call-overload]
11837-
[q],
11842+
# error: List item 0 has incompatible type "float | ExtensionArray |
11843+
# ndarray[Any, Any] | Index | Series | Sequence[float]"; expected "float"
11844+
res_df = self.quantile(
11845+
[q], # type: ignore[list-item]
1183811846
axis=axis,
1183911847
numeric_only=numeric_only,
1184011848
interpolation=interpolation,

pandas/core/generic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11743,7 +11743,7 @@ def _logical_func(
1174311743
self,
1174411744
name: str,
1174511745
func,
11746-
axis: Axis = 0,
11746+
axis: Axis | None = 0,
1174711747
bool_only: bool_t = False,
1174811748
skipna: bool_t = True,
1174911749
**kwargs,
@@ -11756,7 +11756,10 @@ def _logical_func(
1175611756
res = self._logical_func(
1175711757
name, func, axis=0, bool_only=bool_only, skipna=skipna, **kwargs
1175811758
)
11759-
return res._logical_func(name, func, skipna=skipna, **kwargs)
11759+
# error: Item "bool" of "Series | bool" has no attribute "_logical_func"
11760+
return res._logical_func( # type: ignore[union-attr]
11761+
name, func, skipna=skipna, **kwargs
11762+
)
1176011763
elif axis is None:
1176111764
axis = 0
1176211765

pandas/io/excel/_base.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import abc
43
from collections.abc import (
54
Hashable,
65
Iterable,
@@ -549,7 +548,7 @@ def read_excel(
549548
_WorkbookT = TypeVar("_WorkbookT")
550549

551550

552-
class BaseExcelReader(Generic[_WorkbookT], metaclass=abc.ABCMeta):
551+
class BaseExcelReader(Generic[_WorkbookT]):
553552
book: _WorkbookT
554553

555554
def __init__(
@@ -589,13 +588,11 @@ def __init__(
589588
)
590589

591590
@property
592-
@abc.abstractmethod
593591
def _workbook_class(self) -> type[_WorkbookT]:
594-
pass
592+
raise NotImplementedError
595593

596-
@abc.abstractmethod
597594
def load_workbook(self, filepath_or_buffer, engine_kwargs) -> _WorkbookT:
598-
pass
595+
raise NotImplementedError
599596

600597
def close(self) -> None:
601598
if hasattr(self, "book"):
@@ -611,21 +608,17 @@ def close(self) -> None:
611608
self.handles.close()
612609

613610
@property
614-
@abc.abstractmethod
615611
def sheet_names(self) -> list[str]:
616-
pass
612+
raise NotImplementedError
617613

618-
@abc.abstractmethod
619614
def get_sheet_by_name(self, name: str):
620-
pass
615+
raise NotImplementedError
621616

622-
@abc.abstractmethod
623617
def get_sheet_by_index(self, index: int):
624-
pass
618+
raise NotImplementedError
625619

626-
@abc.abstractmethod
627620
def get_sheet_data(self, sheet, rows: int | None = None):
628-
pass
621+
raise NotImplementedError
629622

630623
def raise_if_bad_sheet_by_index(self, index: int) -> None:
631624
n_sheets = len(self.sheet_names)
@@ -940,7 +933,7 @@ def parse(
940933

941934

942935
@doc(storage_options=_shared_docs["storage_options"])
943-
class ExcelWriter(Generic[_WorkbookT], metaclass=abc.ABCMeta):
936+
class ExcelWriter(Generic[_WorkbookT]):
944937
"""
945938
Class for writing DataFrame objects into excel sheets.
946939
@@ -1178,20 +1171,19 @@ def engine(self) -> str:
11781171
return self._engine
11791172

11801173
@property
1181-
@abc.abstractmethod
11821174
def sheets(self) -> dict[str, Any]:
11831175
"""Mapping of sheet names to sheet objects."""
1176+
raise NotImplementedError
11841177

11851178
@property
1186-
@abc.abstractmethod
11871179
def book(self) -> _WorkbookT:
11881180
"""
11891181
Book instance. Class type will depend on the engine used.
11901182
11911183
This attribute can be used to access engine-specific features.
11921184
"""
1185+
raise NotImplementedError
11931186

1194-
@abc.abstractmethod
11951187
def _write_cells(
11961188
self,
11971189
cells,
@@ -1214,12 +1206,13 @@ def _write_cells(
12141206
freeze_panes: int tuple of length 2
12151207
contains the bottom-most row and right-most column to freeze
12161208
"""
1209+
raise NotImplementedError
12171210

1218-
@abc.abstractmethod
12191211
def _save(self) -> None:
12201212
"""
12211213
Save workbook to disk.
12221214
"""
1215+
raise NotImplementedError
12231216

12241217
def __init__(
12251218
self,

pandas/io/formats/excel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,7 @@ def write(
941941
if isinstance(writer, ExcelWriter):
942942
need_save = False
943943
else:
944-
# error: Cannot instantiate abstract class 'ExcelWriter' with abstract
945-
# attributes 'engine', 'save', 'supported_extensions' and 'write_cells'
946-
writer = ExcelWriter( # type: ignore[abstract]
944+
writer = ExcelWriter(
947945
writer,
948946
engine=engine,
949947
storage_options=storage_options,

0 commit comments

Comments
 (0)