Skip to content

Commit b35f16d

Browse files
author
MarcoGorelli
committed
clean up
1 parent b973b4d commit b35f16d

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

pandas/_libs/tslibs/parsing.pyx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1101,15 +1101,13 @@ cdef void _maybe_warn_about_dayfirst(format: str, bint dayfirst):
11011101
if (day_index > month_index) and dayfirst:
11021102
warnings.warn(
11031103
f"Parsing dates in {format} format when dayfirst=True was specified. "
1104-
f"Pass `dayfirst=False` or explicitly specify a format to silence "
1105-
"this warning.",
1104+
f"Pass `dayfirst=False` or specify a format to silence this warning.",
11061105
stacklevel=find_stack_level(inspect.currentframe()),
11071106
)
11081107
if (day_index < month_index) and not dayfirst:
11091108
warnings.warn(
11101109
f"Parsing dates in {format} format when dayfirst=False was specified. "
1111-
f"Pass `dayfirst=True` or explicitly specify a format to silence "
1112-
"this warning.",
1110+
f"Pass `dayfirst=True` or specify a format to silence this warning.",
11131111
stacklevel=find_stack_level(inspect.currentframe()),
11141112
)
11151113

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str
137137
return guessed_format
138138
warnings.warn(
139139
"Could not infer format - "
140-
"to ensure consistent parsing, please specify `format`.",
140+
"to ensure consistent parsing, specify a format.",
141141
stacklevel=find_stack_level(inspect.currentframe()),
142142
)
143143
return None

pandas/tests/io/parser/test_parse_dates.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ def test_parse_delimited_date_swap_with_warning(
17291729
expected = DataFrame({0: [expected]}, dtype="datetime64[ns]")
17301730
warning_msg = (
17311731
"Parsing dates in .* format when dayfirst=.* was specified. "
1732-
"Pass `dayfirst=.*` or explicitly specify a format to silence this warning."
1732+
"Pass `dayfirst=.*` or specify a format to silence this warning."
17331733
)
17341734
result = parser.read_csv_check_warnings(
17351735
UserWarning,
@@ -1927,7 +1927,7 @@ def test_dayfirst_warnings():
19271927
)
19281928
warning_msg = (
19291929
"Parsing dates in .* format when dayfirst=.* was specified. "
1930-
"Pass `dayfirst=.*` or `format='.*'` to silence this warning."
1930+
"Pass `dayfirst=.*` or specify a format to silence this warning."
19311931
)
19321932

19331933
# A. dayfirst arg correct, no warning
@@ -1988,7 +1988,7 @@ def test_dayfirst_warnings_no_leading_zero(date_string, dayfirst):
19881988
)
19891989
warning_msg = (
19901990
"Parsing dates in .* format when dayfirst=.* was specified. "
1991-
"Pass `dayfirst=.*` or explicitly specify a format to silence this warning."
1991+
"Pass `dayfirst=.*` or specify a format to silence this warning."
19921992
)
19931993
with tm.assert_produces_warning(UserWarning, match=warning_msg):
19941994
res = read_csv(

pandas/tests/tools/test_to_datetime.py

+28-26
Original file line numberDiff line numberDiff line change
@@ -1113,42 +1113,41 @@ def test_convert_object_to_datetime_with_cache(
11131113

11141114
@pytest.mark.parametrize("cache", [True, False])
11151115
@pytest.mark.parametrize(
1116-
("input", "expected"),
1116+
("input", "expected", "warning"),
11171117
(
11181118
(
11191119
Series([NaT] * 20 + [None] * 20, dtype="object"),
11201120
Series([NaT] * 40, dtype="datetime64[ns]"),
1121+
None,
11211122
),
11221123
(
11231124
Series([NaT] * 60 + [None] * 60, dtype="object"),
11241125
Series([NaT] * 120, dtype="datetime64[ns]"),
1126+
None,
11251127
),
1126-
(Series([None] * 20), Series([NaT] * 20, dtype="datetime64[ns]")),
1127-
(Series([None] * 60), Series([NaT] * 60, dtype="datetime64[ns]")),
1128-
(Series([pd.NA] * 20), Series([NaT] * 20, dtype="datetime64[ns]")),
1129-
(Series([pd.NA] * 60), Series([NaT] * 60, dtype="datetime64[ns]")),
1130-
(Series([np.NaN] * 20), Series([NaT] * 20, dtype="datetime64[ns]")),
1131-
(Series([np.NaN] * 60), Series([NaT] * 60, dtype="datetime64[ns]")),
1132-
),
1133-
)
1134-
def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected):
1135-
# GH35888
1136-
result = to_datetime(input, cache=cache)
1137-
tm.assert_series_equal(result, expected)
1138-
1139-
@pytest.mark.parametrize("cache", [True, False])
1140-
@pytest.mark.parametrize(
1141-
("input", "expected"),
1142-
(
1143-
(Series([""] * 20), Series([NaT] * 20, dtype="datetime64[ns]")),
1144-
(Series([""] * 60), Series([NaT] * 60, dtype="datetime64[ns]")),
1128+
(Series([None] * 20), Series([NaT] * 20, dtype="datetime64[ns]"), None),
1129+
(Series([None] * 60), Series([NaT] * 60, dtype="datetime64[ns]"), None),
1130+
(
1131+
Series([""] * 20),
1132+
Series([NaT] * 20, dtype="datetime64[ns]"),
1133+
UserWarning,
1134+
),
1135+
(
1136+
Series([""] * 60),
1137+
Series([NaT] * 60, dtype="datetime64[ns]"),
1138+
UserWarning,
1139+
),
1140+
(Series([pd.NA] * 20), Series([NaT] * 20, dtype="datetime64[ns]"), None),
1141+
(Series([pd.NA] * 60), Series([NaT] * 60, dtype="datetime64[ns]"), None),
1142+
(Series([np.NaN] * 20), Series([NaT] * 20, dtype="datetime64[ns]"), None),
1143+
(Series([np.NaN] * 60), Series([NaT] * 60, dtype="datetime64[ns]"), None),
11451144
),
11461145
)
1147-
def test_to_datetime_converts_null_like_to_nat_with_warning(
1148-
self, cache, input, expected
1146+
def test_to_datetime_converts_null_like_to_nat(
1147+
self, cache, input, expected, warning
11491148
):
11501149
# GH35888
1151-
with tm.assert_produces_warning(UserWarning, match="Could not infer format"):
1150+
with tm.assert_produces_warning(warning, match="Could not infer format"):
11521151
result = to_datetime(input, cache=cache)
11531152
tm.assert_series_equal(result, expected)
11541153

@@ -1897,7 +1896,7 @@ def test_to_datetime_strings(self, cache):
18971896
def test_to_datetime_strings_variation(self, cache):
18981897
array = ["2012", "20120101", "20120101 12:01:01"]
18991898
with tm.assert_produces_warning(UserWarning, match="Could not infer format"):
1900-
expected = [to_datetime(i, cache=cache) for i in array]
1899+
expected = [to_datetime(date_string, cache=cache) for date_string in array]
19011900
result = [Timestamp(date_str) for date_str in array]
19021901
tm.assert_almost_equal(result, expected)
19031902

@@ -2077,7 +2076,7 @@ def test_dayfirst_warnings_valid_input(self):
20772076
# GH 12585
20782077
warning_msg = (
20792078
"Parsing dates in .* format when dayfirst=.* was specified. "
2080-
"Pass `dayfirst=.*` or `format='.*'` to silence this warning."
2079+
"Pass `dayfirst=.*` or specify a format to silence this warning."
20812080
)
20822081

20832082
# CASE 1: valid input
@@ -2663,7 +2662,10 @@ def test_incorrect_value_exception(self):
26632662
)
26642663
def test_to_datetime_out_of_bounds_with_format_arg(self, format, warning):
26652664
# see gh-23830
2666-
msg = "Out of bounds nanosecond timestamp: 2417-10-27 00:00:00"
2665+
msg = (
2666+
"Out of bounds nanosecond timestamp: 2417-10-27 00:00:00 "
2667+
"present at position 0"
2668+
)
26672669
with pytest.raises(OutOfBoundsDatetime, match=msg):
26682670
with tm.assert_produces_warning(warning, match="Could not infer format"):
26692671
to_datetime("2417-10-27 00:00:00", format=format)

0 commit comments

Comments
 (0)