Skip to content

Commit 8838773

Browse files
committed
add test2
1 parent 2965213 commit 8838773

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

pandas/tests/dtypes/cast/test_construct_ndarray.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414
(["1", "2", None], None, np.array(["1", "2", None])),
1515
(["1", "2", None], np.dtype("str"), np.array(["1", "2", None])),
1616
([1, 2, None], np.dtype("str"), np.array(["1", "2", None])),
17+
],
18+
)
19+
def test_construct_1d_ndarray_preserving_na(
20+
values, dtype, expected, using_infer_string
21+
):
22+
result = sanitize_array(values, index=None, dtype=dtype)
23+
if using_infer_string and expected.dtype == object and dtype is None:
24+
tm.assert_extension_array_equal(result, pd.array(expected, dtype="str"))
25+
else:
26+
tm.assert_numpy_array_equal(result, expected)
27+
28+
29+
@pytest.mark.parametrize("dtype", ["m8[ns]", "M8[ns]"])
30+
def test_construct_1d_ndarray_preserving_na_datetimelike(dtype):
31+
arr = np.arange(5, dtype=np.int64).view(dtype)
32+
expected = np.array(list(arr), dtype=object)
33+
assert all(isinstance(x, type(arr[0])) for x in expected)
34+
35+
result = sanitize_array(arr, index=None, dtype=np.dtype(object))
36+
tm.assert_numpy_array_equal(result, expected)
37+
38+
39+
@pytest.mark.parametrize(
40+
"values, dtype, expected",
41+
[
1742
(
1843
np.ma.masked_array([1, 2, 3], mask=[False, True, False]),
1944
"int64",
@@ -41,26 +66,6 @@
4166
),
4267
],
4368
)
44-
def test_construct_1d_ndarray_preserving_na(
45-
values, dtype, expected, using_infer_string
46-
):
47-
result = sanitize_array(values, index=None, dtype=dtype)
48-
if using_infer_string and expected.dtype == object and dtype is None:
49-
tm.assert_extension_array_equal(result, pd.array(expected, dtype="str"))
50-
else:
51-
tm.assert_numpy_array_equal(result, expected)
52-
53-
54-
@pytest.mark.parametrize("dtype", ["m8[ns]", "M8[ns]"])
55-
def test_construct_1d_ndarray_preserving_na_datetimelike(dtype):
56-
arr = np.arange(5, dtype=np.int64).view(dtype)
57-
expected = np.array(list(arr), dtype=object)
58-
assert all(isinstance(x, type(arr[0])) for x in expected)
59-
60-
result = sanitize_array(arr, index=None, dtype=np.dtype(object))
61-
tm.assert_numpy_array_equal(result, expected)
62-
63-
6469
def test_sanitize_masked_array_with_masked_ea(values, dtype, expected):
6570
result = sanitize_array(values, dtype=dtype)
6671
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)