@@ -1113,42 +1113,41 @@ def test_convert_object_to_datetime_with_cache(
1113
1113
1114
1114
@pytest .mark .parametrize ("cache" , [True , False ])
1115
1115
@pytest .mark .parametrize (
1116
- ("input" , "expected" ),
1116
+ ("input" , "expected" , "warning" ),
1117
1117
(
1118
1118
(
1119
1119
Series ([NaT ] * 20 + [None ] * 20 , dtype = "object" ),
1120
1120
Series ([NaT ] * 40 , dtype = "datetime64[ns]" ),
1121
+ None ,
1121
1122
),
1122
1123
(
1123
1124
Series ([NaT ] * 60 + [None ] * 60 , dtype = "object" ),
1124
1125
Series ([NaT ] * 120 , dtype = "datetime64[ns]" ),
1126
+ None ,
1125
1127
),
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 ),
1145
1144
),
1146
1145
)
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
1149
1148
):
1150
1149
# 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" ):
1152
1151
result = to_datetime (input , cache = cache )
1153
1152
tm .assert_series_equal (result , expected )
1154
1153
@@ -1897,7 +1896,7 @@ def test_to_datetime_strings(self, cache):
1897
1896
def test_to_datetime_strings_variation (self , cache ):
1898
1897
array = ["2012" , "20120101" , "20120101 12:01:01" ]
1899
1898
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 ]
1901
1900
result = [Timestamp (date_str ) for date_str in array ]
1902
1901
tm .assert_almost_equal (result , expected )
1903
1902
@@ -2077,7 +2076,7 @@ def test_dayfirst_warnings_valid_input(self):
2077
2076
# GH 12585
2078
2077
warning_msg = (
2079
2078
"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."
2081
2080
)
2082
2081
2083
2082
# CASE 1: valid input
@@ -2663,7 +2662,10 @@ def test_incorrect_value_exception(self):
2663
2662
)
2664
2663
def test_to_datetime_out_of_bounds_with_format_arg (self , format , warning ):
2665
2664
# 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
+ )
2667
2669
with pytest .raises (OutOfBoundsDatetime , match = msg ):
2668
2670
with tm .assert_produces_warning (warning , match = "Could not infer format" ):
2669
2671
to_datetime ("2417-10-27 00:00:00" , format = format )
0 commit comments