Skip to content

Panel.fillna with method='ffill' ignores the axis parameter and only fills along axis=1 #8251

Closed
@0zeroth

Description

@0zeroth

This is also a documentation error, as the docs say the default axis is axis = 0

import pandas as pd
from pandas.util.testing import makePanel

#
# Demo A: We want to fill along axis 0
# 
p = makePanel().transpose(1,0,2)
p.iloc[10:20,0,0] = np.nan

# Demonstrate we have a gap
p.iloc[:,0,0].plot()

# Demonstrate that nothing seems to fill the gap
p.fillna(method='ffill').iloc[:,0,0].plot()
p.fillna(method='ffill', axis=0).iloc[:,0,0].plot()
p.fillna(method='ffill', axis=1).iloc[:,0,0].plot()
p.fillna(method='ffill', axis=2).iloc[:,0,0].plot()

# At least one of the above should be the same as:
p.apply(lambda series: series.fillna(method='ffill'), axis=0).iloc[:,0,0].plot()

#
# Demo B: We want to fill along axis 1
#
p = makePanel()
p.iloc[0, 10:20,0] = np.nan

# Demonstrate we have a gap
p.iloc[0,:,0].plot()

# Demonstrate the gap is filled regardless of the axis
p.fillna(method='ffill').iloc[0,:,0].plot()
p.fillna(method='ffill', axis=0).iloc[0,:,0].plot()
p.fillna(method='ffill', axis=1).iloc[0,:,0].plot()
p.fillna(method='ffill', axis=2).iloc[0,:,0].plot()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions