Skip to content

Commit a0c7051

Browse files
Update tests according to discussion
1 parent c5fc3c6 commit a0c7051

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

pandas/tests/series/test_constructors.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,31 @@ def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
909909
expected = Series(pd.Timestamp(arg)).dt.tz_localize('CET')
910910
assert_series_equal(result, expected)
911911

912-
def test_constructor_datetime64_outofbound(self):
913-
# GH-26206 out of bound non-ns unit
912+
@pytest.mark.parametrize("a", [
913+
np.array(['2263-01-01'], dtype='datetime64[D]'),
914+
np.array([datetime(2263, 1, 1)], dtype=object),
915+
np.array([np.datetime64('2263-01-01', 'D')], dtype=object),
916+
np.array(["2263-01-01"], dtype=object)
917+
], ids=['datetime64[D]', 'object-datetime.datetime',
918+
'object-numpy-scalar', 'object-string'])
919+
def test_constructor_datetime_outofbound(self, a):
920+
# GH-26853 (+ bug GH-26206 out of bound non-ns unit)
921+
922+
# No dtype specified (dtype inference)
923+
# datetime64[non-ns] raise error, other cases result in object dtype
924+
# and preserve original data
925+
if a.dtype.kind == 'M':
926+
with pytest.raises(pd.errors.OutOfBoundsDatetime):
927+
pd.Series(a)
928+
else:
929+
result = pd.Series(a)
930+
assert result.dtype == 'object'
931+
tm.assert_numpy_array_equal(result.to_numpy(), a)
932+
933+
# Explicit dtype specified
934+
# Forced conversion fails for all -> all cases raise error
914935
with pytest.raises(pd.errors.OutOfBoundsDatetime):
915-
pd.Series(np.array(['2262-04-12'], dtype='datetime64[D]'))
936+
pd.Series(a, dtype='datetime64[ns]')
916937

917938
def test_construction_interval(self):
918939
# construction from interval & array of intervals

0 commit comments

Comments
 (0)