Skip to content

TYP: misc return annotations #58468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/excel/_xlsxwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _XlsxStyler:
}

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

Expand Down
39 changes: 23 additions & 16 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Final,
Literal,
cast,
overload,
)
import warnings

Expand Down Expand Up @@ -593,7 +594,7 @@ def __getitem__(self, key: str):
def __setitem__(self, key: str, value) -> None:
self.put(key, value)

def __delitem__(self, key: str) -> None:
def __delitem__(self, key: str) -> int | None:
return self.remove(key)

def __getattr__(self, name: str):
Expand Down Expand Up @@ -1203,7 +1204,7 @@ def put(
dropna=dropna,
)

def remove(self, key: str, where=None, start=None, stop=None) -> None:
def remove(self, key: str, where=None, start=None, stop=None) -> int | None:
"""
Remove pandas object partially by specifying the where condition

Expand Down Expand Up @@ -1251,14 +1252,12 @@ def remove(self, key: str, where=None, start=None, stop=None) -> None:
# remove the node
if com.all_none(where, start, stop):
s.group._f_remove(recursive=True)
return None

# delete from the table
else:
if not s.is_table:
raise ValueError(
"can only remove with where on objects written as tables"
)
return s.delete(where=where, start=start, stop=stop)
if not s.is_table:
raise ValueError("can only remove with where on objects written as tables")
return s.delete(where=where, start=start, stop=stop)

def append(
self,
Expand Down Expand Up @@ -2895,7 +2894,7 @@ def read(
columns=None,
start: int | None = None,
stop: int | None = None,
):
) -> Series | DataFrame:
raise NotImplementedError(
"cannot read on an abstract storer: subclasses should implement"
)
Expand All @@ -2907,7 +2906,7 @@ def write(self, obj, **kwargs) -> None:

def delete(
self, where=None, start: int | None = None, stop: int | None = None
) -> None:
) -> int | None:
"""
support fully deleting the node in its entirety (only) - where
specification must be None
Expand Down Expand Up @@ -3601,7 +3600,7 @@ def queryables(self) -> dict[str, Any]:

return dict(d1 + d2 + d3)

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

def f(i, c):
def f(i, c: str) -> DataCol:
assert isinstance(c, str)
klass = DataCol
if c in dc:
Expand Down Expand Up @@ -3897,7 +3896,7 @@ def get_object(cls, obj, transposed: bool):
"""return the data for this obj"""
return obj

def validate_data_columns(self, data_columns, min_itemsize, non_index_axes):
def validate_data_columns(self, data_columns, min_itemsize, non_index_axes) -> list:
"""
take the input data_columns and min_itemize and create a data
columns spec
Expand Down Expand Up @@ -4590,7 +4589,9 @@ def write_data_chunk(
self.table.append(rows)
self.table.flush()

def delete(self, where=None, start: int | None = None, stop: int | None = None):
def delete(
self, where=None, start: int | None = None, stop: int | None = None
) -> int | None:
# delete all rows (and return the nrows)
if where is None or not len(where):
if start is None and stop is None:
Expand Down Expand Up @@ -4918,7 +4919,7 @@ def read(
columns=None,
start: int | None = None,
stop: int | None = None,
):
) -> DataFrame:
df = super().read(where=where, columns=columns, start=start, stop=stop)
df = df.set_index(self.levels)

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

def generate(self, where):
@overload
def generate(self, where: dict | list | tuple | str) -> PyTablesExpr: ...

@overload
def generate(self, where: None) -> None: ...

def generate(self, where: dict | list | tuple | str | None) -> PyTablesExpr | None:
"""where can be a : dict,list,tuple,string"""
if where is None:
return None
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def indent(text: str | None, indents: int = 1) -> str:
]


def set_module(module):
def set_module(module) -> Callable[[F], F]:
"""Private decorator for overriding __module__ on a function or class.

Example usage::
Expand All @@ -518,7 +518,7 @@ def example():
assert example.__module__ == "pandas"
"""

def decorator(func):
def decorator(func: F) -> F:
if module is not None:
func.__module__ = module
return func
Expand Down
Loading