Skip to content

Conversation

@peanutfun
Copy link

@peanutfun peanutfun commented Nov 7, 2025

This fixes an issue with the fill_value when performing unstack. The docs on unstack state (emphasis by me):

fill_value (scalar or dict-like, default: nan) – value to be filled. If a dict-like, maps variable names to fill values. If not provided or if the dict-like does not contain all variables, the dtype’s NA value will be used.

If a full reindex is required during unstack, this is performed by the aligner, with the fill value handled here:

if isinstance(fill_value, dict):

If a full reindex is not required, the emphasized part in the docs is not true. Then, the program flow does not call the aligner but _unstack_once instead here:

result = result._unstack_once(d, stacked_indexes[d], fill_value, sparse)

_unstack_once, however, does not handle the case where a variable name is not found in the fill_value mapping.

This PR fixes the latter issue.

Please let me know if I should add a test and mention a change in whats-new.rst.

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@welcome
Copy link

welcome bot commented Nov 7, 2025

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@dcherian
Copy link
Contributor

dcherian commented Nov 7, 2025

LGTM! Thanks. Can you add a unit test for this please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants