-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: align with broadcast_axis, #13194 #13198
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
Changes from 8 commits
b4867df
a4e6804
51c5968
e15e17e
e6ec1d9
1b5bbde
fb1b41f
248e8da
6de9b0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -880,3 +880,47 @@ 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 | ||
# 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='right', axis=0, broadcast_axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try one of these with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
expected1 = DataFrame(np.array([[1., 2.], [3., 4.], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call these |
||
[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(result[0], expected1) | ||
assert_frame_equal(result[1], expected2) | ||
|
||
# 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.]]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to pass these as numpy arrays, just list-of-lists is fine |
||
columns=list('AB')) | ||
expected2 = DataFrame(np.array([[5., 5.], [6., 6.], | ||
[7., 7.]]), | ||
columns=list('AB')) | ||
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) | ||
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(result[0], expected1) | ||
assert_frame_equal(result[1], expected2) | ||
|
||
# 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(result[0], expected1) | ||
assert_frame_equal(result[1], expected2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same name scheme here |
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.assertTrue(result[1].equals(expected2)) | ||
|
||
# Series.align(DataFrame) tests, 'inner' join | ||
result = ts.align(df, join='inner', axis=0, broadcast_axis=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can make all tests more comprehensive as "inner" and "outer" outputs the same, and "left" and "right" outputs inversed results.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed @jreback suggestion for variable names:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback Can you please look into the issue I have reported above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a single Ping is enough then you need to wait for comments |
||
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug in
use double-backticks around
broadcast_axis
.say
incorrect output
(not wrong output)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
say that this was not taking into account the
how
parameter whenbroadcast_axis
was passed