Skip to content

TST: Series.update with categorical #38873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ def test_repr_range_categories(self):
expected = "CategoricalDtype(categories=range(0, 3), ordered=False)"
assert result == expected

def test_update_dtype(self):
# GH 27338
result = CategoricalDtype(["a"]).update_dtype(Categorical(["b"], ordered=True))
expected = CategoricalDtype(["b"], ordered=True)
assert result == expected


class TestDatetimeTZDtype(Base):
@pytest.fixture
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/series/methods/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,11 @@ def test_update_from_non_series(self, series, other, expected):
def test_update_extension_array_series(self, result, target, expected):
result.update(target)
tm.assert_series_equal(result, expected)
def test_update_with_categorical_type(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a blank line before the test.

# GH 25744
t = CategoricalDtype(['a', 'b', 'c', 'd'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this dtype

s1 = Series(['a', 'b', 'c'], index=[1, 2, 3], dtype=t)
s2 = Series(['b', 'a'], index=[1, 2], dtype=t)
result = s1.update(s2)
expected = Series(['b', 'a', 'c'], index=[1, 2, 3], dtype=t)
tm.assert_series_equal(result, expected)