Skip to content

BUG: DataFrame.astype with category dtype #16983

Closed
@rhaps0dy

Description

@rhaps0dy

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'a': list('aab'), 'b': list('bba')})
df.a = df.a.astype('category')
df.b = df.b.astype('category')
df.astype('object')
# ValueError: Wrong number of dimensions

related failure

In [1]: df = pd.DataFrame({
   ...:     'a': ['foo', 'bar', None],
   ...:     'b': ['baz', 'quux', None]
   ...: }, dtype='category')
   ...: df
   ...: 
Out[1]: 
     a     b
0  foo   baz
1  bar  quux
2  NaN   NaN

In [2]: df.where(df.isnull(), None)
---------------------------------------------------------------------------
ValueError: Wrong number of items passed 3, placement implies 1

Problem description

Object dataframes can contain any Python object so anything should be convertible to them. Split off of #16979.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions