Skip to content

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

Closed
@sinhrks

Description

@sinhrks

Though API doc says Index.union can accept Index or array-like, it raises errors.

import numpy as np
import pandas as pd
idx = pd.Index([1, 2, 3])

idx.union([2, 3, 4])
# AttributeError: 'list' object has no attribute 'dtype'

idx.union(pd.Series([2, 3, 4]))
# AttributeError: 'Series' object has no attribute 'is_monotonic'

idx.union(np.array([2, 3, 4]))
# AttributeError: 'numpy.ndarray' object has no attribute 'is_monotonic'

NOTE: intersection looks OK.

idx.intersection([2, 3, 4])
# Int64Index([2, 3], dtype='int64')

idx.intersection(pd.Series([2, 3, 4]))
# Int64Index([2, 3], dtype='int64')

idx.union([2, 3, 4])
# Int64Index([2, 3], dtype='int64')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions