Skip to content

Commit bf2e77c

Browse files
move tests
1 parent bbb59b1 commit bf2e77c

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

pandas/tests/series/test_constructors.py

-33
Original file line numberDiff line numberDiff line change
@@ -909,39 +909,6 @@ 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-
@pytest.mark.parametrize("klass", [
913-
Series,
914-
lambda x, **kwargs: DataFrame({'a': x}, **kwargs)['a'],
915-
pytest.param(lambda x, **kwargs: DataFrame(x, **kwargs)[0],
916-
marks=pytest.mark.xfail),
917-
Index,
918-
])
919-
@pytest.mark.parametrize("a", [
920-
np.array(['2263-01-01'], dtype='datetime64[D]'),
921-
np.array([datetime(2263, 1, 1)], dtype=object),
922-
np.array([np.datetime64('2263-01-01', 'D')], dtype=object),
923-
np.array(["2263-01-01"], dtype=object)
924-
], ids=['datetime64[D]', 'object-datetime.datetime',
925-
'object-numpy-scalar', 'object-string'])
926-
def test_constructor_datetime_outofbound(self, a, klass):
927-
# GH-26853 (+ bug GH-26206 out of bound non-ns unit)
928-
929-
# No dtype specified (dtype inference)
930-
# datetime64[non-ns] raise error, other cases result in object dtype
931-
# and preserve original data
932-
if a.dtype.kind == 'M':
933-
with pytest.raises(pd.errors.OutOfBoundsDatetime):
934-
klass(a)
935-
else:
936-
result = klass(a)
937-
assert result.dtype == 'object'
938-
tm.assert_numpy_array_equal(result.to_numpy(), a)
939-
940-
# Explicit dtype specified
941-
# Forced conversion fails for all -> all cases raise error
942-
with pytest.raises(pd.errors.OutOfBoundsDatetime):
943-
klass(a, dtype='datetime64[ns]')
944-
945912
def test_construction_interval(self):
946913
# construction from interval & array of intervals
947914
index = IntervalIndex.from_breaks(np.arange(3), closed='right')

pandas/tests/test_base.py

+38
Original file line numberDiff line numberDiff line change
@@ -1341,3 +1341,41 @@ def test_to_numpy_dtype(as_series):
13411341
expected = np.array(['2000-01-01T05', '2001-01-01T05'],
13421342
dtype='M8[ns]')
13431343
tm.assert_numpy_array_equal(result, expected)
1344+
1345+
1346+
class TestConstruction:
1347+
# test certain constructor behaviours on dtype inference across Series,
1348+
# Index and DataFrame
1349+
1350+
@pytest.mark.parametrize("klass", [
1351+
Series,
1352+
lambda x, **kwargs: DataFrame({'a': x}, **kwargs)['a'],
1353+
pytest.param(lambda x, **kwargs: DataFrame(x, **kwargs)[0],
1354+
marks=pytest.mark.xfail),
1355+
Index,
1356+
])
1357+
@pytest.mark.parametrize("a", [
1358+
np.array(['2263-01-01'], dtype='datetime64[D]'),
1359+
np.array([datetime(2263, 1, 1)], dtype=object),
1360+
np.array([np.datetime64('2263-01-01', 'D')], dtype=object),
1361+
np.array(["2263-01-01"], dtype=object)
1362+
], ids=['datetime64[D]', 'object-datetime.datetime',
1363+
'object-numpy-scalar', 'object-string'])
1364+
def test_constructor_datetime_outofbound(self, a, klass):
1365+
# GH-26853 (+ bug GH-26206 out of bound non-ns unit)
1366+
1367+
# No dtype specified (dtype inference)
1368+
# datetime64[non-ns] raise error, other cases result in object dtype
1369+
# and preserve original data
1370+
if a.dtype.kind == 'M':
1371+
with pytest.raises(pd.errors.OutOfBoundsDatetime):
1372+
klass(a)
1373+
else:
1374+
result = klass(a)
1375+
assert result.dtype == 'object'
1376+
tm.assert_numpy_array_equal(result.to_numpy(), a)
1377+
1378+
# Explicit dtype specified
1379+
# Forced conversion fails for all -> all cases raise error
1380+
with pytest.raises(pd.errors.OutOfBoundsDatetime):
1381+
klass(a, dtype='datetime64[ns]')

0 commit comments

Comments
 (0)