From b4867df72de5978782ea4424e6fe2a07275cce81 Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 15:09:59 +0530 Subject: [PATCH 1/9] BUG: GH13194 fixed --- doc/source/whatsnew/v0.17.1.txt | 1 + pandas/core/generic.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index c25e0300a1050..545e3cee06d57 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -202,3 +202,4 @@ Bug Fixes - Bug in ``DataFrame.to_sparse()`` loses column names for MultiIndexes (:issue:`11600`) - Bug in ``DataFrame.round()`` with non-unique column index producing a Fatal Python error (:issue:`11611`) - Bug in ``DataFrame.round()`` with ``decimals`` being a non-unique indexed Series producing extra columns (:issue:`11618`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. (:issue:`13194`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6c80ab9d87e33..05a5497f76764 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4153,7 +4153,8 @@ def align(self, other, join='outer', axis=None, level=None, copy=True, # self cons = self._constructor_expanddim df = cons(dict((c, self) for c in other.columns), - **other._construct_axes_dict()) + **self._construct_axes_dict( + **other._construct_axes_dict(axes=['columns']))) return df._align_frame(other, join=join, axis=axis, level=level, copy=copy, fill_value=fill_value, method=method, @@ -4163,7 +4164,8 @@ def align(self, other, join='outer', axis=None, level=None, copy=True, # other cons = other._constructor_expanddim df = cons(dict((c, other) for c in self.columns), - **self._construct_axes_dict()) + **other._construct_axes_dict( + **self._construct_axes_dict(axes=['columns']))) return self._align_frame(df, join=join, axis=axis, level=level, copy=copy, fill_value=fill_value, method=method, limit=limit, From a4e6804decddb3a2414041f72dd8471e4d792fd7 Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 15:24:36 +0530 Subject: [PATCH 2/9] DOC : Change in release notes --- doc/source/whatsnew/v0.17.1.txt | 1 - doc/source/whatsnew/v0.18.2.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 545e3cee06d57..c25e0300a1050 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -202,4 +202,3 @@ Bug Fixes - Bug in ``DataFrame.to_sparse()`` loses column names for MultiIndexes (:issue:`11600`) - Bug in ``DataFrame.round()`` with non-unique column index producing a Fatal Python error (:issue:`11611`) - Bug in ``DataFrame.round()`` with ``decimals`` being a non-unique indexed Series producing extra columns (:issue:`11618`) -- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. (:issue:`13194`) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 459bdbf10a4f1..0499d1f11dccb 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -149,3 +149,4 @@ Bug Fixes - Bug in ``NaT`` - ``Period`` raises ``AttributeError`` (:issue:`13071`) - Bug in ``Period`` addition raises ``TypeError`` if ``Period`` is on right hand side (:issue:`13069`) - Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. (:issue:`13194`) From 51c5968e4ad349aa70601c3006f4cd9a771b802d Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 16:27:05 +0530 Subject: [PATCH 3/9] TST: Added tests for #13194 --- pandas/tests/test_generic.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index ba282f0107d71..a651dab5df8ab 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -1874,6 +1874,52 @@ def test_pipe_panel(self): with tm.assertRaises(ValueError): result = wp.pipe((f, 'y'), x=1, y=1) + def test_align_joins(self): + df = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) + ts = Series([5., 6., 7.]) + check = df.align(ts, join='outer', axis=0, broadcast_axis=1) + df1 = DataFrame(check[0]) + df2 = DataFrame(check[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + assert_frame_equal(df1, expected1) + assert_frame_equal(df2, expected2) + + check = df.align(ts, join='inner', axis=0, broadcast_axis=1) + df1 = DataFrame(check[0]) + df2 = DataFrame(check[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + assert_frame_equal(df1, expected1) + assert_frame_equal(df2, expected2) + + check = df.align(ts, join='left', axis=0, broadcast_axis=1) + df1 = DataFrame(check[0]) + df2 = DataFrame(check[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + assert_frame_equal(df1, expected1) + assert_frame_equal(df2, expected2) + + check = df.align(ts, join='right', axis=0, broadcast_axis=1) + df1 = DataFrame(check[0]) + df2 = DataFrame(check[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + assert_frame_equal(df1, expected1) + assert_frame_equal(df2, expected2) + + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) From e15e17ed7ff35f089316c259437ab2ca60b5ee4d Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 16:34:36 +0530 Subject: [PATCH 4/9] CLN: Changed location of axis check --- pandas/core/generic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 05a5497f76764..ae3d71f148a82 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4147,6 +4147,9 @@ def align(self, other, join='outer', axis=None, level=None, copy=True, from pandas import DataFrame, Series method = missing.clean_fill_method(method) + if axis is not None: + axis = self._get_axis_number(axis) + if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, Series): # this means other is a DataFrame, and we need to broadcast @@ -4171,8 +4174,6 @@ def align(self, other, join='outer', axis=None, level=None, copy=True, method=method, limit=limit, fill_axis=fill_axis) - if axis is not None: - axis = self._get_axis_number(axis) if isinstance(other, DataFrame): return self._align_frame(other, join=join, axis=axis, level=level, copy=copy, fill_value=fill_value, From e6ec1d9d45f351b55303524cd2642c41839c526c Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 20:14:08 +0530 Subject: [PATCH 5/9] TST : Renamed and changed the location of unittests. --- doc/source/whatsnew/v0.18.2.txt | 2 +- .../tests/frame/test_axis_select_reindex.py | 50 +++++++++++++++++++ pandas/tests/test_generic.py | 45 ----------------- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 0499d1f11dccb..afb5a8c282918 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -149,4 +149,4 @@ Bug Fixes - Bug in ``NaT`` - ``Period`` raises ``AttributeError`` (:issue:`13071`) - Bug in ``Period`` addition raises ``TypeError`` if ``Period`` is on right hand side (:issue:`13069`) - Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`) -- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. (:issue:`13194`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. Earlier, upon supplying value of join argument as any of the four('outer', 'inner', 'left', 'right' ), align() was giving erraneous output. The problem was identified to be in pandas/core/generic.py and has been subsequently fixed. (:issue:`13194`) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index 09dd0f3b14812..e83da01bc1700 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -880,3 +880,53 @@ def test_reindex_multi(self): expected = df.reindex([0, 1]).reindex(columns=['a', 'b']) assert_frame_equal(result, expected) + + def test_align_broadcast_axis(self): + # GH 13194 + # For 'outer' join + df = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) + ts = Series([5., 6., 7.]) + result = df.align(ts, join='outer', axis=0, broadcast_axis=1) + result1 = DataFrame(result[0]) + result2 = DataFrame(result[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + assert_frame_equal(result1, expected1) + assert_frame_equal(result2, expected2) + + # For 'inner' join + result = df.align(ts, join='inner', axis=0, broadcast_axis=1) + result1 = DataFrame(result[0]) + result2 = DataFrame(result[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + assert_frame_equal(result1, expected1) + assert_frame_equal(result2, expected2) + + # For 'left' join + result = df.align(ts, join='left', axis=0, broadcast_axis=1) + result1 = DataFrame(result[0]) + result2 = DataFrame(result[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + assert_frame_equal(result1, expected1) + assert_frame_equal(result2, expected2) + + # For 'right' join + result = df.align(ts, join='right', axis=0, broadcast_axis=1) + result1 = DataFrame(result[0]) + result2 = DataFrame(result[1]) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + assert_frame_equal(result1, expected1) + assert_frame_equal(result2, expected2) diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index a651dab5df8ab..004107fe4f783 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -1874,51 +1874,6 @@ def test_pipe_panel(self): with tm.assertRaises(ValueError): result = wp.pipe((f, 'y'), x=1, y=1) - def test_align_joins(self): - df = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) - ts = Series([5., 6., 7.]) - check = df.align(ts, join='outer', axis=0, broadcast_axis=1) - df1 = DataFrame(check[0]) - df2 = DataFrame(check[1]) - expected1 = DataFrame(np.array([[1., 2.], [3., 4.], - [pd.np.nan, pd.np.nan]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), - columns=list('AB')) - assert_frame_equal(df1, expected1) - assert_frame_equal(df2, expected2) - - check = df.align(ts, join='inner', axis=0, broadcast_axis=1) - df1 = DataFrame(check[0]) - df2 = DataFrame(check[1]) - expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), - columns=list('AB')) - assert_frame_equal(df1, expected1) - assert_frame_equal(df2, expected2) - - check = df.align(ts, join='left', axis=0, broadcast_axis=1) - df1 = DataFrame(check[0]) - df2 = DataFrame(check[1]) - expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), - columns=list('AB')) - assert_frame_equal(df1, expected1) - assert_frame_equal(df2, expected2) - - check = df.align(ts, join='right', axis=0, broadcast_axis=1) - df1 = DataFrame(check[0]) - df2 = DataFrame(check[1]) - expected1 = DataFrame(np.array([[1., 2.], [3., 4.], - [pd.np.nan, pd.np.nan]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), - columns=list('AB')) - assert_frame_equal(df1, expected1) - assert_frame_equal(df2, expected2) - if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], From 1b5bbde7cb01fdb910cc4beef3085d82bfb267fe Mon Sep 17 00:00:00 2001 From: Amol Date: Tue, 17 May 2016 20:30:22 +0530 Subject: [PATCH 6/9] DOC : improved the documentation in release notes --- doc/source/whatsnew/v0.18.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index afb5a8c282918..8e336a78cc801 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -149,4 +149,4 @@ Bug Fixes - Bug in ``NaT`` - ``Period`` raises ``AttributeError`` (:issue:`13071`) - Bug in ``Period`` addition raises ``TypeError`` if ``Period`` is on right hand side (:issue:`13069`) - Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`) -- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. Earlier, upon supplying value of join argument as any of the four('outer', 'inner', 'left', 'right' ), align() was giving erraneous output. The problem was identified to be in pandas/core/generic.py and has been subsequently fixed. (:issue:`13194`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. Earlier, upon supplying value of join argument as any of the four('outer', 'inner', 'left', 'right' ), align() was giving erraneous output. Align with broadcast_axis specified was using 'inner' join consistently irrespective of the value of 'join' provided when aligning dataframe and series on other axis. The problem was identified to be in pandas/core/generic.py and has been subsequently fixed. (:issue:`13194`) From fb1b41f2ba015aeaac85fefbbb5a2728570d8543 Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 20 May 2016 10:09:07 +0530 Subject: [PATCH 7/9] TST: Added and modified unittests --- .../tests/frame/test_axis_select_reindex.py | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index e83da01bc1700..959eda4e1a591 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -883,50 +883,63 @@ def test_reindex_multi(self): def test_align_broadcast_axis(self): # GH 13194 - # For 'outer' join + # First four tests for DataFrame.align(Index) + # For 'right' join df = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) ts = Series([5., 6., 7.]) - result = df.align(ts, join='outer', axis=0, broadcast_axis=1) - result1 = DataFrame(result[0]) - result2 = DataFrame(result[1]) + + result = df.align(ts, join='right', axis=0, broadcast_axis=1) expected1 = DataFrame(np.array([[1., 2.], [3., 4.], [pd.np.nan, pd.np.nan]]), columns=list('AB')) expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), columns=list('AB')) - assert_frame_equal(result1, expected1) - assert_frame_equal(result2, expected2) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) - # For 'inner' join - result = df.align(ts, join='inner', axis=0, broadcast_axis=1) - result1 = DataFrame(result[0]) - result2 = DataFrame(result[1]) + # For 'right' join on different index + result = df.align(ts, join='right', axis=1, broadcast_axis=1) expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) - expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), + expected2 = DataFrame(np.array([[5., 5.], [6., 6.], + [7., 7.]]), columns=list('AB')) - assert_frame_equal(result1, expected1) - assert_frame_equal(result2, expected2) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) # For 'left' join result = df.align(ts, join='left', axis=0, broadcast_axis=1) - result1 = DataFrame(result[0]) - result2 = DataFrame(result[1]) expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) expected2 = DataFrame(np.array([[5., 5.], [6., 6.]]), columns=list('AB')) - assert_frame_equal(result1, expected1) - assert_frame_equal(result2, expected2) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) - # For 'right' join - result = df.align(ts, join='right', axis=0, broadcast_axis=1) - result1 = DataFrame(result[0]) - result2 = DataFrame(result[1]) - expected1 = DataFrame(np.array([[1., 2.], [3., 4.], - [pd.np.nan, pd.np.nan]]), + # For 'left' join on different axis + result = df.align(ts, join='left', axis=1, broadcast_axis=1) + expected1 = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) expected2 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), columns=list('AB')) - assert_frame_equal(result1, expected1) - assert_frame_equal(result2, expected2) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) + + # Series.align(DataFrame) tests, 'outer' join + result = ts.align(df, join='outer', axis=0, broadcast_axis=1) + expected1 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) + + # Series.align(DataFrame) tests, 'inner' join + result = ts.align(df, join='inner', axis=0, broadcast_axis=1) + expected1 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + assert_frame_equal(result[0], expected1) + assert_frame_equal(result[1], expected2) From 248e8daf30fb4e60457395bc474f816ed68b7093 Mon Sep 17 00:00:00 2001 From: Amol Date: Fri, 20 May 2016 19:55:11 +0530 Subject: [PATCH 8/9] TST: Restructured and moved unittests --- doc/source/whatsnew/v0.18.2.txt | 2 +- .../tests/frame/test_axis_select_reindex.py | 19 --------------- pandas/tests/series/test_indexing.py | 23 +++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 8e336a78cc801..6a6940b87969e 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -149,4 +149,4 @@ Bug Fixes - Bug in ``NaT`` - ``Period`` raises ``AttributeError`` (:issue:`13071`) - Bug in ``Period`` addition raises ``TypeError`` if ``Period`` is on right hand side (:issue:`13069`) - Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`) -- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with the ``join`` argument. Earlier, upon supplying value of join argument as any of the four('outer', 'inner', 'left', 'right' ), align() was giving erraneous output. Align with broadcast_axis specified was using 'inner' join consistently irrespective of the value of 'join' provided when aligning dataframe and series on other axis. The problem was identified to be in pandas/core/generic.py and has been subsequently fixed. (:issue:`13194`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with broadcast_axis. (:issue:`13194`) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index 959eda4e1a591..b6132d7f20113 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -924,22 +924,3 @@ def test_align_broadcast_axis(self): columns=list('AB')) assert_frame_equal(result[0], expected1) assert_frame_equal(result[1], expected2) - - # Series.align(DataFrame) tests, 'outer' join - result = ts.align(df, join='outer', axis=0, broadcast_axis=1) - expected1 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[1., 2.], [3., 4.], - [pd.np.nan, pd.np.nan]]), - columns=list('AB')) - assert_frame_equal(result[0], expected1) - assert_frame_equal(result[1], expected2) - - # Series.align(DataFrame) tests, 'inner' join - result = ts.align(df, join='inner', axis=0, broadcast_axis=1) - expected1 = DataFrame(np.array([[5., 5.], [6., 6.]]), - columns=list('AB')) - expected2 = DataFrame(np.array([[1., 2.], [3., 4.]]), - columns=list('AB')) - assert_frame_equal(result[0], expected1) - assert_frame_equal(result[1], expected2) diff --git a/pandas/tests/series/test_indexing.py b/pandas/tests/series/test_indexing.py index 5ed3fda7d0b8f..410e3fa2a6b7c 100644 --- a/pandas/tests/series/test_indexing.py +++ b/pandas/tests/series/test_indexing.py @@ -1838,3 +1838,26 @@ def test_multilevel_preserve_name(self): result2 = s.ix['foo'] self.assertEqual(result.name, s.name) self.assertEqual(result2.name, s.name) + + def test_align_broadcast_axis_series(self): + # GH 13194 + # Series.align(DataFrame) tests, 'outer' join + df = DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB')) + ts = Series([5., 6., 7.]) + result = ts.align(df, join='outer', axis=0, broadcast_axis=1) + expected1 = DataFrame(np.array([[5., 5.], [6., 6.], [7., 7.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[1., 2.], [3., 4.], + [pd.np.nan, pd.np.nan]]), + columns=list('AB')) + self.assertTrue(result[0].equals(expected1)) + self.assertTrue(result[1].equals(expected2)) + + # Series.align(DataFrame) tests, 'inner' join + result = ts.align(df, join='inner', axis=0, broadcast_axis=1) + expected1 = DataFrame(np.array([[5., 5.], [6., 6.]]), + columns=list('AB')) + expected2 = DataFrame(np.array([[1., 2.], [3., 4.]]), + columns=list('AB')) + self.assertTrue(result[0].equals(expected1)) + self.assertTrue(result[1].equals(expected2)) From 6de9b0c0d19b7e4d18dc78d69dbfe71bda4cc65d Mon Sep 17 00:00:00 2001 From: Amol Date: Sun, 11 Sep 2016 18:58:24 +0530 Subject: [PATCH 9/9] Cleaned up doc --- doc/source/whatsnew/v0.18.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 6a6940b87969e..7a04e72a631dc 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -149,4 +149,4 @@ Bug Fixes - Bug in ``NaT`` - ``Period`` raises ``AttributeError`` (:issue:`13071`) - Bug in ``Period`` addition raises ``TypeError`` if ``Period`` is on right hand side (:issue:`13069`) - Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`) -- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with broadcast_axis. (:issue:`13194`) +- Fixed the bug in ``DataFrame.align()`` which was giving wrong output when supplied with broadcast_axis. (:issue:`13194`)