BUG: align with broadcast_axis, #13194
State: closed

Closes #13194 
- Implemented the _easy fix_
- Future work : To implement broadcast axis remaining functionality.
- All tests in test_generic.py passed.


Labels:
name: Bug
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode

Comments:
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.
Rest all is OK, right?
This is my first pull request to pandas, sorry for the noob errors.

Also, have I missed something?

@jreback I have corrected the documentation to the proper version file. Is this everything?
I have ran the tests also.
Am I missing something?

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](https://github.com/pydata/pandas/blob/master/pandas/core/generic.py#L4172):

``` python
if axis is not None:
    axis = self._get_axis_number(axis)
```

to right before the `if broadcast_axis == 1` block, such that broadcasting will work (correctly) also in case align is called with `axis='index'` instead of `axis=0`.

Thanks!

## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/13198?src=pr) is 84.11% (diff: 100%)

> Merging [#13198](https://codecov.io/gh/pydata/pandas/pull/13198?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will not change coverage

``` diff
@@             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          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [4e4a7d9...1b5bbde](https://codecov.io/gh/pydata/pandas/compare/4e4a7d9ae5b3c05b21dc0a0f3c12648236ec586e...1b5bbde7cb01fdb910cc4beef3085d82bfb267fe?src=pr)

@jreback @kdebrab I've included the unit test and have also moved the location of the axis check.
Can you please take a look?

@jreback Have made the required changes. 
Please comment if something's lacking. 

Can u add tests with:
- alternately different `Index` to clheck left and right join.
- `Series.align(DataFrame)`

@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?

@jreback Done. Kindly check and comment.

@jreback 

```
    right = df.align(ts, join='right', axis=1, broadcast_axis='index')
    expected1_right = DataFrame([[pd.np.nan, pd.np.nan, pd.np.nan],
                                 [pd.np.nan, pd.np.nan, pd.np,nan]],
                                columns=[0, 1, 2])
    expected2_right = Series([5., 6., 7.])
    assert_frame_equal(right[0], expected1_right)
    assert_series_equal(right[1], expected2_right)  
```

While trying to run the above code, nosetests gives the error 

AssertionError: Series.index are different

```
    Series.index classes are not equivalent
    [left]:  Index([u'A', u'B'], dtype='object')
    [right]: RangeIndex(start=0, stop=2, step=1)
```

However, upon running in the interpreter

> > > right = df.align(ts, join='right', axis=1, broadcast_axis='index')
> > > right[1]
> > > 0    5.0
> > > 1    6.0
> > > 2    7.0
> > > dtype: float64
> > > right[1].index
> > > RangeIndex(start=0, stop=3, step=1)
> > > expected2_right = Series([5., 6., 7.])
> > > expected2_right.index
> > > RangeIndex(start=0, stop=3, step=1)

We find that both indexes are same.
I am currently in pandas_dev environment.
Is this something assert_series_frame is doing?

can you rebase / update?

@jreback I'm not sure I understand. I have rebased my_branch with master.

doesn't look like it
you need to push 

@jreback 
I have used the following commands:

`git checkout my_branch`
`git rebase master`
`git push -u origin my_branch`

Sorry I closed my mistake

got rebase origin/master

got -> git

you are rebasing to a local master which is not updated 

@jreback 

I followed the steps:

1) `git remote add ups https://github.com/pydata/pandas.git`
2) `git fetch ups`
3) `git checkout master`
4) `git rebase ups/master`

> First, rewinding head to replay your work on top of it...
> Applying: BUG: GH13194 fixed
> Applying: DOC : Change in release notes
> Using index info to reconstruct a base tree...
> A   doc/source/whatsnew/v0.18.2.txt
> <stdin>:19: trailing whitespace.
> - Fixed the bug in `DataFrame.align()` which was giving wrong output when supplied with the `join` argument. (:issue:`13194`) 
>   warning: 1 line adds whitespace errors.
>   Falling back to patching base and 3-way merge...
>   CONFLICT (modify/delete): doc/source/whatsnew/v0.18.2.txt deleted in HEAD and modified in DOC : Change in release notes. Version DOC : Change in release notes of doc/source/whatsnew/v0.18.2.txt left in tree.
>   Failed to merge in the changes.
>   Patch failed at 0002 DOC : Change in release notes
>   The copy of the patch that failed is found in:
>   /home/pfrcks/issues/pandas-pfrcks/.git/rebase-apply/patch
>   When you have resolved this problem, run "git rebase --continue".
>   If you prefer to skip this patch, run "git rebase --skip" instead.
>   To check out the original branch and stop rebasing, run "git rebase --abort".

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