Skip to content

BUG-24971 copying blocks also considers ndim #25521

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 5 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Bug Fixes

**Categorical**

-
- Bug where a copy of a categorical could have the wrong dimensions (:issue:`24971`)
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 reword to make this more clear. mentione this is on a Series of categorical dtype. The dimenension issue is an internal one. You want to emphasize the user visible effects.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is visible when you call .replace()

-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def copy(self, deep=True):
values = self.values
if deep:
values = values.copy()
return self.make_block_same_class(values)
return self.make_block_same_class(values, ndim=self.ndim)

def replace(self, to_replace, value, inplace=False, filter=None,
regex=False, convert=True):
Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pandas.compat import PY36, long, lrange, range, zip

from pandas.core.dtypes.common import (
is_categorical_dtype, is_datetime64tz_dtype)
is_categorical_dtype, is_datetime64tz_dtype, is_list_like)

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -532,6 +532,11 @@ def test_constructor_copy(self):
assert x[0] == 2.
assert y[0] == 1.

def test_copy_categorical_ndim(self):
# GH 24971
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 put all 3 tests from the OP here.

s = Series(Categorical(['A'], categories=['A']))
assert not is_list_like(s.replace({'A': 1})[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

use assert_series_equal


Copy link
Contributor

Choose a reason for hiding this comment

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

this should go with the replace tests

@pytest.mark.parametrize(
"index",
[
Expand Down