Skip to content

ENH: make guess_datetime_format public #55079

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 35 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
020103a
updating init to include guess_datetime_format func
Sep 6, 2023
aa65a91
included guess_datetime_format in api
Sep 6, 2023
b6c8eb0
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 8, 2023
a9ec6a4
updated test to include guess_datetime_format method
Sep 8, 2023
c61fff3
ran pre-commit hook
Sep 8, 2023
ed6c8bf
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 9, 2023
d8c2ea1
updated latest rst doc with enhancement note
Sep 9, 2023
1087408
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 13, 2023
6f5713e
removed enhancement update
Sep 13, 2023
51b3ef1
alphabetize other-enhancement list
Sep 13, 2023
cc204f4
added guess_datetime_format
Sep 14, 2023
85456e7
updated guess_datetime_format docstring with warning sphinx directive
Sep 14, 2023
7c1ee77
fixed spelling from pre-commit hook
Sep 14, 2023
71dea87
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 14, 2023
84d9ecf
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 16, 2023
a7f619d
update guess_datetime_format docstring examples
Sep 16, 2023
b9aa8b0
fixed trailing whitespace
Sep 16, 2023
a993189
correct sphinx directive for guess_datetime_format with trailing whit…
Sep 16, 2023
3876829
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 16, 2023
a1c56cb
updated whatsnew with corrected guess_datatime_format api method string
Sep 16, 2023
6519ccb
removed extra line
Sep 18, 2023
bc77ac7
removed comment lines in example for guess_datetime_format
Sep 18, 2023
e04af8d
removed api from method call for guess_datetime_format
Sep 18, 2023
ffa5691
pre-commit hook fix for whitespace
Sep 18, 2023
382ed88
removed other guess_datetime_format
Sep 18, 2023
e4f99da
fix extra char
Sep 19, 2023
963adc1
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Sep 19, 2023
92ea6e7
fix whitespace
Sep 19, 2023
90f912b
removed toctree api
Sep 19, 2023
f4f916e
fixed conflicts
Oct 22, 2023
3000b9e
Merge remote-tracking branch 'upstream/main' into infer-datetime-54727
Oct 22, 2023
0e03f49
fixup
MarcoGorelli Oct 26, 2023
ccfd788
Merge remote-tracking branch 'upstream/main' into pr/nnlnr/infer-date…
MarcoGorelli Oct 26, 2023
16a14c1
try fixing docstring
MarcoGorelli Oct 26, 2023
0f0f7ef
add whatsnew note
MarcoGorelli Oct 26, 2023
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
8 changes: 8 additions & 0 deletions doc/source/reference/general_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Top-level dealing with datetimelike data

Top-level dealing with Interval data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
:toctree: api/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line, but it doesn't seem to make any difference in the build so is OK imo

image


Expand All @@ -73,6 +74,13 @@ Top-level evaluation

eval

Datetime formats
~~~~~~~~~~~~~~~~
.. autosummary::
:toctree: api/

tseries.api.guess_datetime_format

Hashing
~~~~~~~
.. autosummary::
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"is_supported_unit",
"npy_unit_to_abbrev",
"get_supported_reso",
"guess_datetime_format",
]

from pandas._libs.tslibs import dtypes # pylint: disable=import-self
Expand Down Expand Up @@ -63,6 +64,7 @@
Tick,
to_offset,
)
from pandas._libs.tslibs.parsing import guess_datetime_format
from pandas._libs.tslibs.period import (
IncompatibleFrequency,
Period,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/parsing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def try_parse_dates(
parser,
) -> npt.NDArray[np.object_]: ...
def guess_datetime_format(
dt_str,
dt_str: str,
dayfirst: bool | None = ...,
) -> str | None: ...
def concat_date_cols(
Expand Down
14 changes: 12 additions & 2 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -855,14 +855,24 @@ def guess_datetime_format(dt_str: str, bint dayfirst=False) -> str | None:
Datetime string to guess the format of.
dayfirst : bool, default False
If True parses dates with the day first, eg 20/01/2005
Warning: dayfirst=True is not strict, but will prefer to parse
with day first (this is a known bug).

.. warning::
dayfirst=True is not strict, but will prefer to parse
with day first (this is a known bug).

Returns
-------
str or None : ret
datetime format string (for `strftime` or `strptime`),
or None if it can't be guessed.

Examples
--------
>>> from pandas.tseries.api import guess_datetime_format
>>> guess_datetime_format('09/13/2023')
'%m/%d/%Y'

>>> guess_datetime_format('2023|September|13')
"""
cdef:
NPY_DATETIMEUNIT out_bestunit
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_namespace():
"is_supported_unit",
"get_supported_reso",
"npy_unit_to_abbrev",
"guess_datetime_format",
]

expected = set(submodules + api)
Expand Down
4 changes: 3 additions & 1 deletion pandas/tseries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
Timeseries API
"""

from pandas._libs.tslibs.parsing import guess_datetime_format

from pandas.tseries import offsets
from pandas.tseries.frequencies import infer_freq

__all__ = ["infer_freq", "offsets"]
__all__ = ["infer_freq", "offsets", "guess_datetime_format"]