Skip to content

Commit 653ff5d

Browse files
committed
Revert "TST: insert 'match' to bare pytest raises in pandas/tests/tools/test_to_datetime.py (#37027)"
This reverts commit 05a4eef
1 parent 601eff1 commit 653ff5d

File tree

1 file changed

+28
-55
lines changed

1 file changed

+28
-55
lines changed

pandas/tests/tools/test_to_datetime.py

+28-55
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ def test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utc(self):
349349
def test_to_datetime_parse_timezone_malformed(self, offset):
350350
fmt = "%Y-%m-%d %H:%M:%S %z"
351351
date = "2010-01-01 12:00:00 " + offset
352-
353-
msg = "does not match format|unconverted data remains"
354-
with pytest.raises(ValueError, match=msg):
352+
with pytest.raises(ValueError):
355353
pd.to_datetime([date], format=fmt)
356354

357355
def test_to_datetime_parse_timezone_keeps_name(self):
@@ -786,19 +784,17 @@ def test_to_datetime_tz_psycopg2(self, cache):
786784
@pytest.mark.parametrize("cache", [True, False])
787785
def test_datetime_bool(self, cache):
788786
# GH13176
789-
msg = r"dtype bool cannot be converted to datetime64\[ns\]"
790-
with pytest.raises(TypeError, match=msg):
787+
with pytest.raises(TypeError):
791788
to_datetime(False)
792789
assert to_datetime(False, errors="coerce", cache=cache) is NaT
793790
assert to_datetime(False, errors="ignore", cache=cache) is False
794-
with pytest.raises(TypeError, match=msg):
791+
with pytest.raises(TypeError):
795792
to_datetime(True)
796793
assert to_datetime(True, errors="coerce", cache=cache) is NaT
797794
assert to_datetime(True, errors="ignore", cache=cache) is True
798-
msg = f"{type(cache)} is not convertible to datetime"
799-
with pytest.raises(TypeError, match=msg):
795+
with pytest.raises(TypeError):
800796
to_datetime([False, datetime.today()], cache=cache)
801-
with pytest.raises(TypeError, match=msg):
797+
with pytest.raises(TypeError):
802798
to_datetime(["20130101", True], cache=cache)
803799
tm.assert_index_equal(
804800
to_datetime([0, False, NaT, 0.0], errors="coerce", cache=cache),
@@ -809,10 +805,10 @@ def test_datetime_bool(self, cache):
809805

810806
def test_datetime_invalid_datatype(self):
811807
# GH13176
812-
msg = "is not convertible to datetime"
813-
with pytest.raises(TypeError, match=msg):
808+
809+
with pytest.raises(TypeError):
814810
pd.to_datetime(bool)
815-
with pytest.raises(TypeError, match=msg):
811+
with pytest.raises(TypeError):
816812
pd.to_datetime(pd.to_datetime)
817813

818814
@pytest.mark.parametrize("value", ["a", "00:01:99"])
@@ -830,12 +826,7 @@ def test_datetime_invalid_scalar(self, value, format, infer):
830826
)
831827
assert res is pd.NaT
832828

833-
msg = (
834-
"is a bad directive in format|"
835-
"second must be in 0..59: 00:01:99|"
836-
"Given date string not likely a datetime"
837-
)
838-
with pytest.raises(ValueError, match=msg):
829+
with pytest.raises(ValueError):
839830
pd.to_datetime(
840831
value, errors="raise", format=format, infer_datetime_format=infer
841832
)
@@ -856,14 +847,12 @@ def test_datetime_outofbounds_scalar(self, value, format, infer):
856847
assert res is pd.NaT
857848

858849
if format is not None:
859-
msg = "is a bad directive in format|Out of bounds nanosecond timestamp"
860-
with pytest.raises(ValueError, match=msg):
850+
with pytest.raises(ValueError):
861851
pd.to_datetime(
862852
value, errors="raise", format=format, infer_datetime_format=infer
863853
)
864854
else:
865-
msg = "Out of bounds nanosecond timestamp"
866-
with pytest.raises(OutOfBoundsDatetime, match=msg):
855+
with pytest.raises(OutOfBoundsDatetime):
867856
pd.to_datetime(
868857
value, errors="raise", format=format, infer_datetime_format=infer
869858
)
@@ -883,12 +872,7 @@ def test_datetime_invalid_index(self, values, format, infer):
883872
)
884873
tm.assert_index_equal(res, pd.DatetimeIndex([pd.NaT] * len(values)))
885874

886-
msg = (
887-
"is a bad directive in format|"
888-
"Given date string not likely a datetime|"
889-
"second must be in 0..59: 00:01:99"
890-
)
891-
with pytest.raises(ValueError, match=msg):
875+
with pytest.raises(ValueError):
892876
pd.to_datetime(
893877
values, errors="raise", format=format, infer_datetime_format=infer
894878
)
@@ -1086,8 +1070,7 @@ def test_timestamp_utc_true(self, ts, expected):
10861070
@pytest.mark.parametrize("dt_str", ["00010101", "13000101", "30000101", "99990101"])
10871071
def test_to_datetime_with_format_out_of_bounds(self, dt_str):
10881072
# GH 9107
1089-
msg = "Out of bounds nanosecond timestamp"
1090-
with pytest.raises(OutOfBoundsDatetime, match=msg):
1073+
with pytest.raises(OutOfBoundsDatetime):
10911074
pd.to_datetime(dt_str, format="%Y%m%d")
10921075

10931076
def test_to_datetime_utc(self):
@@ -1113,8 +1096,8 @@ class TestToDatetimeUnit:
11131096
def test_unit(self, cache):
11141097
# GH 11758
11151098
# test proper behavior with errors
1116-
msg = "cannot specify both format and unit"
1117-
with pytest.raises(ValueError, match=msg):
1099+
1100+
with pytest.raises(ValueError):
11181101
to_datetime([1], unit="D", format="%Y%m%d", cache=cache)
11191102

11201103
values = [11111111, 1, 1.0, iNaT, NaT, np.nan, "NaT", ""]
@@ -1140,8 +1123,7 @@ def test_unit(self, cache):
11401123
)
11411124
tm.assert_index_equal(result, expected)
11421125

1143-
msg = "cannot convert input 11111111 with the unit 'D'"
1144-
with pytest.raises(tslib.OutOfBoundsDatetime, match=msg):
1126+
with pytest.raises(tslib.OutOfBoundsDatetime):
11451127
to_datetime(values, unit="D", errors="raise", cache=cache)
11461128

11471129
values = [1420043460000, iNaT, NaT, np.nan, "NaT"]
@@ -1154,8 +1136,7 @@ def test_unit(self, cache):
11541136
expected = DatetimeIndex(["NaT", "NaT", "NaT", "NaT", "NaT"])
11551137
tm.assert_index_equal(result, expected)
11561138

1157-
msg = "cannot convert input 1420043460000 with the unit 's'"
1158-
with pytest.raises(tslib.OutOfBoundsDatetime, match=msg):
1139+
with pytest.raises(tslib.OutOfBoundsDatetime):
11591140
to_datetime(values, errors="raise", unit="s", cache=cache)
11601141

11611142
# if we have a string, then we raise a ValueError
@@ -1223,16 +1204,15 @@ def test_unit_mixed(self, cache):
12231204
result = pd.to_datetime(arr, errors="coerce", cache=cache)
12241205
tm.assert_index_equal(result, expected)
12251206

1226-
msg = "mixed datetimes and integers in passed array"
1227-
with pytest.raises(ValueError, match=msg):
1207+
with pytest.raises(ValueError):
12281208
pd.to_datetime(arr, errors="raise", cache=cache)
12291209

12301210
expected = DatetimeIndex(["NaT", "NaT", "2013-01-01"])
12311211
arr = [1.434692e18, 1.432766e18, pd.Timestamp("20130101")]
12321212
result = pd.to_datetime(arr, errors="coerce", cache=cache)
12331213
tm.assert_index_equal(result, expected)
12341214

1235-
with pytest.raises(ValueError, match=msg):
1215+
with pytest.raises(ValueError):
12361216
pd.to_datetime(arr, errors="raise", cache=cache)
12371217

