Skip to content

BUG: fix DataFarame column slice indexer #6525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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