-
-
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
Conversation
tests we r on 0.18.2 |
Hi, I seem to have made the documentation in the wrong file. I will correct it and push the changes. Also, have I missed something? |
@jreback I have corrected the documentation to the proper version file. Is this everything? |
you need to add tests which fail before this patch and pass after |
Apart from the indispensable unit test, I'd propose to move the lines: if axis is not None:
axis = self._get_axis_number(axis) to right before the Thanks! |
Current coverage is 84.11% (diff: 100%)@@ master #13198 diff @@
==========================================
Files 138 138
Lines 50388 50388
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
Hits 42386 42386
Misses 8002 8002
Partials 0 0
|
@@ -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')) |
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.
add the issue number as a comment here
rename to test_align_broadcast_axis
@jreback Have made the required changes. |
|
||
# For 'inner' join | ||
result = df.align(ts, join='inner', axis=0, broadcast_axis=1) | ||
result1 = DataFrame(result[0]) |
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.
Not needed. Test returned obj (result[0]
and [1]
) as it is.
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.
@sinhrks I'm not sure that I understand. Can you please elaborate?
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.
Pls remove DataFrame(result..)
like below.
result = df.align(...)
expected1 = ...
expected2 = ...
assert_frame_equal(result[0], expected1)
assert_frame_equal(result[1], expected2)
Can u add tests with:
|
@sinhrks Sure. It's late night here right now. I will do this in the morning. |
@sinhrks I've made some changes. Please take a look and comment. This is what you meant right? |
@@ -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. 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`) |
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.
Single line of comments pls. these are read by the users and don't need this kind of explanation.
@jreback Done. Kindly check and comment. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
try one of these with broadcast_axis='columns'
and one with broadcast_axis='index'
as well
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.
left, right = df.align(....)
and same below
ts = Series([5., 6., 7.]) | ||
|
||
result = df.align(ts, join='right', axis=0, broadcast_axis=1) | ||
expected1 = DataFrame(np.array([[1., 2.], [3., 4.], |
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.
call these expected_left
and expected_right
(and same below)
While trying to run the above code, nosetests gives the error AssertionError: Series.index are different
However, upon running in the interpreter
We find that both indexes are same. |
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 comment
The 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.
result = df.align(series, ...)
self.assert_frame_equal(result[0], expected1)
self.assert_frame_equal(result[1], expected2)
result = series.align(df, ...)
self.assert_frame_equal(result[0], expected2)
self.assert_frame_equal(result[1], expected1)
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.
missed @jreback suggestion for variable names:
left, right = df.align(series, ...)
self.assert_frame_equal(left, expected_left)
self.assert_frame_equal(right, expected_right)
left, right = series.align(df, ...)
self.assert_frame_equal(right, expected_left)
self.assert_frame_equal(left, expected_right)
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.
@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 comment
The reason will be displayed to describe this comment to others. Learn more.
a single Ping is enough then you need to wait for comments
can you rebase / update? |
@jreback I'm not sure I understand. I have rebased my_branch with master. |
doesn't look like it |
@jreback
|
Sorry I closed my mistake |
got rebase origin/master |
got -> git |
you are rebasing to a local master which is not updated |
I followed the steps:
I removed the whitespace error and then synced the changes but still I am getting the same issue. |
closing, but if you want to update / rebase. pls reopen |
Closes #13194