12381218
@pytest.mark.parametrize("cache", [True, False])
@@ -1412,8 +1392,7 @@ def test_dataframe_dtypes(self, cache):
14121392

14131393
# float
14141394
df = DataFrame({"year": [2000, 2001], "month": [1.5, 1], "day": [1, 1]})
1415-
msg = "cannot assemble the datetimes: unconverted data remains: 1"
1416-
with pytest.raises(ValueError, match=msg):
1395+
with pytest.raises(ValueError):
14171396
to_datetime(df, cache=cache)
14181397

14191398
def test_dataframe_utc_true(self):
@@ -1521,8 +1500,7 @@ def test_to_datetime_barely_out_of_bounds(self):
15211500
# in an in-bounds datetime
15221501
arr = np.array(["2262-04-11 23:47:16.854775808"], dtype=object)
15231502

1524-
msg = "Out of bounds nanosecond timestamp"
1525-
with pytest.raises(OutOfBoundsDatetime, match=msg):
1503+
with pytest.raises(OutOfBoundsDatetime):
15261504
to_datetime(arr)
15271505

15281506
@pytest.mark.parametrize("cache", [True, False])
@@ -1660,8 +1638,7 @@ def test_to_datetime_overflow(self):
16601638
# gh-17637
16611639
# we are overflowing Timedelta range here
16621640

1663-
msg = "Python int too large to convert to C long"
1664-
with pytest.raises(OverflowError, match=msg):
1641+
with pytest.raises(OverflowError):
16651642
date_range(start="1/1/1700", freq="B", periods=100000)
16661643

16671644
@pytest.mark.parametrize("cache", [True, False])
@@ -2288,26 +2265,23 @@ def test_julian_round_trip(self):
22882265
assert result.to_julian_date() == 2456658
22892266

22902267
# out-of-bounds
2291-
msg = "1 is Out of Bounds for origin='julian'"
2292-
with pytest.raises(ValueError, match=msg):
2268+
with pytest.raises(ValueError):
22932269
pd.to_datetime(1, origin="julian", unit="D")
22942270

22952271
def test_invalid_unit(self, units, julian_dates):
22962272

22972273
# checking for invalid combination of origin='julian' and unit != D
22982274
if units != "D":
2299-
msg = "unit must be 'D' for origin='julian'"
2300-
with pytest.raises(ValueError, match=msg):
2275+
with pytest.raises(ValueError):
23012276
pd.to_datetime(julian_dates, unit=units, origin="julian")
23022277

23032278
def test_invalid_origin(self):
23042279

23052280
# need to have a numeric specified
2306-
msg = "it must be numeric with a unit specified"
2307-
with pytest.raises(ValueError, match=msg):
2281+
with pytest.raises(ValueError):
23082282
pd.to_datetime("2005-01-01", origin="1960-01-01")
23092283

2310-
with pytest.raises(ValueError, match=msg):
2284+
with pytest.raises(ValueError):
23112285
pd.to_datetime("2005-01-01", origin="1960-01-01", unit="D")
23122286

23132287
def test_epoch(self, units, epochs, epoch_1960, units_from_epochs):
@@ -2330,13 +2304,12 @@ def test_epoch(self, units, epochs, epoch_1960, units_from_epochs):
23302304
)
23312305
def test_invalid_origins(self, origin, exc, units, units_from_epochs):
23322306

2333-
msg = f"origin {origin} (is Out of Bounds|cannot be converted to a Timestamp)"
2334-
with pytest.raises(exc, match=msg):
2307+
with pytest.raises(exc):
23352308
pd.to_datetime(units_from_epochs, unit=units, origin=origin)
23362309

23372310
def test_invalid_origins_tzinfo(self):
23382311
# GH16842
2339-
with pytest.raises(ValueError, match="must be tz-naive"):
2312+
with pytest.raises(ValueError):
23402313
pd.to_datetime(1, unit="D", origin=datetime(2000, 1, 1, tzinfo=pytz.utc))
23412314

23422315
@pytest.mark.parametrize("format", [None, "%Y-%m-%d %H:%M:%S"])

0 commit comments

Comments
 (0)