updates · pandas-dev/pandas@6008c08 (original) (raw)

`@@ -462,11 +462,6 @@ def test_from_codes(self):

`

462

462

`res = Categorical.from_codes([0, 1, 2], dtype=dtype)

`

463

463

`tm.assert_categorical_equal(exp, res)

`

464

464

``

465

``

`-

codes = np.random.choice([0, 1], 5, p=[0.9, 0.1])

`

466

``

`-

dtype = CategoricalDtype(categories=["train", "test"])

`

467

``

`-

Categorical.from_codes(codes, categories=dtype.categories)

`

468

``

`-

Categorical.from_codes(codes, dtype=dtype)

`

469

``

-

470

465

`def test_from_codes_with_categorical_categories(self):

`

471

466

`# GH17884

`

472

467

`expected = Categorical(['a', 'b'], categories=['a', 'b', 'c'])

`

`@@ -516,6 +511,16 @@ def test_from_codes_with_float(self):

`

516

511

`match="codes need to be array-like integers"):

`

517

512

`Categorical.from_codes(codes, dtype=dtype)

`

518

513

``

``

514

`+

def test_from_codes_with_dtype_raises(self):

`

``

515

`+

msg = 'Cannot specify'

`

``

516

`+

with pytest.raises(ValueError, match=msg):

`

``

517

`+

Categorical([0, 1], categories=['a', 'b'],

`

``

518

`+

dtype=CategoricalDtype(['a', 'b']))

`

``

519

+

``

520

`+

with pytest.raises(ValueError, match=msg):

`

``

521

`+

Categorical([0, 1], ordered=True,

`

``

522

`+

dtype=CategoricalDtype(['a', 'b']))

`

``

523

+

519

524

`@pytest.mark.parametrize('dtype', [None, 'category'])

`

520

525

`def test_from_inferred_categories(self, dtype):

`

521

526

`cats = ['a', 'b']

`