Skip to content

BUG: creating dataframe from empty series raises exception #5756

Closed
@immerrr

Description

@immerrr

Here's a snippet to show what I'm talking about:

In [1]: pd.__version__
Out[1]: '0.13.0rc1-95-gfec2ff6'

In [2]: pd.DataFrame(pd.Series())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-31c6b8fd30b1> in <module>()
----> 1 pd.DataFrame(pd.Series())

/home/immerrr/sources/pandas/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    230             else:
    231                 mgr = self._init_ndarray(data, index, columns, dtype=dtype,
--> 232                                          copy=copy)
    233         elif isinstance(data, (list, types.GeneratorType)):
    234             if isinstance(data, types.GeneratorType):

/home/immerrr/sources/pandas/pandas/core/frame.py in _init_ndarray(self, values, index, columns, dtype, copy)
    334 
    335             # zero len case (GH #2234)
--> 336             if not len(values) and len(columns):
    337                 values = np.empty((0, 1), dtype=object)
    338 

TypeError: object of type 'NoneType' has no len()

Apparently, it's a regression from 0.12.0, because

In [1]: pd.__version__
Out[1]: '0.12.0'

In [2]: pd.DataFrame(pd.Series())
Out[2]: 
Empty DataFrame
Columns: [0]
Index: []

I'd guess that one of failing checks previously read if smth ..., but since implicit conversion to boolean for ndarrays are now forbidden, the check was replaced by len(smth), but I didn't dig into this.

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