Skip to content
Open
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: 2 additions & 0 deletions pandas-stubs/_libs/tslibs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __all__ = [
"Tick",
"Timedelta",
"Timestamp",
"guess_datetime_format",
"iNaT",
"nat_strings",
]
Expand All @@ -24,6 +25,7 @@ from pandas._libs.tslibs.offsets import (
BaseOffset,
Tick,
)
from pandas._libs.tslibs.parsing import guess_datetime_format as guess_datetime_format
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._libs.tslibs.timestamps import Timestamp
2 changes: 2 additions & 0 deletions pandas-stubs/_libs/tslibs/parsing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ from typing import Any

class DateParseError(ValueError):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...

def guess_datetime_format(dt_str: str, dayfirst: bool | None = ...) -> str | None: ...
2 changes: 0 additions & 2 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,6 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
na_position: NaPosition = "last",
key: Callable[[Index], Index] | None = None,
) -> tuple[Self, np_1darray_intp]: ...
@final
def sort(self, *args: Any, **kwargs: Any) -> None: ...
def argsort(self, *args: Any, **kwargs: Any) -> np_1darray_intp: ...
def get_indexer_non_unique(
self, target: Index
Expand Down
8 changes: 4 additions & 4 deletions pandas-stubs/io/parsers/readers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def read_csv(
keep_default_na: bool = ...,
na_filter: bool = ...,
skip_blank_lines: bool = ...,
parse_dates: bool | list[int] | list[str] | None = ...,
parse_dates: bool | list[int] | list[str] | None = None,
keep_date_col: bool = False,
date_format: dict[Hashable, str] | str | None = ...,
dayfirst: bool = ...,
Expand Down Expand Up @@ -234,7 +234,7 @@ def read_table(
| Sequence[Sequence[int]]
| Mapping[str, Sequence[int | str]]
| None
) = False,
) = None,
keep_date_col: bool = False,
date_format: dict[Hashable, str] | str | None = None,
dayfirst: bool = False,
Expand Down Expand Up @@ -297,7 +297,7 @@ def read_table(
| Sequence[Sequence[int]]
| Mapping[str, Sequence[int | str]]
| None
) = False,
) = None,
keep_date_col: bool = False,
date_format: dict[Hashable, str] | str | None = None,
dayfirst: bool = False,
Expand Down Expand Up @@ -360,7 +360,7 @@ def read_table(
| Sequence[Sequence[int]]
| Mapping[str, Sequence[int | str]]
| None
) = False,
) = None,
keep_date_col: bool = False,
date_format: dict[Hashable, str] | str | None = None,
dayfirst: bool = False,
Expand Down
2 changes: 2 additions & 0 deletions pandas-stubs/tseries/api.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from pandas._libs.tslibs.parsing import guess_datetime_format as guess_datetime_format

from pandas.tseries.frequencies import infer_freq as infer_freq
3 changes: 2 additions & 1 deletion tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def _from_sequence(
def _from_sequence_of_strings(
cls,
strings: SequenceNotStr[str],
dtype: DecimalDtype | None = None,
*,
dtype: DecimalDtype,
copy: bool = False,
) -> Self:
return cls._from_sequence([decimal.Decimal(x) for x in strings], dtype, copy)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
np_1darray_td,
)

from pandas.tseries.api import guess_datetime_format
from pandas.tseries.frequencies import to_offset
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import (
Expand Down Expand Up @@ -1912,3 +1913,11 @@ def test_to_offset_timedelta() -> None:
td = dt.timedelta(hours=1)
result = to_offset(td)
assert_type(result, BaseOffset)


def test_guess_datetime_format() -> None:
"""Test that guess_datetime_format is properly exposed from pandas.tseries.api module."""
check(assert_type(guess_datetime_format("09/13/2023"), str | None), str)
check(
assert_type(guess_datetime_format("2023|September|13"), str | None), type(None)
)
Loading