Skip to content

Mixed dtypes of column index for data frames raises en error #47382

Closed
@ChristopheBernard

Description

@ChristopheBernard

Here is a snippet of code summarizing the issue (pandas 1.4.2, various versions of python).

import pandas as pd


d = pd.DataFrame(columns=list('abc'), data=0.0, index=[0])
e = pd.DataFrame(columns=list('abc'), data=0.0, index=[0])
e.columns = e.columns.astype('string')

d+e ## raises an unexpected exception

The simple addition of 2 arrays of apparently the same shape ends with the following exception:

ValueError: Location based indexing can only have [integer, integer slice 
(START point is INCLUDED, END point is EXCLUDED), listlike of integers, 
boolean array] types

The dtypes of the columns of p1 and p2 are respectively:

>>> p1.columns.dtype
dtype('O')

>>> p2.columns.dtype
string[python]

and that seems to cause the issue.

I would expect the formula p1+p2 to work like p1+p1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.IndexRelated to the Index class or subclassesNeeds TestsUnit test(s) needed to prevent regressionsNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions