-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: GH25495 incorrect dtype when using .loc to set Categorical value for column in 1-row DataFrame #29393
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
BUG: GH25495 incorrect dtype when using .loc to set Categorical value for column in 1-row DataFrame #29393
Changes from 8 commits
712e871
a23b3c9
550d68d
c945ab1
5d47754
2dfa594
3e847e9
8c5a88e
ca60804
b1520b8
2e95853
39c95f4
2b71592
e5c1420
4257fe8
593dda1
5512119
c5a7f6e
4c339ac
241bd7c
41e6ce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3849,6 +3849,16 @@ def test_assigning_ops(self): | |
df.loc[2:3, "b"] = Categorical(["b", "b"], categories=["a", "b"]) | ||
tm.assert_frame_equal(df, exp) | ||
|
||
def test_setitem_single_row_categorical(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move to pandas/tests/frame/indexing/test_indexing.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merged master, and moved to pandas/tests/frame/indexing/test_categorical.py. All tests passed @jreback |
||
# GH 25495 | ||
df = DataFrame({"Alpha": ["a"], "Numeric": [0]}) | ||
categories = pd.Categorical(df["Alpha"], categories=["a", "b", "c"]) | ||
df.loc[:, "Alpha"] = categories | ||
|
||
result = df["Alpha"] | ||
expected = Series(categories, index=df.index, name="Alpha") | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_functions_no_warnings(self): | ||
df = DataFrame({"value": np.random.randint(0, 100, 20)}) | ||
labels = ["{0} - {1}".format(i, i + 9) for i in range(0, 100, 10)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
is_categorical_dtype(arr_value.dtype)
is_categorical_astype is not necessary here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes, and merged master. All tests passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jreback, is the PR good to merge to master?