reindex_like(s, method='ffill') is different than reindex_like(s).fillna(method='ffill') · Issue #34547 · pandas-dev/pandas (original) (raw)

I don't know whether this a bug or a feature, but the behavior is not clear to me after reading the reindex_like docs.

There is a note "Please note: this is only applicable to DataFrames/Series with a monotonically increasing/decreasing index." - but what it actually does is to fill "as if" the index after reindexing was sorted.

>>> import pandas as pd
>>> s1 = pd.Series(['[0, 1)', '[1, 3)', '[3, 4)', '[4, 6)', '[6, inf)'], index=[0, 1, 3, 4, 6], dtype='string')
>>> s2 = pd.Series(['']*8, index=[6, 2, 5, 0, 4, 7, 1, 3], dtype='string')
>>>
>>> s1
0      [0, 1)
1      [1, 3)
3      [3, 4)
4      [4, 6)
6    [6, inf)
dtype: string
>>> s2
6    
2    
5    
0    
4    
7    
1    
3    
dtype: string
>>> s1.reindex_like(s2).fillna(method='ffill')
6    [6, inf)
2    [6, inf)
5    [6, inf)
0      [0, 1)
4      [4, 6)
7      [4, 6)
1      [1, 3)
3      [3, 4)
dtype: string
>>> s1.reindex_like(s2, method='ffill')
6    [6, inf)
2      [1, 3)
5      [4, 6)
0      [0, 1)
4      [4, 6)
7    [6, inf)
1      [1, 3)
3      [3, 4)
dtype: string

I expected the same result with both methods. Should they behave differently?