Skip to content

Commit 6af0391

Browse files
committed
use np.sctypes to extract all dtypes
1 parent 09a602d commit 6af0391

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

pandas/tests/series/test_dtypes.py

-27
Original file line numberDiff line numberDiff line change
@@ -506,33 +506,6 @@ def test_is_homogeneous_type(self):
506506
assert Series([1, 2])._is_homogeneous_type
507507
assert Series(pd.Categorical([1, 2]))._is_homogeneous_type
508508

509-
@pytest.mark.parametrize(
510-
"data, uniques, dtype",
511-
[
512-
([1, 2, 2], [1, 2], "int8"),
513-
([1, 2, 2], [1, 2], "int16"),
514-
([1, 2, 2], [1, 2], "int32"),
515-
([1, 2, 2], [1, 2], "int64"),
516-
([1, 2, 2], [1, 2], "uint8"),
517-
([1, 2, 2], [1, 2], "uint16"),
518-
([1, 2, 2], [1, 2], "uint32"),
519-
([1, 2, 2], [1, 2], "uint64"),
520-
([1, 2, 2], [1.0, 2.0], "float16"),
521-
([1, 2, 2], [1.0, 2.0], "float32"),
522-
([1, 2, 2], [1.0, 2.0], "float64"),
523-
([1, 2, 2], [1.0, 2.0], "complex64"),
524-
([1, 2, 2], [1.0, 2.0], "complex128"),
525-
([True, True, False], [True, False], "bool"),
526-
(["A", "A", "B"], ["A", "B"], "object"),
527-
],
528-
)
529-
def test_unique_preserve_dtype(self, data, uniques, dtype):
530-
# GH 15442
531-
result = Series(data, dtype=dtype).unique()
532-
expected = np.array(uniques, dtype=dtype)
533-
534-
tm.assert_numpy_array_equal(result, expected)
535-
536509
@pytest.mark.parametrize(
537510
"data",
538511
[

pandas/tests/test_algos.py

+19
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,25 @@ def test_on_index_object(self):
353353

354354
tm.assert_almost_equal(result, expected)
355355

356+
@pytest.mark.parametrize(
357+
"data, uniques, dtype_list",
358+
[
359+
([1, 2, 2], [1, 2], np.sctypes["int"]),
360+
([1, 2, 2], [1, 2], np.sctypes["uint"]),
361+
([1, 2, 2], [1.0, 2.0], np.sctypes["float"]),
362+
([1, 2, 2], [1.0, 2.0], np.sctypes["complex"]),
363+
([True, True, False], [True, False], np.sctypes["others"]), # bool, object
364+
],
365+
)
366+
def test_dtype_preservation(self, data, uniques, dtype_list):
367+
# GH 15442
368+
for dtype in dtype_list:
369+
if dtype not in [bytes, str, np.void]:
370+
result = Series(data, dtype=dtype).unique()
371+
expected = np.array(uniques, dtype=dtype)
372+
373+
tm.assert_numpy_array_equal(result, expected)
374+
356375
def test_datetime64_dtype_array_returned(self):
357376
# GH 9431
358377
expected = np_array_datetime64_compat(

0 commit comments

Comments
 (0)