Skip to content

BUG: [unit test] pandas/core/indexes/multi.py:3655: TypeError #48533

Closed
@adrienpacifico

Description

@adrienpacifico

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

pytest --pdb pandas/tests/test_multilevel.py

Issue Description

The unit-test

def test_alignment(self):

does not pass.

I am using VSCode with the .devcontainer file (thus in a container), with a linux distribution (pop-os).

Stack trace:

self = <pandas.tests.test_multilevel.TestMultiLevel object at 0x7fc319bae370>

    def test_alignment(self):
        x = Series(
            data=[1, 2, 3], index=MultiIndex.from_tuples([("A", 1), ("A", 2), ("B", 3)])
        )
    
        y = Series(
            data=[4, 5, 6], index=MultiIndex.from_tuples([("Z", 1), ("Z", 2), ("B", 3)])
        )
    
>       res = x - y

pandas/tests/test_multilevel.py:147: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/core/ops/common.py:72: in new_method
    return method(self, other)
pandas/core/arraylike.py:111: in __sub__
    return self._arith_method(other, operator.sub)
pandas/core/series.py:6273: in _arith_method
    self, other = ops.align_method_SERIES(self, other)
pandas/core/ops/__init__.py:168: in align_method_SERIES
    left, right = left.align(right, copy=False)
pandas/core/series.py:4865: in align
    return super().align(
pandas/core/generic.py:9478: in align
    return self._align_series(
pandas/core/generic.py:9585: in _align_series
    join_index, lidx, ridx = self.index.join(
pandas/util/_decorators.py:317: in wrapper
    return func(*args, **kwargs)
pandas/core/indexes/base.py:230: in join
    join_index, lidx, ridx = meth(self, other, how=how, level=level, sort=sort)
pandas/core/indexes/base.py:4725: in join
    return self._join_via_get_indexer(other, how, sort)
pandas/core/indexes/base.py:4747: in _join_via_get_indexer
    join_index = self.union(other)
pandas/core/indexes/base.py:3351: in union
    result = self._union(other, sort=sort)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = MultiIndex([('A', 1),
            ('A', 2),
            ('B', 3)],
           )
other = MultiIndex([('Z', 1),
            ('Z', 2),
            ('B', 3)],
           ), sort = None

    def _union(self, other, sort) -> MultiIndex:
        other, result_names = self._convert_can_do_setop(other)
        if (
            any(-1 in code for code in self.codes)
            and any(-1 in code for code in other.codes)
            or other.has_duplicates
        ):
            # This is only necessary if both sides have nans or other has dups,
            # fast_unique_multiple is faster
            result = super()._union(other, sort)
    
            if isinstance(result, MultiIndex):
                return result
            return MultiIndex.from_arrays(
                zip(*result), sortorder=None, names=result_names
            )
    
        else:
            rvals = other._values.astype(object, copy=False)
>           right_missing = lib.fast_unique_multiple(self._values, rvals)
E           TypeError: Argument 'arrays' has incorrect type (expected list, got numpy.ndarray)

pandas/core/indexes/multi.py:3655: TypeError

Expected Behavior

The test should pass

Installed Versions

INSTALLED VERSIONS ------------------ commit : aea824f python : 3.8.13.final.0 python-bits : 64 OS : Linux OS-release : 5.8.0-7630-generic Version : #32~1609193707~20.10~781bb80-Ubuntu SMP Tue Jan 5 21:29:56 UTC 2 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : C.UTF-8 LANG : C.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.6.0.dev0+119.gaea824f9aa.dirty
numpy : 1.22.4
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 65.3.0
pip : 22.2.2
Cython : 0.29.32
pytest : 7.1.3
hypothesis : 6.54.5
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : 2.9.3
jinja2 : 3.0.3
IPython : 8.5.0
pandas_datareader: 0.10.0
bs4 : 4.11.1
bottleneck : 1.3.5
brotli :
fastparquet : 0.8.3
fsspec : 2021.11.0
gcsfs : 2021.11.0
matplotlib : 3.5.3
numba : 0.55.2
numexpr : 2.8.3
odfpy : None
openpyxl : 3.0.10
pandas_gbq : 0.17.8
pyarrow : 9.0.0
pyreadstat : 1.1.9
pyxlsb : 1.0.9
s3fs : 2021.11.0
scipy : 1.9.1
snappy :
sqlalchemy : 1.4.41
tables : 3.7.0
tabulate : 0.8.10
xarray : 2022.6.0
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : 0.18.0
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BuildLibrary building on various platformsClosing CandidateMay be closeable, needs more eyeballs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions