Skip to content

Commit 4b77cbe

Browse files
authored
TYP: mostly missing return annotations in IO (#44801)
1 parent 2a2fd48 commit 4b77cbe

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

pandas/io/clipboards.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
""" io on the clipboard """
2+
from __future__ import annotations
3+
24
from io import StringIO
35
import warnings
46

@@ -10,7 +12,7 @@
1012
)
1113

1214

13-
def read_clipboard(sep=r"\s+", **kwargs): # pragma: no cover
15+
def read_clipboard(sep: str = r"\s+", **kwargs): # pragma: no cover
1416
r"""
1517
Read text from clipboard and pass to read_csv.
1618
@@ -83,7 +85,9 @@ def read_clipboard(sep=r"\s+", **kwargs): # pragma: no cover
8385
return read_csv(StringIO(text), sep=sep, **kwargs)
8486

8587

86-
def to_clipboard(obj, excel=True, sep=None, **kwargs): # pragma: no cover
88+
def to_clipboard(
89+
obj, excel: bool | None = True, sep: str | None = None, **kwargs
90+
) -> None: # pragma: no cover
8791
"""
8892
Attempt to write text representation of object to the system clipboard
8993
The clipboard can be then pasted into Excel for example.

pandas/io/common.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _expand_user(filepath_or_buffer: str | BaseBufferT) -> str | BaseBufferT:
174174
return filepath_or_buffer
175175

176176

177-
def validate_header_arg(header) -> None:
177+
def validate_header_arg(header: object) -> None:
178178
if isinstance(header, bool):
179179
raise TypeError(
180180
"Passing a bool to header is invalid. Use header=None for no header or "
@@ -662,8 +662,7 @@ def get_handle(
662662
mode += "b"
663663

664664
# validate encoding and errors
665-
if isinstance(encoding, str):
666-
codecs.lookup(encoding)
665+
codecs.lookup(encoding)
667666
if isinstance(errors, str):
668667
codecs.lookup_error(errors)
669668

pandas/io/date_converters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ def generic_parser(parse_func, *cols):
103103
return results
104104

105105

106-
def _maybe_cast(arr):
106+
def _maybe_cast(arr: np.ndarray) -> np.ndarray:
107107
if not arr.dtype.type == np.object_:
108108
arr = np.array(arr, dtype=object)
109109
return arr
110110

111111

112-
def _check_columns(cols):
112+
def _check_columns(cols) -> int:
113113
if not len(cols):
114114
raise AssertionError("There must be at least 1 column")
115115

pandas/io/html.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import (
1313
Pattern,
1414
Sequence,
15+
cast,
1516
)
1617

1718
from pandas._typing import (
@@ -47,7 +48,7 @@
4748
_HAS_HTML5LIB = False
4849

4950

50-
def _importers():
51+
def _importers() -> None:
5152
# import things we need
5253
# but make this done on a first use basis
5354

@@ -93,7 +94,7 @@ def _remove_whitespace(s: str, regex: Pattern = _RE_WHITESPACE) -> str:
9394
return regex.sub(" ", s.strip())
9495

9596

96-
def _get_skiprows(skiprows: int | Sequence[int] | slice | None):
97+
def _get_skiprows(skiprows: int | Sequence[int] | slice | None) -> int | Sequence[int]:
9798
"""
9899
Get an iterator given an integer, slice or container.
99100
@@ -116,7 +117,7 @@ def _get_skiprows(skiprows: int | Sequence[int] | slice | None):
116117
start, step = skiprows.start or 0, skiprows.step or 1
117118
return list(range(start, skiprows.stop, step))
118119
elif isinstance(skiprows, numbers.Integral) or is_list_like(skiprows):
119-
return skiprows
120+
return cast("int | Sequence[int]", skiprows)
120121
elif skiprows is None:
121122
return 0
122123
raise TypeError(f"{type(skiprows).__name__} is not a valid type for skipping rows")

pandas/io/parquet.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _get_path_or_handle(
109109

110110
class BaseImpl:
111111
@staticmethod
112-
def validate_dataframe(df: DataFrame):
112+
def validate_dataframe(df: DataFrame) -> None:
113113

114114
if not isinstance(df, DataFrame):
115115
raise ValueError("to_parquet only supports IO with DataFrames")
@@ -139,7 +139,7 @@ def validate_dataframe(df: DataFrame):
139139
def write(self, df: DataFrame, path, compression, **kwargs):
140140
raise AbstractMethodError(self)
141141

142-
def read(self, path, columns=None, **kwargs):
142+
def read(self, path, columns=None, **kwargs) -> DataFrame:
143143
raise AbstractMethodError(self)
144144

145145

@@ -164,7 +164,7 @@ def write(
164164
storage_options: StorageOptions = None,
165165
partition_cols: list[str] | None = None,
166166
**kwargs,
167-
):
167+
) -> None:
168168
self.validate_dataframe(df)
169169

170170
from_pandas_kwargs: dict[str, Any] = {"schema": kwargs.pop("schema", None)}
@@ -206,7 +206,7 @@ def read(
206206
use_nullable_dtypes=False,
207207
storage_options: StorageOptions = None,
208208
**kwargs,
209-
):
209+
) -> DataFrame:
210210
kwargs["use_pandas_metadata"] = True
211211

212212
to_pandas_kwargs = {}
@@ -266,7 +266,7 @@ def write(
266266
partition_cols=None,
267267
storage_options: StorageOptions = None,
268268
**kwargs,
269-
):
269+
) -> None:
270270
self.validate_dataframe(df)
271271
# thriftpy/protocol/compact.py:339:
272272
# DeprecationWarning: tostring() is deprecated.
@@ -309,7 +309,7 @@ def write(
309309

310310
def read(
311311
self, path, columns=None, storage_options: StorageOptions = None, **kwargs
312-
):
312+
) -> DataFrame:
313313
parquet_kwargs: dict[str, Any] = {}
314314
use_nullable_dtypes = kwargs.pop("use_nullable_dtypes", False)
315315
if Version(self.api.__version__) >= Version("0.7.1"):
@@ -442,7 +442,7 @@ def read_parquet(
442442
storage_options: StorageOptions = None,
443443
use_nullable_dtypes: bool = False,
444444
**kwargs,
445-
):
445+
) -> DataFrame:
446446
"""
447447
Load a parquet object from the file path, returning a DataFrame.
448448

pandas/io/pickle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def to_pickle(
3030
compression: CompressionOptions = "infer",
3131
protocol: int = pickle.HIGHEST_PROTOCOL,
3232
storage_options: StorageOptions = None,
33-
):
33+
) -> None:
3434
"""
3535
Pickle (serialize) object to file.
3636

0 commit comments

Comments
 (0)