@@ -349,9 +349,7 @@ def test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utc(self):
349
349
def test_to_datetime_parse_timezone_malformed (self , offset ):
350
350
fmt = "%Y-%m-%d %H:%M:%S %z"
351
351
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 ):
355
353
pd .to_datetime ([date ], format = fmt )
356
354
357
355
def test_to_datetime_parse_timezone_keeps_name (self ):
@@ -786,19 +784,17 @@ def test_to_datetime_tz_psycopg2(self, cache):
786
784
@pytest .mark .parametrize ("cache" , [True , False ])
787
785
def test_datetime_bool (self , cache ):
788
786
# GH13176
789
- msg = r"dtype bool cannot be converted to datetime64\[ns\]"
790
- with pytest .raises (TypeError , match = msg ):
787
+ with pytest .raises (TypeError ):
791
788
to_datetime (False )
792
789
assert to_datetime (False , errors = "coerce" , cache = cache ) is NaT
793
790
assert to_datetime (False , errors = "ignore" , cache = cache ) is False
794
- with pytest .raises (TypeError , match = msg ):
791
+ with pytest .raises (TypeError ):
795
792
to_datetime (True )
796
793
assert to_datetime (True , errors = "coerce" , cache = cache ) is NaT
797
794
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 ):
800
796
to_datetime ([False , datetime .today ()], cache = cache )
801
- with pytest .raises (TypeError , match = msg ):
797
+ with pytest .raises (TypeError ):
802
798
to_datetime (["20130101" , True ], cache = cache )
803
799
tm .assert_index_equal (
804
800
to_datetime ([0 , False , NaT , 0.0 ], errors = "coerce" , cache = cache ),
@@ -809,10 +805,10 @@ def test_datetime_bool(self, cache):
809
805
810
806
def test_datetime_invalid_datatype (self ):
811
807
# GH13176
812
- msg = "is not convertible to datetime"
813
- with pytest .raises (TypeError , match = msg ):
808
+
809
+ with pytest .raises (TypeError ):
814
810
pd .to_datetime (bool )
815
- with pytest .raises (TypeError , match = msg ):
811
+ with pytest .raises (TypeError ):
816
812
pd .to_datetime (pd .to_datetime )
817
813
818
814
@pytest .mark .parametrize ("value" , ["a" , "00:01:99" ])
@@ -830,12 +826,7 @@ def test_datetime_invalid_scalar(self, value, format, infer):
830
826
)
831
827
assert res is pd .NaT
832
828
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 ):
839
830
pd .to_datetime (
840
831
value , errors = "raise" , format = format , infer_datetime_format = infer
841
832
)
@@ -856,14 +847,12 @@ def test_datetime_outofbounds_scalar(self, value, format, infer):
856
847
assert res is pd .NaT
857
848
858
849
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 ):
861
851
pd .to_datetime (
862
852
value , errors = "raise" , format = format , infer_datetime_format = infer
863
853
)
864
854
else :
865
- msg = "Out of bounds nanosecond timestamp"
866
- with pytest .raises (OutOfBoundsDatetime , match = msg ):
855
+ with pytest .raises (OutOfBoundsDatetime ):
867
856
pd .to_datetime (
868
857
value , errors = "raise" , format = format , infer_datetime_format = infer
869
858
)
@@ -883,12 +872,7 @@ def test_datetime_invalid_index(self, values, format, infer):
883
872
)
884
873
tm .assert_index_equal (res , pd .DatetimeIndex ([pd .NaT ] * len (values )))
885
874
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 ):
892
876
pd .to_datetime (
893
877
values , errors = "raise" , format = format , infer_datetime_format = infer
894
878
)
@@ -1086,8 +1070,7 @@ def test_timestamp_utc_true(self, ts, expected):
1086
1070
@pytest .mark .parametrize ("dt_str" , ["00010101" , "13000101" , "30000101" , "99990101" ])
1087
1071
def test_to_datetime_with_format_out_of_bounds (self , dt_str ):
1088
1072
# GH 9107
1089
- msg = "Out of bounds nanosecond timestamp"
1090
- with pytest .raises (OutOfBoundsDatetime , match = msg ):
1073
+ with pytest .raises (OutOfBoundsDatetime ):
1091
1074
pd .to_datetime (dt_str , format = "%Y%m%d" )
1092
1075
1093
1076
def test_to_datetime_utc (self ):
@@ -1113,8 +1096,8 @@ class TestToDatetimeUnit:
1113
1096
def test_unit (self , cache ):
1114
1097
# GH 11758
1115
1098
# 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 ):
1118
1101
to_datetime ([1 ], unit = "D" , format = "%Y%m%d" , cache = cache )
1119
1102
1120
1103
values = [11111111 , 1 , 1.0 , iNaT , NaT , np .nan , "NaT" , "" ]
@@ -1140,8 +1123,7 @@ def test_unit(self, cache):
1140
1123
)
1141
1124
tm .assert_index_equal (result , expected )
1142
1125
1143
- msg = "cannot convert input 11111111 with the unit 'D'"
1144
- with pytest .raises (tslib .OutOfBoundsDatetime , match = msg ):
1126
+ with pytest .raises (tslib .OutOfBoundsDatetime ):
1145
1127
to_datetime (values , unit = "D" , errors = "raise" , cache = cache )
1146
1128
1147
1129
values = [1420043460000 , iNaT , NaT , np .nan , "NaT" ]
@@ -1154,8 +1136,7 @@ def test_unit(self, cache):
1154
1136
expected = DatetimeIndex (["NaT" , "NaT" , "NaT" , "NaT" , "NaT" ])
1155
1137
tm .assert_index_equal (result , expected )
1156
1138
1157
- msg = "cannot convert input 1420043460000 with the unit 's'"
1158
- with pytest .raises (tslib .OutOfBoundsDatetime , match = msg ):
1139
+ with pytest .raises (tslib .OutOfBoundsDatetime ):
1159
1140
to_datetime (values , errors = "raise" , unit = "s" , cache = cache )
1160
1141
1161
1142
# if we have a string, then we raise a ValueError
@@ -1223,16 +1204,15 @@ def test_unit_mixed(self, cache):
1223
1204
result = pd .to_datetime (arr , errors = "coerce" , cache = cache )
1224
1205
tm .assert_index_equal (result , expected )
1225
1206
1226
- msg = "mixed datetimes and integers in passed array"
1227
- with pytest .raises (ValueError , match = msg ):
1207
+ with pytest .raises (ValueError ):
1228
1208
pd .to_datetime (arr , errors = "raise" , cache = cache )
1229
1209
1230
1210
expected = DatetimeIndex (["NaT" , "NaT" , "2013-01-01" ])
1231
1211
arr = [1.434692e18 , 1.432766e18 , pd .Timestamp ("20130101" )]
1232
1212
result = pd .to_datetime (arr , errors = "coerce" , cache = cache )
1233
1213
tm .assert_index_equal (result , expected )
1234
1214
1235
- with pytest .raises (ValueError , match = msg ):
1215
+ with pytest .raises (ValueError ):
1236
1216
pd .to_datetime (arr , errors = "raise" , cache = cache )
1237
1217
1238
1218
@pytest .mark .parametrize ("cache" , [True , False ])
@@ -1412,8 +1392,7 @@ def test_dataframe_dtypes(self, cache):
1412
1392
1413
1393
# float
1414
1394
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 ):
1417
1396
to_datetime (df , cache = cache )
1418
1397
1419
1398
def test_dataframe_utc_true (self ):
@@ -1521,8 +1500,7 @@ def test_to_datetime_barely_out_of_bounds(self):
1521
1500
# in an in-bounds datetime
1522
1501
arr = np .array (["2262-04-11 23:47:16.854775808" ], dtype = object )
1523
1502
1524
- msg = "Out of bounds nanosecond timestamp"
1525
- with pytest .raises (OutOfBoundsDatetime , match = msg ):
1503
+ with pytest .raises (OutOfBoundsDatetime ):
1526
1504
to_datetime (arr )
1527
1505
1528
1506
@pytest .mark .parametrize ("cache" , [True , False ])
@@ -1660,8 +1638,7 @@ def test_to_datetime_overflow(self):
1660
1638
# gh-17637
1661
1639
# we are overflowing Timedelta range here
1662
1640
1663
- msg = "Python int too large to convert to C long"
1664
- with pytest .raises (OverflowError , match = msg ):
1641
+ with pytest .raises (OverflowError ):
1665
1642
date_range (start = "1/1/1700" , freq = "B" , periods = 100000 )
1666
1643
1667
1644
@pytest .mark .parametrize ("cache" , [True , False ])
@@ -2288,26 +2265,23 @@ def test_julian_round_trip(self):
2288
2265
assert result .to_julian_date () == 2456658
2289
2266
2290
2267
# 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 ):
2293
2269
pd .to_datetime (1 , origin = "julian" , unit = "D" )
2294
2270
2295
2271
def test_invalid_unit (self , units , julian_dates ):
2296
2272
2297
2273
# checking for invalid combination of origin='julian' and unit != D
2298
2274
if units != "D" :
2299
- msg = "unit must be 'D' for origin='julian'"
2300
- with pytest .raises (ValueError , match = msg ):
2275
+ with pytest .raises (ValueError ):
2301
2276
pd .to_datetime (julian_dates , unit = units , origin = "julian" )
2302
2277
2303
2278
def test_invalid_origin (self ):
2304
2279
2305
2280
# 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 ):
2308
2282
pd .to_datetime ("2005-01-01" , origin = "1960-01-01" )
2309
2283
2310
- with pytest .raises (ValueError , match = msg ):
2284
+ with pytest .raises (ValueError ):
2311
2285
pd .to_datetime ("2005-01-01" , origin = "1960-01-01" , unit = "D" )
2312
2286
2313
2287
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):
2330
2304
)
2331
2305
def test_invalid_origins (self , origin , exc , units , units_from_epochs ):
2332
2306
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 ):
2335
2308
pd .to_datetime (units_from_epochs , unit = units , origin = origin )
2336
2309
2337
2310
def test_invalid_origins_tzinfo (self ):
2338
2311
# GH16842
2339
- with pytest .raises (ValueError , match = "must be tz-naive" ):
2312
+ with pytest .raises (ValueError ):
2340
2313
pd .to_datetime (1 , unit = "D" , origin = datetime (2000 , 1 , 1 , tzinfo = pytz .utc ))
2341
2314
2342
2315
@pytest .mark .parametrize ("format" , [None , "%Y-%m-%d %H:%M:%S" ])
0 commit comments