diff --git a/pandas/tests/tslibs/test_array_to_datetime.py b/pandas/tests/tslibs/test_array_to_datetime.py index fc0000553049e..25975b5ce0163 100644 --- a/pandas/tests/tslibs/test_array_to_datetime.py +++ b/pandas/tests/tslibs/test_array_to_datetime.py @@ -298,3 +298,19 @@ def test_datetime_subclass(klass): expected = np.array(["2000-01-01T00:00:00.000000"], dtype="M8[us]") tm.assert_numpy_array_equal(result, expected) + + +import pandas as pd +from pandas import Timestamp + + +def test_to_datetime_format_long_string_gh54958(): + """ + Test that to_datetime with a specific format doesn't fail on strings + that are longer than the format implies. + GH#54958 + """ + ser = pd.Series(["2023010100"]) + expected = pd.Series([Timestamp("2023-01-01")]) + result = pd.to_datetime(ser, format="%Y%m%d") + tm.assert_series_equal(result, expected)