Skip to content
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

Better support for UserDict on constructor #55109

Closed
wants to merge 10 commits into from

Conversation

gabrielcnr
Copy link

@gabrielcnr gabrielcnr commented Sep 12, 2023

I noticed that if I create my DataFrame passing a dictionary which is a custom one of a subclass of collections.UserDict then we have incompatible behaviour with the one if I pass a builtin dict.

The idea is that the UserDict should have the same type interface as the dict and used for custom behaviour, instead of subclassing direct from dict.

This PR attempts to fix that incompatibility issue.

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@mroeschke mroeschke added the Constructors Series/DataFrame/Index/pd.array Constructors label Sep 12, 2023
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Could you add a new in the whatsnew 2.2.0.rst?

@gabrielcnr
Copy link
Author

Well observed, @marcelotrevisani - Mapping is better here

@gabrielcnr
Copy link
Author

@mroeschke is this good to go? :-)

Co-authored-by: Marcelo Duarte Trevisani <[email protected]>
@marcelotrevisani
Copy link

@datapythonista
Marc, if you don't mind, can you take a look please? :)

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Oct 16, 2023
@@ -29,7 +29,7 @@ enhancement2
Other enhancements
^^^^^^^^^^^^^^^^^^
- DataFrame.apply now allows the usage of numba (via ``engine="numba"``) to JIT compile the passed function, allowing for potential speedups (:issue:`54666`)
-
- It is now possible to pass an object that either directly inherits from ``abc.Mapping`` or has it in its inheritance chain to initialize a DataFrame. The expected behaviour is the same as if you pass a ``dict`` object. (:issue:`55109`)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- It is now possible to pass an object that either directly inherits from ``abc.Mapping`` or has it in its inheritance chain to initialize a DataFrame. The expected behaviour is the same as if you pass a ``dict`` object. (:issue:`55109`)
- :class:`DataFrame` now accepts ``data`` that are ``abc.Mapping`` subclasses. (:issue:`55109`)

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Could you test the Series constructor too?

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.

@mroeschke mroeschke closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants