Skip to content
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

GH: 624 - Added dtype_backend to all read_* functions #655

Merged
merged 14 commits into from
Apr 24, 2023
2 changes: 2 additions & 0 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ from pandas._typing import (
CSVQuoting,
Dtype,
DtypeArg,
DtypeBackend,
FilePath,
FileWriteMode,
FillnaOptions,
Expand Down Expand Up @@ -373,6 +374,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
convert_string: _bool = ...,
convert_integer: _bool = ...,
convert_boolean: _bool = ...,
dtype_backend: DtypeBackend = ...,
) -> NDFrameT: ...
def fillna(
self,
Expand Down
2 changes: 2 additions & 0 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ from pandas._typing import (
CategoryDtypeArg,
ComplexDtypeArg,
CompressionOptions,
DtypeBackend,
DtypeObj,
FilePath,
FillnaOptions,
Expand Down Expand Up @@ -1133,6 +1134,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
convert_string: _bool = ...,
convert_integer: _bool = ...,
convert_boolean: _bool = ...,
dtype_backend: DtypeBackend = ...,
) -> Series[S1]: ...
@overload
def ffill(
Expand Down
6 changes: 6 additions & 0 deletions pandas-stubs/core/tools/numeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import numpy as np
import pandas as pd
from typing_extensions import TypeAlias

from pandas._libs.lib import NoDefault
from pandas._typing import (
DtypeBackend,
IgnoreRaiseCoerce,
Scalar,
npt,
Expand All @@ -20,22 +22,26 @@ def to_numeric(
arg: Scalar,
errors: Literal["raise", "coerce"] = ...,
downcast: _Downcast = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> float: ...
@overload
def to_numeric(
arg: Scalar,
errors: Literal["ignore"],
downcast: _Downcast = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> Scalar: ...
@overload
def to_numeric(
arg: list | tuple | np.ndarray,
errors: IgnoreRaiseCoerce = ...,
downcast: _Downcast = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> npt.NDArray: ...
@overload
def to_numeric(
arg: pd.Series,
errors: IgnoreRaiseCoerce = ...,
downcast: _Downcast = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> pd.Series: ...
5 changes: 5 additions & 0 deletions pandas-stubs/io/clipboards.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ from typing import (

from pandas.core.frame import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
CompressionOptions,
CSVEngine,
CSVQuoting,
DtypeArg,
DtypeBackend,
ListLikeHashable,
StorageOptions,
UsecolsArgType,
Expand All @@ -28,6 +30,7 @@ from pandas.io.parsers import TextFileReader
def read_clipboard(
sep: str | None = ...,
*,
dtype_backend: DtypeBackend | NoDefault = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
Expand Down Expand Up @@ -85,6 +88,7 @@ def read_clipboard(
def read_clipboard(
sep: str | None = ...,
*,
dtype_backend: DtypeBackend | NoDefault = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
Expand Down Expand Up @@ -142,6 +146,7 @@ def read_clipboard(
def read_clipboard(
sep: str | None = ...,
*,
dtype_backend: DtypeBackend | NoDefault = ...,
delimiter: str | None = ...,
header: int | Sequence[int] | Literal["infer"] | None = ...,
names: ListLikeHashable | None = ...,
Expand Down
4 changes: 4 additions & 0 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import pyxlsb.workbook
from typing_extensions import Self
from xlrd.book import Book

from pandas._libs.lib import NoDefault
from pandas._typing import (
Dtype,
DtypeBackend,
FilePath,
ListLikeHashable,
ReadBuffer,
Expand Down Expand Up @@ -66,6 +68,7 @@ def read_excel(
comment: str | None = ...,
skipfooter: int = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> dict[int | str, DataFrame]: ...
@overload
def read_excel(
Expand Down Expand Up @@ -104,6 +107,7 @@ def read_excel(
comment: str | None = ...,
skipfooter: int = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...

class ExcelWriter:
Expand Down
3 changes: 3 additions & 0 deletions pandas-stubs/io/feather_format.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pandas import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
DtypeBackend,
FilePath,
HashableT,
ReadBuffer,
Expand All @@ -12,4 +14,5 @@ def read_feather(
columns: list[HashableT] | None = ...,
use_threads: bool = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
3 changes: 3 additions & 0 deletions pandas-stubs/io/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ from typing import (

from pandas.core.frame import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
DtypeBackend,
FilePath,
HashableT1,
HashableT2,
Expand Down Expand Up @@ -49,4 +51,5 @@ def read_html(
keep_default_na: bool = ...,
displayed_only: bool = ...,
extract_links: Literal["header", "footer", "body", "all"] | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> list[DataFrame]: ...
6 changes: 6 additions & 0 deletions pandas-stubs/io/json/_json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ from typing import (
from pandas.core.frame import DataFrame
from pandas.core.series import Series

from pandas._libs.lib import NoDefault
from pandas._typing import (
CompressionOptions,
DtypeArg,
DtypeBackend,
FilePath,
HashableT,
JsonFrameOrient,
Expand Down Expand Up @@ -43,6 +45,7 @@ def read_json(
compression: CompressionOptions = ...,
nrows: int | None = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> JsonReader[Series]: ...
@overload
def read_json(
Expand All @@ -66,6 +69,7 @@ def read_json(
compression: CompressionOptions = ...,
nrows: int | None = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> JsonReader[DataFrame]: ...
@overload
def read_json(
Expand All @@ -89,6 +93,7 @@ def read_json(
compression: CompressionOptions = ...,
nrows: int | None = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> Series: ...
@overload
def read_json(
Expand All @@ -112,6 +117,7 @@ def read_json(
compression: CompressionOptions = ...,
nrows: int | None = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...

class JsonReader(abc.Iterator, Generic[NDFrameT]):
Expand Down
3 changes: 3 additions & 0 deletions pandas-stubs/io/orc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ from typing import Any

from pandas import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
DtypeBackend,
FilePath,
HashableT,
ReadBuffer,
Expand All @@ -11,5 +13,6 @@ from pandas._typing import (
def read_orc(
path: FilePath | ReadBuffer[bytes],
columns: list[HashableT] | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
**kwargs: Any,
) -> DataFrame: ...
8 changes: 8 additions & 0 deletions pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ from typing import (
from pandas.core.frame import DataFrame
from typing_extensions import Self

from pandas._libs.lib import NoDefault
from pandas._typing import (
CompressionOptions,
CSVEngine,
CSVQuoting,
DtypeArg,
DtypeBackend,
FilePath,
ListLikeHashable,
ReadCsvBuffer,
Expand Down Expand Up @@ -90,6 +92,7 @@ def read_csv(
memory_map: bool = ...,
float_precision: Literal["high", "legacy", "round_trip"] | None = ...,
storage_options: StorageOptions | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> TextFileReader: ...
@overload
def read_csv(
Expand Down Expand Up @@ -149,6 +152,7 @@ def read_csv(
memory_map: bool = ...,
float_precision: Literal["high", "legacy", "round_trip"] | None = ...,
storage_options: StorageOptions | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> TextFileReader: ...
@overload
def read_csv(
Expand Down Expand Up @@ -208,6 +212,7 @@ def read_csv(
memory_map: bool = ...,
float_precision: Literal["high", "legacy", "round_trip"] | None = ...,
storage_options: StorageOptions | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
@overload
def read_table(
Expand Down Expand Up @@ -393,6 +398,7 @@ def read_fwf(
colspecs: Sequence[tuple[int, int]] | Literal["infer"] | None = ...,
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
iterator: Literal[True],
chunksize: int | None = ...,
**kwds: Any,
Expand All @@ -404,6 +410,7 @@ def read_fwf(
colspecs: Sequence[tuple[int, int]] | Literal["infer"] | None = ...,
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
iterator: bool = ...,
chunksize: int,
**kwds: Any,
Expand All @@ -415,6 +422,7 @@ def read_fwf(
colspecs: Sequence[tuple[int, int]] | Literal["infer"] | None = ...,
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
iterator: Literal[False] = ...,
chunksize: None = ...,
**kwds: Any,
Expand Down
3 changes: 3 additions & 0 deletions pandas-stubs/io/spss.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pandas.core.frame import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
DtypeBackend,
FilePath,
HashableT,
)
Expand All @@ -9,4 +11,5 @@ def read_spss(
path: FilePath,
usecols: list[HashableT] | None = ...,
convert_categoricals: bool = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
4 changes: 4 additions & 0 deletions pandas-stubs/io/sql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def read_sql_table(
columns: list[str] | None = ...,
*,
chunksize: int,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> Generator[DataFrame, None, None]: ...
@overload
def read_sql_table(
Expand All @@ -51,6 +52,7 @@ def read_sql_table(
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
columns: list[str] | None = ...,
chunksize: None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
@overload
def read_sql_query(
Expand All @@ -63,6 +65,7 @@ def read_sql_query(
*,
chunksize: int,
dtype: DtypeArg | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> Generator[DataFrame, None, None]: ...
@overload
def read_sql_query(
Expand All @@ -74,6 +77,7 @@ def read_sql_query(
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
chunksize: None = ...,
dtype: DtypeArg | None = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
@overload
def read_sql(
Expand Down
3 changes: 3 additions & 0 deletions pandas-stubs/io/xml.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ from collections.abc import Sequence

from pandas.core.frame import DataFrame

from pandas._libs.lib import NoDefault
from pandas._typing import (
CompressionOptions,
ConvertersArg,
DtypeArg,
DtypeBackend,
FilePath,
ParseDatesArg,
ReadBuffer,
Expand All @@ -31,4 +33,5 @@ def read_xml(
iterparse: dict[str, list[str]] | None = ...,
compression: CompressionOptions = ...,
storage_options: StorageOptions = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> DataFrame: ...
6 changes: 6 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,3 +2597,9 @@ def test_suffix_prefix_index() -> None:
check(
assert_type(df.add_prefix("_col", axis="columns"), pd.DataFrame), pd.DataFrame
)


def test_convert_dtypes_dtype_backend() -> None:
df = pd.DataFrame({"A": [1, 2, 3, 4], "B": [3, 4, 5, 6]})
dfn = df.convert_dtypes(dtype_backend="numpy_nullable")
check(assert_type(dfn, pd.DataFrame), pd.DataFrame)
Loading