Skip to content

Commit 25d522c

Browse files
committed
BUG: fix DataFrame.icol with list of integers when columns are integers with duplicates. close #2259
1 parent b60f0c4 commit 25d522c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pandas 0.10.0
233233
- DataFrame.to_string formatters can be list, too (GH2520_)
234234
- DataFrame.combine_first will always result in the union of the index and
235235
columns, even if one DataFrame is length-zero (GH2525_)
236+
- Fix several DataFrame.icol/irow with duplicate indices issues (GH2228_, GH2259_)
236237

237238
.. _GH407: https://github.com/pydata/pandas/issues/407
238239
.. _GH821: https://github.com/pydata/pandas/issues/821
@@ -348,6 +349,8 @@ pandas 0.10.0
348349
.. _GH2488: https://github.com/pydata/pandas/issues/2488
349350
.. _GH2520: https://github.com/pydata/pandas/issues/2520
350351
.. _GH2525: https://github.com/pydata/pandas/issues/2525
352+
.. _GH2228: https://github.com/pydata/pandas/issues/2228
353+
.. _GH2259: https://github.com/pydata/pandas/issues/2259
351354

352355

353356
pandas 0.9.1

pandas/core/frame.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,7 @@ def icol(self, i):
18751875
else:
18761876
label = self.columns[i]
18771877
if isinstance(label, Index):
1878-
if self.columns.inferred_type == 'integer':
1879-
# XXX re: #2228
1880-
return self.reindex(columns=label)
1881-
else:
1882-
return self.ix[:, i]
1878+
return self.take(i, axis=1)
18831879

18841880
values = self._data.iget(i)
18851881
return self._col_klass.from_array(values, index=self.index,

pandas/tests/test_frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,12 @@ def test_irow_icol_duplicates(self):
13341334
xp = df.ix[:, [0]]
13351335
assert_frame_equal(rs, xp)
13361336

1337+
# #2259
1338+
df = DataFrame([[1,2,3],[4,5,6]], columns=[1,1,2])
1339+
result = df.icol([0])
1340+
expected = df.take([0], axis=1)
1341+
assert_frame_equal(result, expected)
1342+
13371343
def test_icol_sparse_propegate_fill_value(self):
13381344
from pandas.sparse.api import SparseDataFrame
13391345
df=SparseDataFrame({'A' : [999,1]},default_fill_value=999)

0 commit comments

Comments
 (0)