Skip to content

BUG: instantiation using a dict with a period scalar #35966

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

Merged
merged 13 commits into from
Sep 11, 2020

Conversation

justinessert
Copy link
Contributor

Fixing bug discussed in issue 35965 where pd.DataFrame({'a': pd.Period('2020-01')}) created a as an object column instead of a period[m] column.

Changing the functionality of infer_dtype_from_scalar isn't necessarily required here, but the fact that infer_dtype_from_scalar would return the period.ordinal value seems inconsistent with the behavior for other dtypes in this function. Additionally, that functionality was only used in a single place within the code (interval.py), which I fixed accordingly.

@pep8speaks
Copy link

pep8speaks commented Aug 28, 2020

Hello @justinessert! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-09-06 22:33:19 UTC

@jreback jreback added Bug Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. Period Period data type labels Sep 1, 2020
@jreback jreback added this to the 1.2 milestone Sep 1, 2020
@jreback jreback changed the title bugfix for df instantiation using a dict with a period scalar BUG: instantiation using a dict with a period scalar Sep 1, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u update tests i think in pandas/tests/test/test_dtypes.py (thathit infer_scalar_from_dtype for the new behavior) it's possible we were not testing a period before

@justinessert
Copy link
Contributor Author

@jreback there's one that I updated in test_infer_dtype_from_period, is that what you mean or are you after something else?

@justinessert
Copy link
Contributor Author

@jreback What are you looking to be tested outside of test_infer_dtype_from_period?

@jreback
Copy link
Contributor

jreback commented Sep 11, 2020

@jreback What are you looking to be tested outside of test_infer_dtype_from_period?

yep saw that, your change is good

@jreback jreback merged commit 6c8b923 into pandas-dev:master Sep 11, 2020
@jreback
Copy link
Contributor

jreback commented Sep 11, 2020

thanks @justinessert very nice

@justinessert
Copy link
Contributor Author

@jreback Thanks for all your helpful and timely replies, it's much appreciated!

@justinessert justinessert deleted the master branch October 10, 2020 15:07
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors Dtype Conversions Unexpected or buggy dtype conversions ExtensionArray Extending pandas with custom dtypes or arrays. Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame creates an object-dtype array for extension type scalars in dictionaries
4 participants