Skip to content

API: Index/Series/DataFrame op 1-d list-like coercion #13637

Closed
@sinhrks

Description

@sinhrks

xref #1134. There is another inconsistencies related to op. Index/Series/DataFrame op can accept 1-d list-like as input and coercing to Index/Series. However, supported 1-d list-likes differ depending on the class and kind of op.

Code Sample, a copy-pastable example if possible

# Series + equal length list, OK
pd.Series([1, 2, 3]) + [2, 2, 2]
#0    3
#1    4
#2    5
# dtype: int64

# Series + equal length Index, OK
pd.Series([1, 2, 3]) + pd.Index([2, 2, 2])
#0    3
#1    4
#2    5
# dtype: int64

# DataFrame + equal length list, OK
pd.DataFrame([[1, 2, 3]]) + [2, 2, 2]
#    0  1  2
#0  3  4  5

# DataFrame + equal length Index, NG
pd.DataFrame([[1, 2, 3]]) + pd.Index([2, 2, 2])
# ValueError: cannot evaluate a numeric op with unequal lengths

I've organize the result once as the below table. I think all these must be supported and consistent.

Class op list tuple ndarray(1dim) Index
Index Arithmetic x x o o
Index Comparison o o o o
Index Boolean o o o o
Series Arithmetic o o o o
Series Comparison o o o o
Series Boolean o o o x
Frame Arithmetic o o o x
Frame Comparison o o o o
Frame Boolean o o o x

NOTE: Index result may depends on its type.

output of pd.show_versions()

0.18.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugNeeds 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