Skip to content

Commit 1fde6d9

Browse files
authored
REF: remove unnecessary args in libparsing (#46821)
* REF: remove unnecessary args in libparsing * mypy fixup * mypy fixup
1 parent a8968bf commit 1fde6d9

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

pandas/_libs/tslibs/parsing.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def try_parse_datetime_components(
5151
def format_is_iso(f: str) -> bool: ...
5252
def guess_datetime_format(
5353
dt_str,
54-
dayfirst: bool = ...,
55-
dt_str_parse=...,
56-
dt_str_split=...,
54+
dayfirst: bool | None = ...,
5755
) -> str | None: ...
5856
def concat_date_cols(
5957
date_cols: tuple,

pandas/_libs/tslibs/parsing.pyx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -872,12 +872,7 @@ def format_is_iso(f: str) -> bint:
872872
return False
873873

874874

875-
def guess_datetime_format(
876-
dt_str,
877-
bint dayfirst=False,
878-
dt_str_parse=du_parse,
879-
dt_str_split=_DATEUTIL_LEXER_SPLIT,
880-
):
875+
def guess_datetime_format(dt_str, bint dayfirst=False):
881876
"""
882877
Guess the datetime format of a given datetime string.
883878
@@ -889,20 +884,11 @@ def guess_datetime_format(
889884
If True parses dates with the day first, eg 20/01/2005
890885
Warning: dayfirst=True is not strict, but will prefer to parse
891886
with day first (this is a known bug).
892-
dt_str_parse : function, defaults to `dateutil.parser.parse`
893-
This function should take in a datetime string and return
894-
a `datetime.datetime` guess that the datetime string represents
895-
dt_str_split : function, defaults to `_DATEUTIL_LEXER_SPLIT` (dateutil)
896-
This function should take in a datetime string and return
897-
a list of strings, the guess of the various specific parts
898-
e.g. '2011/12/30' -> ['2011', '/', '12', '/', '30']
899887
900888
Returns
901889
-------
902890
ret : datetime format string (for `strftime` or `strptime`)
903891
"""
904-
if dt_str_parse is None or dt_str_split is None:
905-
return None
906892

907893
if not isinstance(dt_str, str):
908894
return None
@@ -934,17 +920,16 @@ def guess_datetime_format(
934920
datetime_attrs_to_format.insert(0, day_attribute_and_format)
935921

936922
try:
937-
parsed_datetime = dt_str_parse(dt_str, dayfirst=dayfirst)
923+
parsed_datetime = du_parse(dt_str, dayfirst=dayfirst)
938924
except (ValueError, OverflowError):
939925
# In case the datetime can't be parsed, its format cannot be guessed
940926
return None
941927

942928
if parsed_datetime is None:
943929
return None
944930

945-
# the default dt_str_split from dateutil will never raise here; we assume
946-
# that any user-provided function will not either.
947-
tokens = dt_str_split(dt_str)
931+
# _DATEUTIL_LEXER_SPLIT from dateutil will never raise here
932+
tokens = _DATEUTIL_LEXER_SPLIT(dt_str)
948933

949934
# Normalize offset part of tokens.
950935
# There are multiple formats for the timezone offset.

pandas/core/tools/datetimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ class FulldatetimeDict(YearMonthDayDict, total=False):
124124
# ---------------------------------------------------------------------
125125

126126

127-
def _guess_datetime_format_for_array(arr, **kwargs):
127+
def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False):
128128
# Try to guess the format based on the first non-NaN element
129129
non_nan_elements = notna(arr).nonzero()[0]
130130
if len(non_nan_elements):
131-
return guess_datetime_format(arr[non_nan_elements[0]], **kwargs)
131+
return guess_datetime_format(arr[non_nan_elements[0]], dayfirst=dayfirst)
132132

133133

134134
def should_cache(

0 commit comments

Comments
 (0)