Skip to content

BUG: casting dt64 in DataFrame.reindex #39755

Closed
@jbrockmendel

Description

@jbrockmendel
import numpy as np
import pandas as pd

mi = pd.MultiIndex.from_product([list("ABCDE"), range(2)])
dti = pd.date_range("2016-01-01", periods=10)
ser = pd.Series(dti, index=mi)
df = ser.unstack()

index = df.index.append(pd.Index([1]))
columns = df.columns.append(pd.Index(["foo"]))
axes = {"index": index, "columns": columns}

fv = np.timedelta64("NaT", "ns")

res = df.reindex(fill_value=fv, **axes)

>>> res
>>> res
                     0                    1 foo
A  1451606400000000000  1451692800000000000 NaT
B  1451779200000000000  1451865600000000000 NaT
C  1451952000000000000  1452038400000000000 NaT
D  1452124800000000000  1452211200000000000 NaT
E  1452297600000000000  1452384000000000000 NaT
1                  NaT                  NaT NaT

The underlying problem here is numpy/numpy#12550

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateReshapingConcat, Merge/Join, Stack/Unstack, ExplodeTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions