Skip to content

align with broadcast_axis specified always uses inner join when aligning dataframe and series on other axis. #13194

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

Open
kdebrab opened this issue May 16, 2016 · 3 comments
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@kdebrab
Copy link
Contributor

kdebrab commented May 16, 2016

Pandas version 0.18.1:

In[1]: import pandas as pd
In[2]: df = pd.DataFrame(np.array([[1., 2.], [3., 4.]]), columns=list('AB'))
In[3]: ts = pd.Series([5., 6., 7.])
In[4]: df.align(ts, join='outer', axis=0, broadcast_axis=1)
Out[4]: 
(     A    B
 0  1.0  2.0
 1  3.0  4.0,      A    B
 0  5.0  5.0
 1  6.0  6.0)

However, as 'join' is specified to be 'outer', I would have expected the following result:

Out[4]: 
(     A    B
 0  1.0  2.0
 1  3.0  4.0
 2  NaN  NaN,      A    B
 0  5.0  5.0
 1  6.0  6.0
 2  7.0  7.0
 dtype: float64)

Same problem occurs for:

df.align(ts, join='right', axis=0, broadcast_axis=1)
ts.align(df, join='outer', axis=0, broadcast_axis=1)
ts.align(df, join='left', axis=0, broadcast_axis=1)
@jreback
Copy link
Contributor

jreback commented May 16, 2016

yeah this has very little testing. I'll mark it as a bug; seems like an easy fix if you'd like to take a crack at it.

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Difficulty Intermediate labels May 16, 2016
@jreback jreback added this to the Next Major Release milestone May 16, 2016
@kdebrab
Copy link
Contributor Author

kdebrab commented May 16, 2016

The easy fix seems to replace in generic.py:
**other._construct_axes_dict() by **self._construct_axes_dict(**other._construct_axes_dict(axes=['columns']))
and
**self._construct_axes_dict() by **other._construct_axes_dict(**self._construct_axes_dict(axes=['columns']))

However, looking at the code I see another issue: though the documentation mentions as possible values for broadcast_axis: {0, 1, ‘index’, ‘columns’}, in reality only broadcast_axis == 1 has been implemented!

Unfortunately, I don't have the time now to implement that myself. I hope someone else will take this up...

@pfrcks
Copy link
Contributor

pfrcks commented May 17, 2016

Hi @jreback @kdebrab I would like to work on this as my first fix if that's not a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
5 participants