Skip to content
Prev Previous commit
Next Next commit
expand test for demonstration purposes
  • Loading branch information
Robert Schmidtke committed Feb 16, 2024
commit b4c825da2f87131b379ee81119ccdc3ba8237fec
22 changes: 14 additions & 8 deletions pandas/tests/tslibs/test_array_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,21 @@ def test_to_datetime_barely_out_of_bounds():
tslib.array_to_datetime(arr)


def test_to_datetime_barely_inside_bounds():
@pytest.mark.parametrize(
"timestamp",
[
# Close enough to bounds that scaling micros to nanos overflows
# but adding nanos would result in an in-bounds datetime.
"1677-09-21T00:12:43.145224193",
"1677-09-21T00:12:43.145224999",
# this always worked
"1677-09-21T00:12:43.145225000",
],
)
def test_to_datetime_barely_inside_bounds(timestamp):
# see gh-57150
#
# Close enough to bounds that scaling micros to nanos overflows
# but adding nanos would result in an in-bounds datetime.
arr = np.array(["1677-09-21T00:12:43.145224193"], dtype=object)
result, _ = tslib.array_to_datetime(arr)
expected = ["1677-09-21T00:12:43.145224193"]
tm.assert_numpy_array_equal(result, np.array(expected, dtype="M8[ns]"))
result, _ = tslib.array_to_datetime(np.array([timestamp], dtype=object))
tm.assert_numpy_array_equal(result, np.array([timestamp], dtype="M8[ns]"))


class SubDatetime(datetime):
Expand Down