Skip to content

BUG: fix 1xN mask on 1xN frame #4073

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 2 commits into from
Jun 28, 2013
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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ pandas 0.12
:issue:`4028`, :issue:`4054`)
- ``Series.hist`` will now take the figure from the current environment if
one is not passed
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)


pandas 0.11.0
=============
Expand Down
1 change: 1 addition & 0 deletions doc/source/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ Bug Fixes
:issue:`4028`, :issue:`4054`)
- ``Series.hist`` will now take the figure from the current environment if
one is not passed
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)

See the :ref:`full release notes
<release>` or issue tracker
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,10 @@ def func(c,v,o):
return make_block(result, self.items, self.ref_items)

# might need to separate out blocks
axis = cond.ndim-1
cond = cond.swapaxes(axis,0)
mask = np.array([ cond[i].all() for i in enumerate(range(cond.shape[0]))],dtype=bool)
axis = cond.ndim - 1
cond = cond.swapaxes(axis, 0)
mask = np.array([cond[i].all() for i in xrange(cond.shape[0])],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback any reason for using enumerate here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boy - guess was not thinking when I originally wrote that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still worked tho...strange since enumerate composed with range should yield a tuple thus accessing the diagonal of the mask (in this case)...seems like that would have broken things (in a more general way)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok if your fix worked grrat

dtype=bool)

result_blocks = []
for m in [mask, ~mask]:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7675,6 +7675,13 @@ def test_mask(self):
assert_frame_equal(rs, df.mask(df <= 0))
assert_frame_equal(rs, df.mask(~cond))

def test_mask_edge_case_1xN_frame(self):
# GH4071
df = DataFrame([[1, 2]])
res = df.mask(DataFrame([[True, False]]))
expec = DataFrame([[nan, 2]])
assert_frame_equal(res, expec)

#----------------------------------------------------------------------
# Transposing
def test_transpose(self):
Expand Down