Skip to content

BUG: Automatic upcast to object fails when unstacking datetime/timedelta with incompatible fill_value #12189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
amcpherson opened this issue Jan 31, 2016 · 4 comments
Labels
Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@amcpherson
Copy link
Contributor

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.

@amcpherson
Copy link
Contributor Author

Follows from work done for #9746.

@jreback jreback added Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Difficulty Novice Dtype Conversions Unexpected or buggy dtype conversions labels Jan 31, 2016
@jreback jreback added this to the Next Major Release milestone Jan 31, 2016
@jreback
Copy link
Contributor

jreback commented Jan 31, 2016

thanks @amcpherson for the clear issue!

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@jbrockmendel
Copy link
Member

It isn't clear to me that this should be supported.

@mroeschke
Copy link
Member

Yeah I would expect this to raise

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

5 participants