Skip to content

BUG: assignment to Series.iloc with dtype="object" converts dictionary to Series #62723

@Liam-DeVoe

Description

@Liam-DeVoe

When a series has dtype="object", series.iloc[0] = {} converts the series element to a pandas Series, instead of storing the dictionary:

import pandas
s = pandas.Series(0, dtype="object")

s[0] = {}
assert s[0] == {}  # passes

s.iloc[0] = {}
assert s[0] == {}  # fails

I was surprised by this behavior, because I expected that dtype="object" would let me store the actual dictionary inside the series.

If this is expected behavior, I'd love to know if there's a recommended way to store dictionary values inside of a object-dtype series without it being converted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions