Skip to content

Commit 8da8743

Browse files
authored
ENH skip 'now' and 'today' when inferring format for array (#50039)
skip now and today when inferring format for array Co-authored-by: MarcoGorelli <>
1 parent 74f1e94 commit 8da8743

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: pandas/_libs/tslib.pyx

+5-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,11 @@ def first_non_null(values: ndarray) -> int:
431431
val = values[i]
432432
if checknull_with_nat_and_na(val):
433433
continue
434-
if isinstance(val, str) and (len(val) == 0 or val in nat_strings):
434+
if (
435+
isinstance(val, str)
436+
and
437+
(len(val) == 0 or val in ("now", "today", *nat_strings))
438+
):
435439
continue
436440
return i
437441
else:

Diff for: pandas/tests/tools/test_to_datetime.py

+2
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,8 @@ class TestGuessDatetimeFormat:
23312331
["", "2011-12-30 00:00:00.000000"],
23322332
["NaT", "2011-12-30 00:00:00.000000"],
23332333
["2011-12-30 00:00:00.000000", "random_string"],
2334+
["now", "2011-12-30 00:00:00.000000"],
2335+
["today", "2011-12-30 00:00:00.000000"],
23342336
],
23352337
)
23362338
def test_guess_datetime_format_for_array(self, test_list):

0 commit comments

Comments
 (0)