Skip to content
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
4 changes: 2 additions & 2 deletions pandas-stubs/io/excel/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def read_excel(
| Sequence[int]
| Sequence[Sequence[str] | Sequence[int]]
| dict[str, Sequence[int] | list[str]] = ...,
date_parser: Callable | None = ...,
date_format: dict[Hashable, str] | str | None = ...,
thousands: str | None = ...,
decimal: str = ...,
comment: str | None = ...,
Expand Down Expand Up @@ -101,7 +101,7 @@ def read_excel(
| Sequence[int]
| Sequence[Sequence[str] | Sequence[int]]
| dict[str, Sequence[int] | list[str]] = ...,
date_parser: Callable | None = ...,
date_format: dict[Hashable, str] | str | None = ...,
thousands: str | None = ...,
decimal: str = ...,
comment: str | None = ...,
Expand Down
19 changes: 10 additions & 9 deletions pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from collections import (
)
from collections.abc import (
Callable,
Hashable,
Mapping,
Sequence,
)
Expand Down Expand Up @@ -68,8 +69,7 @@ def read_csv(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: str | Mapping[int | str, str] | None = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: Literal[True],
Expand Down Expand Up @@ -129,8 +129,7 @@ def read_csv(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: str | Mapping[int | str, str] | None = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: bool = ...,
Expand Down Expand Up @@ -190,8 +189,7 @@ def read_csv(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: str | Mapping[int | str, str] | None = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: Literal[False] = ...,
Expand Down Expand Up @@ -251,7 +249,7 @@ def read_table(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: Literal[True],
Expand Down Expand Up @@ -310,7 +308,7 @@ def read_table(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: bool = ...,
Expand Down Expand Up @@ -369,7 +367,7 @@ def read_table(
| Mapping[str, Sequence[int | str]] = ...,
infer_datetime_format: bool = ...,
keep_date_col: bool = ...,
date_parser: Callable = ...,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
cache_dates: bool = ...,
iterator: Literal[False] = ...,
Expand Down Expand Up @@ -402,6 +400,7 @@ def read_fwf(
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
date_format: dict[Hashable, str] | str | None = ...,
iterator: Literal[True],
chunksize: int | None = ...,
**kwds: Any,
Expand All @@ -414,6 +413,7 @@ def read_fwf(
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
date_format: dict[Hashable, str] | str | None = ...,
iterator: bool = ...,
chunksize: int,
**kwds: Any,
Expand All @@ -426,6 +426,7 @@ def read_fwf(
widths: Sequence[int] | None = ...,
infer_nrows: int = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
date_format: dict[Hashable, str] | str | None = ...,
iterator: Literal[False] = ...,
chunksize: None = ...,
**kwds: Any,
Expand Down
98 changes: 98 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,101 @@ def test_read_sql_dict_str_value_dtype() -> None:
DataFrame,
)
con.close()


def test_added_date_format() -> None:
with ensure_clean() as path:
df_dates = pd.DataFrame(
data={
"col1": ["2023-03-15", "2023-04-20"],
}
)
df_dates.to_csv(path)

check(
assert_type(
pd.read_table(
path, sep=",", parse_dates=["col1"], date_format="%Y-%m-%d"
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_table(
path,
sep=",",
parse_dates=["col1"],
date_format={"col1": "%Y-%m-%d"},
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_table(
path, sep=",", parse_dates=["col1"], date_format={0: "%Y-%m-%d"}
),
pd.DataFrame,
),
pd.DataFrame,
)

check(
assert_type(
pd.read_fwf(path, date_format="%Y-%m-%d"),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_fwf(path, date_format={"col1": "%Y-%m-%d"}),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_fwf(path, date_format={0: "%Y-%m-%d"}),
pd.DataFrame,
),
pd.DataFrame,
)
with ensure_clean(".xlsx") as path:
check(
assert_type(
pd.DataFrame(
data={
"col1": ["2023-03-15", "2023-04-20"],
}
).to_excel(path),
None,
),
type(None),
)
check(
assert_type(
pd.read_excel(path, parse_dates=["col1"], date_format={0: "%Y-%m-%d"}),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_excel(
path, parse_dates=["col1"], date_format={"col1": "%Y-%m-%d"}
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.read_excel(path, parse_dates=["col1"], date_format="%Y-%m-%d"),
pd.DataFrame,
),
pd.DataFrame,
)