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

BUG: Index.union cannot handle array-likes #10157

Merged
merged 1 commit into from
Jun 1, 2015

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented May 16, 2015

Closes #10149.

  • Added explicit tests for array-likes in set-ops, intersection, union, difference and sym_diff.
    • TimedeltaIndex previously did additional input check which is inconsistent with others. Made it work as the same manner as others.
    • MultiIndex set-ops should only accept list-likes of tuples. Implement the logic and add explicit test.
  • Changed to understandable error message for str which has __iter__ in py3.
# current error msg
idx.intersection('aaa')
# TypeError: Index(...) must be called with a collection of some kind, 'aaa' was passed

NOTE: This DOESN'T care the name attribute checks, which is being worked in #9965.

@sinhrks sinhrks added the Bug label May 16, 2015
@sinhrks sinhrks added this to the 0.17.0 milestone May 16, 2015
self.assertTrue(tm.equalContents(intersect, second))

# GH 10149
cases = [klass(second.values) for klass in [np.array, Series, list]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move these to Base (so that they get tested for all types)?

@jreback
Copy link
Contributor

jreback commented May 20, 2015

rebase / address comments when you have a chance

@sinhrks
Copy link
Member Author

sinhrks commented May 20, 2015

Rebased. I've added tests to Base, but it cannot work in all Index currently. I'll prepare separate issue about CategoricalIndex and TimedeltaIndex set ops behavior.

What I'd like to confirm here is MultiIndex should accept list-likes of something? Currently, it raises error not understandable for users as below.

>>> midx = pd.MultiIndex.from_tuples([(1, 2), (3, 4)])
>>> midx
MultiIndex(levels=[[1, 3], [2, 4]],
           labels=[[0, 1], [0, 1]])
>>> midx.intersection([(1, 2)])
AttributeError: 'list' object has no attribute 'names'

@sinhrks
Copy link
Member Author

sinhrks commented May 20, 2015

Let me update TimedeltaIndex behavior here (because simple than I initially thought). On current master, DatetimeIndex.union performs additional check and it causes an error. Removed this check in and made it consistent with others in this PR.

idx1 = pd.timedelta_range('1 day', freq='D', periods=5)
idx2 = pd.timedelta_range('3 day', freq='D', periods=5)

idx1.intersection(idx2.asobject.tolist())
# TimedeltaIndex(['3 days', '4 days', '5 days'], dtype='timedelta64[ns]', freq=None)

idx1.union(idx2.asobject.tolist())
# AttributeError: 'list' object has no attribute 'inferred_type'

idx1.difference(idx2.asobject.tolist())
# TimedeltaIndex(['1 days', '2 days'], dtype='timedelta64[ns]', freq=None)

idx1.sym_diff(idx2.asobject.tolist())
# TimedeltaIndex(['1 days', '2 days', '6 days', '7 days'], dtype='timedelta64[ns]', freq=None)

@sinhrks
Copy link
Member Author

sinhrks commented May 31, 2015

Rebased, and updated top descriptions about TimedeltaIndex and MultiIndex behaviors.

jreback added a commit that referenced this pull request Jun 1, 2015
BUG: Index.union cannot handle array-likes
@jreback jreback merged commit 4fde946 into pandas-dev:master Jun 1, 2015
@jreback
Copy link
Contributor

jreback commented Jun 1, 2015

thanks @sinhrks

@sinhrks sinhrks deleted the union_array branch June 1, 2015 13:43
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.17.0, 0.16.2 Jun 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Index.union cannot handle array-likes
3 participants