From d4c864c835a0bcd008a1c514142b837bd739f20c Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 3 Nov 2020 20:48:04 +0100 Subject: [PATCH 1/2] Add tests for categorical with null ea as input --- pandas/tests/arrays/categorical/test_constructors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index 657511116c306..56adf7dbd7de8 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -682,3 +682,11 @@ def test_interval(self): expected_codes = np.array([0, 1], dtype="int8") tm.assert_numpy_array_equal(cat.codes, expected_codes) tm.assert_index_equal(cat.categories, idx) + + @pytest.mark.parametrize("nullable", [pd.NA, NaT]) + def test_categorical_extension_array_nullable(self, nullable): + # GH: + arr = pd.arrays.StringArray._from_sequence([nullable] * 2) + result = Categorical(arr) + expected = Categorical(Series([pd.NA, pd.NA], dtype="object")) + tm.assert_categorical_equal(result, expected) From 7a960dc2c6292c3a78154b97ab57f09867d60750 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 4 Nov 2020 03:11:41 +0100 Subject: [PATCH 2/2] Use null fixture --- pandas/tests/arrays/categorical/test_constructors.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index 56adf7dbd7de8..23921356a2c5d 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -683,10 +683,9 @@ def test_interval(self): tm.assert_numpy_array_equal(cat.codes, expected_codes) tm.assert_index_equal(cat.categories, idx) - @pytest.mark.parametrize("nullable", [pd.NA, NaT]) - def test_categorical_extension_array_nullable(self, nullable): + def test_categorical_extension_array_nullable(self, nulls_fixture): # GH: - arr = pd.arrays.StringArray._from_sequence([nullable] * 2) + arr = pd.arrays.StringArray._from_sequence([nulls_fixture] * 2) result = Categorical(arr) expected = Categorical(Series([pd.NA, pd.NA], dtype="object")) tm.assert_categorical_equal(result, expected)