Skip to content

Commit 2ee1b31

Browse files
committed
BUG: fix 1xN mask on 1xN frame
1 parent 99acda4 commit 2ee1b31

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7675,6 +7675,13 @@ def test_mask(self):
76757675
assert_frame_equal(rs, df.mask(df <= 0))
76767676
assert_frame_equal(rs, df.mask(~cond))
76777677

7678+
def test_mask_edge_case_1xN_frame(self):
7679+
# GH4071
7680+
df = DataFrame([[1, 2]])
7681+
res = df.mask(np.array([[True, False]]))
7682+
expec = DataFrame([[nan, 2]])
7683+
assert_frame_equal(res, expec)
7684+
76787685
#----------------------------------------------------------------------
76797686
# Transposing
76807687
def test_transpose(self):

0 commit comments

Comments
 (0)