Skip to content

Commit 9ee56ac

Browse files
committed
revert
1 parent 390969f commit 9ee56ac

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

pandas/_libs/tslib.pyx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ cpdef array_to_datetime(
531531
return values, tz_out
532532

533533
try:
534-
py_dt, swapped_day_and_month = parse_datetime_string(val,
534+
py_dt = parse_datetime_string(val,
535535
dayfirst=dayfirst,
536536
yearfirst=yearfirst)
537537
# If the dateutil parser returned tzinfo, capture it
@@ -727,7 +727,6 @@ cdef _array_to_datetime_object(
727727
# We return an object array and only attempt to parse:
728728
# 1) NaT or NaT-like values
729729
# 2) datetime strings, which we return as datetime.datetime
730-
swapped_day_and_month = False
731730
for i in range(n):
732731
val = values[i]
733732
if checknull_with_nat_and_na(val) or PyDateTime_Check(val):
@@ -738,7 +737,7 @@ cdef _array_to_datetime_object(
738737
oresult[i] = 'NaT'
739738
continue
740739
try:
741-
oresult[i], swapped_day_and_month = parse_datetime_string(val, dayfirst=dayfirst,
740+
oresult[i] = parse_datetime_string(val, dayfirst=dayfirst,
742741
yearfirst=yearfirst)
743742
pydatetime_to_dt64(oresult[i], &dts)
744743
check_dts_bounds(&dts)
@@ -753,12 +752,6 @@ cdef _array_to_datetime_object(
753752
if is_raise:
754753
raise
755754
return values, None
756-
757-
if dayfirst and not swapped_day_and_month:
758-
warnings.warn(f"Parsing '{date_string}' in MM/DD/YYYY format.")
759-
elif not dayfirst and swapped_day_and_month:
760-
warnings.warn(f"Parsing '{date_string}' in DD/MM/YYYY format.")
761-
762755
return oresult, None
763756

764757

pandas/_libs/tslibs/conversion.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ cdef _TSObject _convert_str_to_tsobject(object ts, tzinfo tz, str unit,
645645

646646
if string_to_dts_failed or do_parse_datetime_string:
647647
try:
648-
ts, swapped_day_and_month = parse_datetime_string(ts, dayfirst=dayfirst,
648+
ts = parse_datetime_string(ts, dayfirst=dayfirst,
649649
yearfirst=yearfirst)
650650
except (ValueError, OverflowError):
651651
raise ValueError("could not convert string to Timestamp")

pandas/_libs/tslibs/parsing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def parse_datetime_string(
1111
dayfirst: bool = ...,
1212
yearfirst: bool = ...,
1313
**kwargs,
14-
) -> tuple[datetime, bool]: ...
14+
) -> datetime: ...
1515
def parse_time_string(
1616
arg: str,
1717
freq: BaseOffset | str | None = ...,

pandas/_libs/tslibs/parsing.pyx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
146146
if length == 10:
147147
# parsing MM?DD?YYYY and DD?MM?YYYY dates
148148
if _is_not_delimiter(buf[2]) or _is_not_delimiter(buf[5]):
149-
return None, None, None
149+
return None, None
150150
month = _parse_2digit(buf)
151151
day = _parse_2digit(buf + 3)
152152
year = _parse_4digit(buf + 6)
@@ -157,17 +157,17 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
157157
if buf[2] == b'.' or _is_not_delimiter(buf[2]):
158158
# we cannot reliably tell whether e.g. 10.2010 is a float
159159
# or a date, thus we refuse to parse it here
160-
return None, None, None
160+
return None, None
161161
month = _parse_2digit(buf)
162162
year = _parse_4digit(buf + 3)
163163
reso = 'month'
164164
else:
165-
return None, None, None
165+
return None, None
166166

167167
if month < 0 or day < 0 or year < 1000:
168168
# some part is not an integer, so
169169
# date_string can't be converted to date, above format
170-
return None, None, None
170+
return None, None
171171

172172
swapped_day_and_month = False
173173
if 1 <= month <= MAX_DAYS_IN_MONTH and 1 <= day <= MAX_DAYS_IN_MONTH \
@@ -184,14 +184,14 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
184184
elif not dayfirst and swapped_day_and_month:
185185
warnings.warn(f"Parsing '{date_string}' in DD/MM/YYYY format.")
186186

187-
return datetime_new(year, month, day, 0, 0, 0, 0, None), reso, swapped_day_and_month
187+
return datetime_new(year, month, day, 0, 0, 0, 0, None), reso
188188

189189
if dayfirst and not swapped_day_and_month:
190190
warnings.warn(f"Parsing '{date_string}' in MM/DD/YYYY format.")
191191
elif not dayfirst and swapped_day_and_month:
192192
warnings.warn(f"Parsing '{date_string}' in DD/MM/YYYY format.")
193193

194-
return datetime(year, month, day, 0, 0, 0, 0, None), reso, swapped_day_and_month
194+
return datetime(year, month, day, 0, 0, 0, 0, None), reso
195195

196196
raise DateParseError(f"Invalid date specified ({month}/{day})")
197197

@@ -234,7 +234,7 @@ def parse_datetime_string(
234234
bint dayfirst=False,
235235
bint yearfirst=False,
236236
**kwargs,
237-
) -> tuple[datetime, bool]:
237+
) -> datetime:
238238
"""
239239
Parse datetime string, only returns datetime.
240240
Also cares special handling matching time patterns.
@@ -254,15 +254,15 @@ def parse_datetime_string(
254254
# use current datetime as default, not pass _DEFAULT_DATETIME
255255
dt = du_parse(date_string, dayfirst=dayfirst,
256256
yearfirst=yearfirst, **kwargs)
257-
return dt, False
257+
return dt
258258

259-
dt, _, swapped_day_and_month = _parse_delimited_date(date_string, dayfirst)
259+
dt, _ = _parse_delimited_date(date_string, dayfirst)
260260
if dt is not None:
261-
return dt, swapped_day_and_month
261+
return dt
262262

263263
try:
264264
dt, _ = _parse_dateabbr_string(date_string, _DEFAULT_DATETIME, freq=None)
265-
return dt, False
265+
return dt
266266
except DateParseError:
267267
raise
268268
except ValueError:
@@ -276,7 +276,7 @@ def parse_datetime_string(
276276
# TypeError: 'NoneType' object is not iterable
277277
raise ValueError('Given date string not likely a datetime.')
278278

279-
return dt, False
279+
return dt
280280

281281

282282
def parse_time_string(arg: str, freq=None, dayfirst=None, yearfirst=None):
@@ -309,10 +309,10 @@ def parse_time_string(arg: str, freq=None, dayfirst=None, yearfirst=None):
309309
if yearfirst is None:
310310
yearfirst = get_option("display.date_yearfirst")
311311

312-
res, swapped_day_and_month = parse_datetime_string_with_reso(arg, freq=freq,
312+
res = parse_datetime_string_with_reso(arg, freq=freq,
313313
dayfirst=dayfirst,
314314
yearfirst=yearfirst)
315-
return res, swapped_day_and_month
315+
return res
316316

317317

318318
cdef parse_datetime_string_with_reso(

0 commit comments

Comments
 (0)