@@ -146,7 +146,8 @@ def test_to_datetime_format_YYYYMM_with_nat(self, cache):
146
146
result = to_datetime (ser , format = "%Y%m" , cache = cache )
147
147
tm .assert_series_equal (result , expected )
148
148
149
- def test_to_datetime_format_YYYYMM_with_nat (self , cache ):
149
+ def test_to_datetime_format_YYYYMM_with_nat_2 (self , cache ):
150
+ # is this different from above? can remove?
150
151
# https://github.com/pandas-dev/pandas/issues/50237
151
152
ser = Series ([198012 , 198012 ] + [198101 ] * 5 )
152
153
expected = Series (
@@ -1748,8 +1749,8 @@ def test_dataframe_coerce(self, cache):
1748
1749
df2 = DataFrame ({"year" : [2015 , 2016 ], "month" : [2 , 20 ], "day" : [4 , 5 ]})
1749
1750
1750
1751
msg = (
1751
- r"cannot assemble the datetimes: time data .+ at position 1 doesn\'t "
1752
- r"match format \" %Y%m%d\" "
1752
+ r"cannot assemble the datetimes: time data '.*' does not match "
1753
+ r"format ' %Y%m%d' \(match\) "
1753
1754
)
1754
1755
with pytest .raises (ValueError , match = msg ):
1755
1756
to_datetime (df2 , cache = cache )
@@ -1825,10 +1826,7 @@ def test_dataframe_mixed(self, cache):
1825
1826
def test_dataframe_float (self , cache ):
1826
1827
# float
1827
1828
df = DataFrame ({"year" : [2000 , 2001 ], "month" : [1.5 , 1 ], "day" : [1 , 1 ]})
1828
- msg = (
1829
- 'cannot assemble the datetimes: time data "20000151" at position 0 '
1830
- 'doesn\' t match format "%Y%m%d"'
1831
- )
1829
+ msg = "cannot assemble the datetimes: unconverted data remains: 1"
1832
1830
with pytest .raises (ValueError , match = msg ):
1833
1831
to_datetime (df , cache = cache )
1834
1832
@@ -1887,10 +1885,7 @@ def test_to_datetime_iso8601_fails(self, input, format, exact):
1887
1885
# `format` is longer than the string, so this fails regardless of `exact`
1888
1886
with pytest .raises (
1889
1887
ValueError ,
1890
- match = (
1891
- rf"time data \"{ input } \" at position 0 doesn't match format "
1892
- rf"\" { format } \""
1893
- ),
1888
+ match = (rf"time data '{ input } ' does not match format '{ format } '" ),
1894
1889
):
1895
1890
to_datetime (input , format = format , exact = exact )
1896
1891
@@ -1909,10 +1904,7 @@ def test_to_datetime_iso8601_exact_fails(self, input, format):
1909
1904
# `format` is shorter than the date string, so only fails with `exact=True`
1910
1905
with pytest .raises (
1911
1906
ValueError ,
1912
- match = (
1913
- rf"time data \"{ input } \" at position 0 doesn't match format "
1914
- rf"\" { format } \""
1915
- ),
1907
+ match = ("unconverted data remains: |does not match format" ),
1916
1908
):
1917
1909
to_datetime (input , format = format )
1918
1910
@@ -1948,10 +1940,7 @@ def test_to_datetime_iso8601_separator(self, input, format):
1948
1940
# https://github.com/pandas-dev/pandas/issues/12649
1949
1941
with pytest .raises (
1950
1942
ValueError ,
1951
- match = (
1952
- rf"time data \"{ input } \" at position 0 doesn\'t match format "
1953
- rf"\" { format } \""
1954
- ),
1943
+ match = (rf"time data \'{ input } \' does not match format '{ format } '" ),
1955
1944
):
1956
1945
to_datetime (input , format = format )
1957
1946
@@ -1977,6 +1966,28 @@ def test_to_datetime_iso8601_valid(self, input, format):
1977
1966
result = to_datetime (input , format = format )
1978
1967
assert result == expected
1979
1968
1969
+ @pytest .mark .parametrize (
1970
+ "input, format" ,
1971
+ [
1972
+ ("2020-1" , "%Y-%m" ),
1973
+ ("2020-1-1" , "%Y-%m-%d" ),
1974
+ ("2020-1-1 0" , "%Y-%m-%d %H" ),
1975
+ ("2020-1-1T0" , "%Y-%m-%dT%H" ),
1976
+ ("2020-1-1 0:0" , "%Y-%m-%d %H:%M" ),
1977
+ ("2020-1-1T0:0" , "%Y-%m-%dT%H:%M" ),
1978
+ ("2020-1-1 0:0:0" , "%Y-%m-%d %H:%M:%S" ),
1979
+ ("2020-1-1T0:0:0" , "%Y-%m-%dT%H:%M:%S" ),
1980
+ ("2020-1-1T0:0:0.000" , "%Y-%m-%dT%H:%M:%S.%f" ),
1981
+ ("2020-1-1T0:0:0.000000" , "%Y-%m-%dT%H:%M:%S.%f" ),
1982
+ ("2020-1-1T0:0:0.000000000" , "%Y-%m-%dT%H:%M:%S.%f" ),
1983
+ ],
1984
+ )
1985
+ def test_to_datetime_iso8601_non_padded (self , input , format ):
1986
+ # https://github.com/pandas-dev/pandas/issues/21422
1987
+ expected = Timestamp (2020 , 1 , 1 )
1988
+ result = to_datetime (input , format = format )
1989
+ assert result == expected
1990
+
1980
1991
@pytest .mark .parametrize (
1981
1992
"input, format" ,
1982
1993
[
@@ -2479,7 +2490,7 @@ def test_day_not_in_month_raise(self, cache):
2479
2490
2480
2491
@pytest .mark .parametrize ("arg" , ["2015-02-29" , "2015-02-32" , "2015-04-31" ])
2481
2492
def test_day_not_in_month_raise_value (self , cache , arg ):
2482
- msg = f'time data " { arg } " at position 0 doesn \' t match format "%Y-%m-%d"'
2493
+ msg = "day is out of range for month|unconverted data remains"
2483
2494
with pytest .raises (ValueError , match = msg ):
2484
2495
to_datetime (arg , errors = "raise" , format = "%Y-%m-%d" , cache = cache )
2485
2496
0 commit comments