Skip to content

Commit

Permalink
BUG: issue constructing DataFrame from empty Series with name. close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Nov 14, 2012
1 parent 20529df commit 60e69a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pandas 0.9.1
- Fix icol with integer sequence failure (#2228)
- Fixed resampling tz-aware time series issue (#2245)
- SparseDataFrame.icol was not returning SparseSeries (#2227, #2229)
- Enable ExcelWriter to handle PeriodIndex (#2240)
- Fix issue constructing DataFrame from empty Series with name (#2234)
pandas 0.9.0
============
Expand Down
9 changes: 4 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5091,6 +5091,9 @@ def extract_index(data):

def _prep_ndarray(values, copy=True):
if not isinstance(values, np.ndarray):
if len(values) == 0:
return np.empty((0, 0), dtype=object)

arr = np.asarray(values)
# NumPy strings are a pain, convert to object
if issubclass(arr.dtype.type, basestring):
Expand All @@ -5103,11 +5106,7 @@ def _prep_ndarray(values, copy=True):
values = values.copy()

if values.ndim == 1:
N = values.shape[0]
if N == 0:
values = values.reshape((values.shape[0], 0))
else:
values = values.reshape((values.shape[0], 1))
values = values.reshape((values.shape[0], 1))
elif values.ndim != 2:
raise Exception('Must pass 2-d input')

Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2269,11 +2269,16 @@ def test_constructor_orient(self):
assert_frame_equal(recons, expected)

def test_constructor_Series_named(self):
a = Series([1,2,3], index=['a','b','c'], name='x')
a = Series([1, 2, 3], index=['a', 'b', 'c'], name='x')
df = DataFrame(a)
self.assert_(df.columns[0] == 'x')
self.assert_(df.index.equals(a.index))

# #2234
a = Series([], name='x')
df = DataFrame(a)
self.assert_(df.columns[0] == 'x')

def test_constructor_Series_differently_indexed(self):
# name
s1 = Series([1, 2, 3], index=['a','b','c'], name='x')
Expand Down

0 comments on commit 60e69a3

Please sign in to comment.