Skip to content

Commit

Permalink
Merge pull request #3058 from dieterv77/FixGH2972
Browse files Browse the repository at this point in the history
BUG: Handle concat of series with same name, GH2972
  • Loading branch information
dieterv77 committed Mar 16, 2013
2 parents 2d69034 + 57660e8 commit 828f9f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pandas/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,10 @@ def get_result(self):
name = com._consensus_name_attr(self.objs)
return Series(new_data, index=self.new_axes[0], name=name)
elif self._is_series:
data = dict(zip(self.new_axes[1], self.objs))
return DataFrame(data, index=self.new_axes[0],
columns=self.new_axes[1])
data = dict(itertools.izip(xrange(len(self.objs)), self.objs))
tmpdf = DataFrame(data, index=self.new_axes[0])
tmpdf.columns = self.new_axes[1]
return tmpdf
else:
new_data = self._get_concatenated_data()
return self.objs[0]._from_axes(new_data, self.new_axes)
Expand Down
10 changes: 10 additions & 0 deletions pandas/tools/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,16 @@ def test_concat_bug_1719(self):

self.assertEqual(len(left), len(right))

def test_concat_bug_2972(self):
ts0 = Series(np.zeros(5))
ts1 = Series(np.ones(5))
ts0.name = ts1.name = 'same name'
result = concat([ts0, ts1], axis=1)

expected = DataFrame({0: ts0, 1: ts1})
expected.columns=['same name', 'same name']
assert_frame_equal(result, expected)


class TestOrderedMerge(unittest.TestCase):

Expand Down

0 comments on commit 828f9f9

Please sign in to comment.