Skip to content

Creating series with multiindex from dict with tuple keys with None #18505

Closed
@fumitoh

Description

@fumitoh

Code Sample

import pandas as pd

data1={(1, 2): 3,
       (4, None): 6}

s1 = pd.Series(data=data1)

data2={(1, 2): 3,
       (None, 5): 6}

s2 = pd.Series(data=data2)

Problem description

s1 has MultiIndex while s2 has Index of tuple just because the second element of the data2 has None as the first element of the key tuple.

>>> s1
1  2      3.0
4  NaN    NaN
dtype: float64
>>> s2
(1, 2)       3
(None, 5)    6
dtype: int64

Is this a bug? or is this how it's supposed to be?

FYI, both of mi1 and mi2 below yield MultiIndex as I expect.

mi1 = pd.MultiIndex.from_tuples([(1, 2), (4, None)])
mi2 = pd.MultiIndex.from_tuples([(1, 2), (None, 5)])

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions