Skip to content

Commit c34d634

Browse files
committed
BUG: construction of DataFrame from empty Series regression (GH5756)
1 parent b319d24 commit c34d634

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/source/release.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ API Changes
247247
(:issue:`4390`)
248248
- allow ``ix/loc`` for Series/DataFrame/Panel to set on any axis even when
249249
the single-key is not currently contained in the index for that axis
250-
(:issue:`2578`, :issue:`5226`, :issue:`5632`, :issue:`5720`, :issue:`5744`)
250+
(:issue:`2578`, :issue:`5226`, :issue:`5632`, :issue:`5720`,
251+
:issue:`5744`, :issue:`5756`)
251252
- Default export for ``to_clipboard`` is now csv with a sep of `\t` for
252253
compat (:issue:`3368`)
253254
- ``at`` now will enlarge the object inplace (and return the same)

pandas/core/frame.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,16 @@ def _init_dict(self, data, index, columns, dtype=None):
325325
def _init_ndarray(self, values, index, columns, dtype=None,
326326
copy=False):
327327
if isinstance(values, Series):
328-
if columns is None and values.name is not None:
329-
columns = [values.name]
328+
if columns is None:
329+
if values.name is not None:
330+
columns = [values.name]
330331
if index is None:
331332
index = values.index
332333
else:
333334
values = values.reindex(index)
334335

335336
# zero len case (GH #2234)
336-
if not len(values) and len(columns):
337+
if not len(values) and columns is not None and len(columns):
337338
values = np.empty((0, 1), dtype=object)
338339

339340
values = _prep_ndarray(values, copy=copy)

pandas/tests/test_indexing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,14 @@ def f():
17931793
expected = DataFrame(columns=['A','B','C'])
17941794
assert_frame_equal(result,expected)
17951795

1796+
# GH 5756
1797+
# setting with empty Series
1798+
df = DataFrame(Series())
1799+
assert_frame_equal(df, DataFrame({ 0 : Series() }))
1800+
1801+
df = DataFrame(Series(name='foo'))
1802+
assert_frame_equal(df, DataFrame({ 'foo' : Series() }))
1803+
17961804
def test_cache_updating(self):
17971805
# GH 4939, make sure to update the cache on setitem
17981806

0 commit comments

Comments
 (0)