-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Open
Labels
BugPDEP6-relatedrelated to PDEP6 (not upcasting during setitem-like Series operations)related to PDEP6 (not upcasting during setitem-like Series operations)
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
In [7]: df = pd.DataFrame(range(2))
In [8]: df.iloc[:, 0] = df.iloc[:, 0].astype("category")
TypeError: Invalid value '0 0
1 1
Name: 0, dtype: category
Categories (2, int64): [0, 1]' for dtype 'int64'Issue Description
In the PDEP 6 discussions (#39584 #50424), I can't find any discussion really of whether setting values with a different "representation" (e.g. to category or sparse) of the dtype should be disallowed. Technically casting to e.g. category, sparse, ArrowDtype of the same underlying type doesn't upcast, so should that be allowed?
Expected Behavior
Setitem with category/sparse/ArrowDtype that doesn't change the underlying type should be allowed
Installed Versions
Replace this line with the output of pd.show_versions()
Metadata
Metadata
Assignees
Labels
BugPDEP6-relatedrelated to PDEP6 (not upcasting during setitem-like Series operations)related to PDEP6 (not upcasting during setitem-like Series operations)