-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Why is pd.Index.union not commutative? #23525
Comments
cc @jreback |
we don't ignore empties. actually these should all convert to object dtype (and work). |
Agreed. |
@jreback - just to clarify - are you suggesting that:
>>> pd.Index([]).union(pd.period_range('19910905', periods=2))
Current: PeriodIndex(['1991-09-05', '1991-09-06'], dtype='period[D]', freq='D')
Desired: Index([1991-09-05, 1991-09-06], dtype='object')
>>> pd.Index([]).union(pd.interval_range(start=0, end=5))
Current: IntervalIndex([(0, 1], (1, 2]]
closed='right',
dtype='interval[int64]')
Desired: Index([(0, 1], (1, 2]], dtype='object')
>>> pd.period_range('19910905', periods=2).union(pd.Index([1,2,3]))
Current: ValueError
Desired: Index([1991-09-05, 1991-09-06, 1, 2, 3], dtype='object') 2b) And should this only be the case for which the |
yes to both |
Thoughts on 2b? |
no like indexes are combined to form the same type it’s likely that the coercion logic is not fully handling things we should not have any special cases - these are general ops |
@jreback - how should the union of Int64Index and RangeIndex behave ideally? Should they also result in an object dtype or behave the same as they do now? |
RangeIndex should always be just an optimization of Int64Index. So you
would return a RangeIndex if possible, else an Int64Index.
…On Thu, Nov 8, 2018 at 9:03 PM ArtinSarraf ***@***.***> wrote:
@jreback <https://github.com/jreback> - how should the union of
Int64Index and RangeIndex behave ideally? Should they also result in an
object dtype or behave the same as they do now?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#23525 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIu9_YxMmMlL0xNVPSc523ZESwKX1ks5utPCKgaJpZM4YPp62>
.
|
Code Sample, a copy-pastable example if possible
Problem description
Conceptually I would imagine a union operation to be commutative. I was just wondering if there was an deliberate rationale behind not implementing pd.Index._assert_can_do_setop to only fail if the complementary self._assert_can_do_setop also fails.
This behavior also leads to some unexpected behaviors in
pd.concat
. For example:Additionally (and perhaps this should be raised as a separate issue) should the specific implementation of
pd.PeriodIndex._assert_can_do_setop
not raise if theother
index is empty? Sincepd.Index([]).union(<instance of pd.PeriodIndex>)
results in an instance ofpd.PeriodIndex
.The text was updated successfully, but these errors were encountered: