Skip to content

Commit 2e31faa

Browse files
Fix a few tests, want to make sure it'll be approved if the tests are good before fixing everything
1 parent dbcb428 commit 2e31faa

File tree

3 files changed

+23
-39
lines changed

3 files changed

+23
-39
lines changed

pandas/core/tools/datetimes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
)
3434
from pandas._libs.tslibs.conversion import cast_from_unit_vectorized
3535
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
36-
from pandas._libs.tslibs.nattype import NaTType
3736
from pandas._libs.tslibs.parsing import (
3837
DateParseError,
3938
guess_datetime_format,
@@ -86,7 +85,7 @@
8685
Callable,
8786
Hashable,
8887
)
89-
88+
from pandas._libs.tslibs.nattype import NaTType
9089
from pandas._libs.tslibs.timedeltas import UnitChoices
9190

9291
from pandas import (
@@ -153,7 +152,7 @@ def _guess_datetime_format_for_array(
153152
[
154153
datetime.strptime(date_string, fmt)
155154
for date_string in arr
156-
if date_string and not isinstance(date_string, NaTType)
155+
if date_string and isinstance(date_string, str)
157156
]
158157
return fmt
159158
except ValueError:

pandas/tests/tools/test_to_datetime.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,7 @@ def test_datetime_invalid_index(self, values, format):
14291429
else:
14301430
warn = None
14311431

1432-
with tm.assert_produces_warning(
1433-
warn, match="Could not infer format", raise_on_extra_warnings=False
1434-
):
1435-
res = to_datetime(values, errors="coerce", format=format)
1432+
res = to_datetime(values, errors="coerce", format=format)
14361433
tm.assert_index_equal(res, DatetimeIndex([NaT] * len(values)))
14371434

14381435
msg = "|".join(
@@ -1628,13 +1625,10 @@ def test_to_datetime_malformed_raise(self):
16281625
ValueError,
16291626
match=msg,
16301627
):
1631-
with tm.assert_produces_warning(
1632-
UserWarning, match="Could not infer format"
1633-
):
1634-
to_datetime(
1635-
ts_strings,
1636-
errors="raise",
1637-
)
1628+
to_datetime(
1629+
ts_strings,
1630+
errors="raise",
1631+
)
16381632

16391633
def test_iso_8601_strings_with_same_offset(self):
16401634
# GH 17697, 11736

pandas/tests/tslibs/test_parsing.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ def test_parsers_month_freq(date_str, expected):
232232
],
233233
)
234234
def test_guess_datetime_format_with_parseable_formats(string, fmt):
235-
with tm.maybe_produces_warning(
236-
UserWarning, fmt is not None and re.search(r"%d.*%m", fmt)
237-
):
238-
result = parsing.guess_datetime_format(string)
235+
result = parsing.guess_datetime_format(string)
239236
assert result == fmt
240237

241238

@@ -292,31 +289,25 @@ def test_guess_datetime_format_wrong_type_inputs(invalid_type_dt):
292289

293290

294291
@pytest.mark.parametrize(
295-
"string,fmt,dayfirst,warning",
292+
"string,fmt,dayfirst",
296293
[
297-
("2011-1-1", "%Y-%m-%d", False, None),
298-
("2011-1-1", "%Y-%d-%m", True, None),
299-
("1/1/2011", "%m/%d/%Y", False, None),
300-
("1/1/2011", "%d/%m/%Y", True, None),
301-
("30-1-2011", "%d-%m-%Y", False, UserWarning),
302-
("30-1-2011", "%d-%m-%Y", True, None),
303-
("2011-1-1 0:0:0", "%Y-%m-%d %H:%M:%S", False, None),
304-
("2011-1-1 0:0:0", "%Y-%d-%m %H:%M:%S", True, None),
305-
("2011-1-3T00:00:0", "%Y-%m-%dT%H:%M:%S", False, None),
306-
("2011-1-3T00:00:0", "%Y-%d-%mT%H:%M:%S", True, None),
307-
("2011-1-1 00:00:00", "%Y-%m-%d %H:%M:%S", False, None),
308-
("2011-1-1 00:00:00", "%Y-%d-%m %H:%M:%S", True, None),
294+
("2011-1-1", "%Y-%m-%d", False),
295+
("2011-1-1", "%Y-%d-%m", True),
296+
("1/1/2011", "%m/%d/%Y", False),
297+
("1/1/2011", "%d/%m/%Y", True),
298+
("30-1-2011", "%d-%m-%Y", False),
299+
("30-1-2011", "%d-%m-%Y", True),
300+
("2011-1-1 0:0:0", "%Y-%m-%d %H:%M:%S", False),
301+
("2011-1-1 0:0:0", "%Y-%d-%m %H:%M:%S", True),
302+
("2011-1-3T00:00:0", "%Y-%m-%dT%H:%M:%S", False),
303+
("2011-1-3T00:00:0", "%Y-%d-%mT%H:%M:%S", True),
304+
("2011-1-1 00:00:00", "%Y-%m-%d %H:%M:%S", False),
305+
("2011-1-1 00:00:00", "%Y-%d-%m %H:%M:%S", True),
309306
],
310307
)
311-
def test_guess_datetime_format_no_padding(string, fmt, dayfirst, warning):
308+
def test_guess_datetime_format_no_padding(string, fmt, dayfirst):
312309
# see gh-11142
313-
msg = (
314-
rf"Parsing dates in {fmt} format when dayfirst=False \(the default\) "
315-
"was specified. "
316-
"Pass `dayfirst=True` or specify a format to silence this warning."
317-
)
318-
with tm.assert_produces_warning(warning, match=msg):
319-
result = parsing.guess_datetime_format(string, dayfirst=dayfirst)
310+
result = parsing.guess_datetime_format(string, dayfirst=dayfirst)
320311
assert result == fmt
321312

322313

0 commit comments

Comments
 (0)