Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.24.0 DateTimeIndex: union() got an unexpected keyword argument 'sort' #24994

Closed
bilalkamoon opened this issue Jan 29, 2019 · 2 comments · Fixed by #25110
Closed

0.24.0 DateTimeIndex: union() got an unexpected keyword argument 'sort' #24994

bilalkamoon opened this issue Jan 29, 2019 · 2 comments · Fixed by #25110
Labels
Datetime Datetime data dtype Timedelta Timedelta data type
Milestone

Comments

@bilalkamoon
Copy link

bilalkamoon commented Jan 29, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
index1 = pd.DataFrame(index=pd.to_datetime(['19900101'])).index
index2 = index1.copy()
index1.union(index2, sort=False)
TypeError: union() got an unexpected keyword argument 'sort'

Problem description

The 'sort' argument works with 'difference' and 'intersection' but fails on 'union' for DateTimeIndex.

@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jan 29, 2019
@TomAugspurger TomAugspurger added Datetime Datetime data dtype Timedelta Timedelta data type labels Jan 29, 2019
@TomAugspurger
Copy link
Contributor

xref #24966 (that's for intersection, just TimedeltaIndex).

cc @reidy-p.

@reidy-p
Copy link
Contributor

reidy-p commented Jan 29, 2019

@TomAugspurger thanks.

This is just not implemented yet for DatetimeIndex. I have started work on implementing this for DatetimeIndex.union and it is quite straightforward except in the case where this._fast_union(other) is called:

if len(other) == 0 or self.equals(other) or len(self) == 0:
return super(DatetimeIndex, self).union(other)
if not isinstance(other, DatetimeIndex):
try:
other = DatetimeIndex(other)
except TypeError:
pass
this, other = self._maybe_utc_convert(other)
if this._can_fast_union(other):
return this._fast_union(other)
else:
result = Index.union(this, other)
if isinstance(result, DatetimeIndex):
# TODO: we shouldn't be setting attributes like this;
# in all the tests this equality already holds
result._data._dtype = this.dtype
if (result.freq is None and
(this.freq is not None or other.freq is not None)):
result.freq = to_offset(result.inferred_freq)
return result

I'm still trying to figure out whether we can do the sorting inside of _fast_union.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants