Skip to content

Commit 5abe1a2

Browse files
committed
Merge pull request #4073 from cpcloud/internals-mask-edge-case
BUG: fix 1xN mask on 1xN frame
2 parents 0875770 + 3bac181 commit 5abe1a2

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ pandas 0.12
293293
:issue:`4028`, :issue:`4054`)
294294
- ``Series.hist`` will now take the figure from the current environment if
295295
one is not passed
296+
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
297+
296298

297299
pandas 0.11.0
298300
=============

doc/source/v0.12.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ Bug Fixes
436436
:issue:`4028`, :issue:`4054`)
437437
- ``Series.hist`` will now take the figure from the current environment if
438438
one is not passed
439+
- Fixed bug where a 1xN DataFrame would barf on a 1xN mask (:issue:`4071`)
439440

440441
See the :ref:`full release notes
441442
<release>` or issue tracker

pandas/core/internals.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ def func(c,v,o):
575575
return make_block(result, self.items, self.ref_items)
576576

577577
# might need to separate out blocks
578-
axis = cond.ndim-1
579-
cond = cond.swapaxes(axis,0)
580-
mask = np.array([ cond[i].all() for i in enumerate(range(cond.shape[0]))],dtype=bool)
578+
axis = cond.ndim - 1
579+
cond = cond.swapaxes(axis, 0)
580+
mask = np.array([cond[i].all() for i in xrange(cond.shape[0])],
581+
dtype=bool)
581582

582583
result_blocks = []
583584
for m in [mask, ~mask]:

pandas/tests/test_frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -7695,6 +7695,13 @@ def test_mask(self):
76957695
assert_frame_equal(rs, df.mask(df <= 0))
76967696
assert_frame_equal(rs, df.mask(~cond))
76977697

7698+
def test_mask_edge_case_1xN_frame(self):
7699+
# GH4071
7700+
df = DataFrame([[1, 2]])
7701+
res = df.mask(DataFrame([[True, False]]))
7702+
expec = DataFrame([[nan, 2]])
7703+
assert_frame_equal(res, expec)
7704+
76987705
#----------------------------------------------------------------------
76997706
# Transposing
77007707
def test_transpose(self):

0 commit comments

Comments
 (0)