From 2ee1b3182fef45113246dc2f0fbcc6f8612d2038 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Fri, 28 Jun 2013 10:52:03 -0400 Subject: [PATCH 1/2] BUG: fix 1xN mask on 1xN frame --- doc/source/release.rst | 2 ++ doc/source/v0.12.0.txt | 1 + pandas/core/internals.py | 7 ++++--- pandas/tests/test_frame.py | 7 +++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 1edb44502221c..ae76324c0e848 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 ============= diff --git a/doc/source/v0.12.0.txt b/doc/source/v0.12.0.txt index 0d2251bf225d9..2a5847af4ed1d 100644 --- a/doc/source/v0.12.0.txt +++ b/doc/source/v0.12.0.txt @@ -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 ` or issue tracker diff --git a/pandas/core/internals.py b/pandas/core/internals.py index c2af6e395a7e5..60746197644a7 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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])], + dtype=bool) result_blocks = [] for m in [mask, ~mask]: diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 7dacacd8ad1fd..3a5eb7c01eec8 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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(np.array([[True, False]])) + expec = DataFrame([[nan, 2]]) + assert_frame_equal(res, expec) + #---------------------------------------------------------------------- # Transposing def test_transpose(self): From 3bac1816bac4be72ef2be7ab305eaea081604c2f Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Fri, 28 Jun 2013 10:56:57 -0400 Subject: [PATCH 2/2] TST: use DataFrame in the test --- pandas/tests/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 3a5eb7c01eec8..7884a36fa5747 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -7678,7 +7678,7 @@ def test_mask(self): def test_mask_edge_case_1xN_frame(self): # GH4071 df = DataFrame([[1, 2]]) - res = df.mask(np.array([[True, False]])) + res = df.mask(DataFrame([[True, False]])) expec = DataFrame([[nan, 2]]) assert_frame_equal(res, expec)