Skip to content

Commit

Permalink
BUG: fix _ref_locs corruption when slice indexing across columns axis
Browse files Browse the repository at this point in the history
  • Loading branch information
immerrr committed Mar 3, 2014
1 parent 30d3cba commit a1a2cfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Bug Fixes
- Bug in ``read_html`` tests where redirected invalid URLs would make one test
fail (:issue:`6445`).
- Bug in multi-axis indexing using ``.loc`` on non-unique indices (:issue:`6504`)
- Bug that caused _ref_locs corruption when slice indexing across columns axis of a DataFrame (:issue:`6525`)

pandas 0.13.1
-------------
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def take_ref_locs(self, indexer):
tindexer[indexer] = False
tindexer = tindexer.astype(int).cumsum()[indexer]
ref_locs = ref_locs[indexer]

# Make sure the result is a copy, or otherwise self._ref_locs will be
# updated.
if ref_locs.base is not None:
ref_locs = ref_locs.copy()

ref_locs -= tindexer
return ref_locs

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12267,6 +12267,19 @@ def test_empty_frame_dtypes_ftypes(self):
('b', 'bool:dense'),
('c', 'float64:dense')])))

def test_dtypes_are_correct_after_column_slice(self):
# GH6525
df = pd.DataFrame(index=range(5), columns=list("abc"), dtype=np.float_)
odict = OrderedDict
assert_series_equal(df.dtypes,
pd.Series(odict([('a', np.float_), ('b', np.float_),
('c', np.float_),])))
assert_series_equal(df.iloc[:,2:].dtypes,
pd.Series(odict([('c', np.float_)])))
assert_series_equal(df.dtypes,
pd.Series(odict([('a', np.float_), ('b', np.float_),
('c', np.float_),])))


def skip_if_no_ne(engine='numexpr'):
if engine == 'numexpr':
Expand Down

0 comments on commit a1a2cfb

Please sign in to comment.