Skip to content

DataFrame.where does not respect axis parameter for n x n frames #9736

Closed
@evanpw

Description

@evanpw
In [3]: df = pd.DataFrame(np.random.randn(5, 5))

In [4]: s = pd.Series(range(5))

In [5]: df.where(df.isnull(), s, axis=0)
Out[5]:
   0  1  2  3  4
0  0  1  2  3  4
1  0  1  2  3  4
2  0  1  2  3  4
3  0  1  2  3  4
4  0  1  2  3  4

In [6]: df.where(df.isnull(), s, axis=1)
Out[6]:
   0  1  2  3  4
0  0  1  2  3  4
1  0  1  2  3  4
2  0  1  2  3  4
3  0  1  2  3  4
4  0  1  2  3  4

The right axis is used when aligning indices, but it's not used when broadcasting the aligned Series. You also get the right result if the DataFrame is not square, because core.internals.where will transpose if necessary to the get the dimensions to fit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions