Skip to content

Commit bd84be4

Browse files
authored
TYP: misc return annotations (#58468)
1 parent a1fc8e8 commit bd84be4

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

pandas/io/excel/_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class _XlsxStyler:
9393
}
9494

9595
@classmethod
96-
def convert(cls, style_dict, num_format_str=None):
96+
def convert(cls, style_dict, num_format_str=None) -> dict[str, Any]:
9797
"""
9898
converts a style_dict to an xlsxwriter format dict
9999

pandas/io/pytables.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Final,
2323
Literal,
2424
cast,
25+
overload,
2526
)
2627
import warnings
2728

@@ -593,7 +594,7 @@ def __getitem__(self, key: str):
593594
def __setitem__(self, key: str, value) -> None:
594595
self.put(key, value)
595596

596-
def __delitem__(self, key: str) -> None:
597+
def __delitem__(self, key: str) -> int | None:
597598
return self.remove(key)
598599

599600
def __getattr__(self, name: str):
@@ -1203,7 +1204,7 @@ def put(
12031204
dropna=dropna,
12041205
)
12051206

1206-
def remove(self, key: str, where=None, start=None, stop=None) -> None:
1207+
def remove(self, key: str, where=None, start=None, stop=None) -> int | None:
12071208
"""
12081209
Remove pandas object partially by specifying the where condition
12091210
@@ -1251,14 +1252,12 @@ def remove(self, key: str, where=None, start=None, stop=None) -> None:
12511252
# remove the node
12521253
if com.all_none(where, start, stop):
12531254
s.group._f_remove(recursive=True)
1255+
return None
12541256

12551257
# delete from the table
1256-
else:
1257-
if not s.is_table:
1258-
raise ValueError(
1259-
"can only remove with where on objects written as tables"
1260-
)
1261-
return s.delete(where=where, start=start, stop=stop)
1258+
if not s.is_table:
1259+
raise ValueError("can only remove with where on objects written as tables")
1260+
return s.delete(where=where, start=start, stop=stop)
12621261

12631262
def append(
12641263
self,
@@ -2895,7 +2894,7 @@ def read(
28952894
columns=None,
28962895
start: int | None = None,
28972896
stop: int | None = None,
2898-
):
2897+
) -> Series | DataFrame:
28992898
raise NotImplementedError(
29002899
"cannot read on an abstract storer: subclasses should implement"
29012900
)
@@ -2907,7 +2906,7 @@ def write(self, obj, **kwargs) -> None:
29072906

29082907
def delete(
29092908
self, where=None, start: int | None = None, stop: int | None = None
2910-
) -> None:
2909+
) -> int | None:
29112910
"""
29122911
support fully deleting the node in its entirety (only) - where
29132912
specification must be None
@@ -3601,7 +3600,7 @@ def queryables(self) -> dict[str, Any]:
36013600

36023601
return dict(d1 + d2 + d3)
36033602

3604-
def index_cols(self):
3603+
def index_cols(self) -> list[tuple[Any, Any]]:
36053604
"""return a list of my index cols"""
36063605
# Note: each `i.cname` below is assured to be a str.
36073606
return [(i.axis, i.cname) for i in self.index_axes]
@@ -3731,7 +3730,7 @@ def indexables(self):
37313730
dc = set(self.data_columns)
37323731
base_pos = len(_indexables)
37333732

3734-
def f(i, c):
3733+
def f(i, c: str) -> DataCol:
37353734
assert isinstance(c, str)
37363735
klass = DataCol
37373736
if c in dc:
@@ -3897,7 +3896,7 @@ def get_object(cls, obj, transposed: bool):
38973896
"""return the data for this obj"""
38983897
return obj
38993898

3900-
def validate_data_columns(self, data_columns, min_itemsize, non_index_axes):
3899+
def validate_data_columns(self, data_columns, min_itemsize, non_index_axes) -> list:
39013900
"""
39023901
take the input data_columns and min_itemize and create a data
39033902
columns spec
@@ -4590,7 +4589,9 @@ def write_data_chunk(
45904589
self.table.append(rows)
45914590
self.table.flush()
45924591

4593-
def delete(self, where=None, start: int | None = None, stop: int | None = None):
4592+
def delete(
4593+
self, where=None, start: int | None = None, stop: int | None = None
4594+
) -> int | None:
45944595
# delete all rows (and return the nrows)
45954596
if where is None or not len(where):
45964597
if start is None and stop is None:
@@ -4918,7 +4919,7 @@ def read(
49184919
columns=None,
49194920
start: int | None = None,
49204921
stop: int | None = None,
4921-
):
4922+
) -> DataFrame:
49224923
df = super().read(where=where, columns=columns, start=start, stop=stop)
49234924
df = df.set_index(self.levels)
49244925

@@ -5379,7 +5380,13 @@ def __init__(
53795380
if self.terms is not None:
53805381
self.condition, self.filter = self.terms.evaluate()
53815382

5382-
def generate(self, where):
5383+
@overload
5384+
def generate(self, where: dict | list | tuple | str) -> PyTablesExpr: ...
5385+
5386+
@overload
5387+
def generate(self, where: None) -> None: ...
5388+
5389+
def generate(self, where: dict | list | tuple | str | None) -> PyTablesExpr | None:
53835390
"""where can be a : dict,list,tuple,string"""
53845391
if where is None:
53855392
return None

pandas/util/_decorators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def indent(text: str | None, indents: int = 1) -> str:
505505
]
506506

507507

508-
def set_module(module):
508+
def set_module(module) -> Callable[[F], F]:
509509
"""Private decorator for overriding __module__ on a function or class.
510510
511511
Example usage::
@@ -518,7 +518,7 @@ def example():
518518
assert example.__module__ == "pandas"
519519
"""
520520

521-
def decorator(func):
521+
def decorator(func: F) -> F:
522522
if module is not None:
523523
func.__module__ = module
524524
return func

0 commit comments

Comments
 (0)