Index.intersection changed behavior to sort by default in pandas 0.24 · Issue #24959 · pandas-dev/pandas (original) (raw)
Prior to #24521 (i.e., for pandas 0.23 and earlier), pandas.Index.intersection would not sort values:
# pandas 0.23.3
In [21]: pd.Index(['c', 'b', 'a']).intersection(['b', 'a'])
Out[21]: Index(['b', 'a'], dtype='object')
Now it does:
In [28]: pd.Index(['c', 'b', 'a']).intersection(['b', 'a'])
Out[28]: Index(['a', 'b'], dtype='object')
This turned up in a failure in xarray's test suite (not a real bug): pydata/xarray#2717
It's fine to change this for consistency, but a deprecation cycle would probably make sense so users aren't surprised by the behavior of their code changing, e.g., we could default to sort=None
and issue a FutureWarning for now.