Skip to content

BUG: astype('Int64') raises AttributeError #22578

Closed
@jorisvandenbossche

Description

@jorisvandenbossche
In [8]: df = pd.DataFrame([[1., 2.], [3., 4.], [5., 6.]], columns=['a', 'b'])

In [9]: df
Out[9]: 
     a    b
0  1.0  2.0
1  3.0  4.0
2  5.0  6.0

In [10]: df.astype('Int64')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-b9d2763e69d8> in <module>()
----> 1 df.astype('Int64')

~/scipy/pandas/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    175                 else:
    176                     kwargs[new_arg_name] = new_arg_value
--> 177             return func(*args, **kwargs)
    178         return wrapper
    179     return _deprecate_kwarg

~/scipy/pandas/pandas/core/generic.py in astype(self, dtype, copy, errors, **kwargs)
   5162             # else, only a single dtype is given
   5163             new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,
-> 5164                                          **kwargs)
   5165             return self._constructor(new_data).__finalize__(self)
   5166 

~/scipy/pandas/pandas/core/internals/managers.py in astype(self, dtype, **kwargs)
    554 
    555     def astype(self, dtype, **kwargs):
--> 556         return self.apply('astype', dtype=dtype, **kwargs)
    557 
    558     def convert(self, **kwargs):

~/scipy/pandas/pandas/core/internals/managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
    421 
    422             kwargs['mgr'] = self
--> 423             applied = getattr(b, f)(**kwargs)
    424             result_blocks = _extend_blocks(applied, result_blocks)
    425 

~/scipy/pandas/pandas/core/internals/blocks.py in astype(self, dtype, copy, errors, values, **kwargs)
    562     def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
    563         return self._astype(dtype, copy=copy, errors=errors, values=values,
--> 564                             **kwargs)
    565 
    566     def _astype(self, dtype, copy=False, errors='raise', values=None,

~/scipy/pandas/pandas/core/internals/blocks.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
    679                     "current ({newb_dtype} [{newb_size}])".format(
    680                         copy=copy, dtype=self.dtype.name,
--> 681                         itemsize=self.itemsize, newb_dtype=newb.dtype.name,
    682                         newb_size=newb.itemsize))
    683         return newb

AttributeError: 'FloatBlock' object has no attribute 'itemsize'

The same if the starting dataframe is of integer dtype.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions