This should be a pretty straightforward followup on #9258 that will allow us to also support align with method='nearest'.

fillna internally relies on interpolate which already supports `method='nearest' so this may just work (it will needs lots of tests).

Comment From: tacaswell

:+1: on this.

Comment From: mgdadv

I'm not really sure how this is supposed to be implemented. It seems that the .interpolate() mechanism is capable of doing this already.

With the above patch:

import pandas as pd
import numpy as np

x=np.linspace(0,1,10)
y=np.sin(x)

y[[3,4,7]]=np.NaN

df=pd.DataFrame({'y':y}, index=x)

dfi=df.interpolate(method='nearest')
dfn=df.fillna(method='nearest')

dfi and dfn are now identical.

Is this the desired behavior? Shouldn't all the .interpolate() methods be supported by fillna? And why is the work from #9258 needed here?

Comment From: shoyer

@mgdadv Agreed, the work from #9258 is not needed here -- this is merely complementary. The functionality is indeed mostly implemented by interpolate already, so most of the work will just be hooking things up, testing and documentation. I was planning on tackling this myself, but if you'd like to take a crack at it, great!

The only reason for calling out nearest explicitly is that nearest indexing can be done with columns with any dtypes. method='linear' does not make sense, for example, if one of your columns consists of strings. This is actually more relevant for methods like align which rely on fillna internally. But I agree, we could probably support all of the interpolate methods in fillna (though that might be a bit of API overload).

Comment From: MarcoGorelli

Closing as there's been no activity in nearly a decade, if there's a need for this I presume someone will open a new issue