Skip to content

Commit 60e69a3

Browse files
committed
BUG: issue constructing DataFrame from empty Series with name. close #2234
1 parent 20529df commit 60e69a3

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ pandas 0.9.1
106106
- Fix icol with integer sequence failure (#2228)
107107
- Fixed resampling tz-aware time series issue (#2245)
108108
- SparseDataFrame.icol was not returning SparseSeries (#2227, #2229)
109+
- Enable ExcelWriter to handle PeriodIndex (#2240)
110+
- Fix issue constructing DataFrame from empty Series with name (#2234)
109111
110112
pandas 0.9.0
111113
============

pandas/core/frame.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,9 @@ def extract_index(data):
50915091

50925092
def _prep_ndarray(values, copy=True):
50935093
if not isinstance(values, np.ndarray):
5094+
if len(values) == 0:
5095+
return np.empty((0, 0), dtype=object)
5096+
50945097
arr = np.asarray(values)
50955098
# NumPy strings are a pain, convert to object
50965099
if issubclass(arr.dtype.type, basestring):
@@ -5103,11 +5106,7 @@ def _prep_ndarray(values, copy=True):
51035106
values = values.copy()
51045107

51055108
if values.ndim == 1:
5106-
N = values.shape[0]
5107-
if N == 0:
5108-
values = values.reshape((values.shape[0], 0))
5109-
else:
5110-
values = values.reshape((values.shape[0], 1))
5109+
values = values.reshape((values.shape[0], 1))
51115110
elif values.ndim != 2:
51125111
raise Exception('Must pass 2-d input')
51135112

pandas/tests/test_frame.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -2269,11 +2269,16 @@ def test_constructor_orient(self):
22692269
assert_frame_equal(recons, expected)
22702270

22712271
def test_constructor_Series_named(self):
2272-
a = Series([1,2,3], index=['a','b','c'], name='x')
2272+
a = Series([1, 2, 3], index=['a', 'b', 'c'], name='x')
22732273
df = DataFrame(a)
22742274
self.assert_(df.columns[0] == 'x')
22752275
self.assert_(df.index.equals(a.index))
22762276

2277+
# #2234
2278+
a = Series([], name='x')
2279+
df = DataFrame(a)
2280+
self.assert_(df.columns[0] == 'x')
2281+
22772282
def test_constructor_Series_differently_indexed(self):
22782283
# name
22792284
s1 = Series([1, 2, 3], index=['a','b','c'], name='x')

0 commit comments

Comments
 (0)