Skip to content

Union of index with itself not invariant, sets frequency attribute #11086

Closed
@multiloc

Description

@multiloc

When creating the union of an index with itself, the frequency may end up being reset. I would have expected the call to union in the following example to be invariant and return the original index:

In [56]: index = pd.bdate_range('20150101', periods=10)
In [57]: index.freq = None
In [58]: index
Out[58]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2015-01-01, ..., 2015-01-14]
Length: 10, Freq: None, Timezone: None

In [59]: index.union(index)
Out[59]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2015-01-01, ..., 2015-01-14]
Length: 10, Freq: B, Timezone: None

This then propagates through to e.g. combine_first, which is also not invariant. This might be desirable behavior in some cases but definitely surprising imo.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions