diff --git a/pandas/core/internals.py b/pandas/core/internals.py index fd998e5060b5f..f171915eeaccc 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -666,14 +666,24 @@ def convert(self, convert_dates = True, convert_numeric = True, copy = True): # attempt to create new type blocks blocks = [] - for i, c in enumerate(self.items): - values = self.get(c) - - values = com._possibly_convert_objects(values, convert_dates=convert_dates, convert_numeric=convert_numeric) - values = _block_shape(values) - items = self.items.take([i]) - newb = make_block(values, items, self.ref_items) - blocks.append(newb) + if self.items.is_unique: + for i,c in enumerate(self.items): + values = self.get(c) + + values = com._possibly_convert_objects(values, convert_dates=convert_dates, convert_numeric=convert_numeric) + values = _block_shape(values) + items = self.items.take([i]) + newb = make_block(values, items, self.ref_items) + blocks.append(newb) + else: + for i in range(len(self.items)): + values = self.values[i] + + values = com._possibly_convert_objects(values, convert_dates=convert_dates, convert_numeric=convert_numeric) + values = _block_shape(values) + items = self.items.take([i]) + newb = make_block(values, items, self.ref_items) + blocks.append(newb) return blocks diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 626592958147e..c3b2c39c803fe 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -7171,6 +7171,16 @@ def test_applymap(self): result = df.applymap(lambda x: x) self.assert_(result.dtypes[0] == object) + # GH2786 + + df = DataFrame(np.random.random((3,4))) + df.columns = Index(['a','a','a','a']) + res = df.applymap(str) + assert_series_equal(res.icol(0),Series(map(str,df.icol(0).values))) + assert_series_equal(res.icol(1),Series(map(str,df.icol(1).values))) + assert_series_equal(res.icol(2),Series(map(str,df.icol(2).values))) + assert_series_equal(res.icol(3),Series(map(str,df.icol(3).values))) + def test_filter(self): # items