-
-
Notifications
You must be signed in to change notification settings - Fork 19k
Closed
Labels
BugDatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Description
Converting to object before then unstack works, whereas automatic upcast does not happen. Missing values are replaced with NaT instead of automatically upcasting to object and filling with the requested value.
In [44]: td = [Timedelta(days=i) for i in range(4)]
In [45]: data = Series(td)
In [46]: data.index = MultiIndex.from_tuples(
....: [('x', 'a'), ('x', 'b'), ('y', 'b'), ('z', 'a')])
In [47]: data.unstack(fill_value='foo')
Out[47]:
a b
x 0 days 1 days
y NaT 2 days
z 3 days NaT
In [48]: data.astype(np.object_).unstack(fill_value='foo')
Out[48]:
a b
x 0 days 00:00:00 1 days 00:00:00
y foo 2 days 00:00:00
z 3 days 00:00:00 foo
Culprit is some outdated code in _maybe_promote.
Metadata
Metadata
Assignees
Labels
BugDatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode