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

Converting Series to categorical #16524

Closed
ttylec opened this Issue May 28, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@ttylec

ttylec commented May 28, 2017

When converting Series to categorical dtype, the following method

pd.Series(pd.Series(['a', 'b', 'c']), dtype='category')

fails with traceback

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-6c903a3f0db3> in <module>()
----> 1 pd.Series(pd.Series(['a', 'b', 'c']), dtype='category')

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    241                 if dtype is not None:
    242                     data = data.astype(dtype=dtype, raise_on_error=False,
--> 243                                        copy=copy)
    244                 elif copy:
    245                     data = data.copy()

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in astype(self, dtype, **kwargs)
   3222 
   3223     def astype(self, dtype, **kwargs):
-> 3224         return self.apply('astype', dtype=dtype, **kwargs)
   3225 
   3226     def convert(self, **kwargs):

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
   3089 
   3090             kwargs['mgr'] = self
-> 3091             applied = getattr(b, f)(**kwargs)
   3092             result_blocks = _extend_blocks(applied, result_blocks)
   3093 

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in astype(self, dtype, copy, errors, values, **kwargs)
    469     def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
    470         return self._astype(dtype, copy=copy, errors=errors, values=values,
--> 471                             **kwargs)
    472 
    473     def _astype(self, dtype, copy=False, errors='raise', values=None,

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
    488         # this is only called for non-categoricals
    489         if self.is_categorical_astype(dtype):
--> 490             return self.make_block(Categorical(self.values, **kwargs))
    491 
    492         # astype processing

TypeError: __init__() got an unexpected keyword argument 'raise_on_error'

When using simple list or np.array instead of pd.Series, it work. Doing .astype('category') also works.

INSTALLED VERSIONS ------------------ commit: None python: 3.6.1.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.20.1
pytest: None
pip: 9.0.1
setuptools: 35.0.1
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback May 29, 2017

Contributor

yeah this should work. the riase_on_error arg should not be passed thru here (we changing this arg in the future anyhow)

PR's are welcome.

Contributor

jreback commented May 29, 2017

yeah this should work. the riase_on_error arg should not be passed thru here (we changing this arg in the future anyhow)

PR's are welcome.

@jreback jreback added this to the Next Major Release milestone May 29, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue May 31, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue May 31, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 1, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 1, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 1, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 2, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 4, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 5, 2017

preddy5 added a commit to preddy5/pandas that referenced this issue Jun 5, 2017

TomAugspurger added a commit to preddy5/pandas that referenced this issue Jun 7, 2017

@jreback jreback modified the milestones: 0.20.3, Next Major Release Jun 8, 2017

jorisvandenbossche added a commit that referenced this issue Jun 9, 2017

Kiv added a commit to Kiv/pandas that referenced this issue Jun 11, 2017

stangirala added a commit to stangirala/pandas that referenced this issue Jun 11, 2017

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jul 6, 2017

TomAugspurger added a commit that referenced this issue Jul 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment