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

ENH/API: allow DataFrame constructor to better accept list-like collections (GH3783,GH4297) #4829

Merged
merged 2 commits into from
Sep 13, 2013

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Sep 13, 2013

closes #3783
closes #4297
related to #2305 (as now accept GeneratorType), but just convert to list, don't incrementally create the frame

@@ -418,7 +418,8 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
if index is None and isinstance(data[0], Series):
index = _get_names_from_index(data)

if isinstance(data[0], (list, tuple, collections.Mapping, Series)):
if isinstance(data[0], (list, tuple, collections.Mapping,
collections.Sequence, Series)) and is_list_like(data[0]):
Copy link
Contributor

Choose a reason for hiding this comment

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

why couldn't you just remove the entire type check and just use is_list_like instead here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DataFrame([DataFrame(dict(A = lrange(5)))])

this beauty here (which if you use just is_list_like) collapses it...maybe should just completely disallow this

Copy link
Contributor

Choose a reason for hiding this comment

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

I think core.common.is_list_like(DataFrame(dict(A = lrange(5)))) returns True.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's the problem, it needs to be initialized to an object array, rather than like a list-of-lists which is intialized differently

Copy link
Contributor

Choose a reason for hiding this comment

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

ah - I see...could you check for PandasObjects first or something? (or add
not isinstance(data[0], (DataFrame, Panel))?) otherwise I guess it's fine

On Thu, Sep 12, 2013 at 9:08 PM, jreback [email protected] wrote:

In pandas/core/frame.py:

@@ -418,7 +418,8 @@ def init(self, data=None, index=None, columns=None, dtype=None,
if index is None and isinstance(data[0], Series):
index = _get_names_from_index(data)

  •            if isinstance(data[0], (list, tuple, collections.Mapping, Series)):
    
  •            if isinstance(data[0], (list, tuple, collections.Mapping,
    
  •                                    collections.Sequence, Series)) and is_list_like(data[0]):
    

that's the problem, it needs to be initialized to an object array, rather
than like a list-of-lists which is intialized differently


Reply to this email directly or view it on GitHubhttps://github.com//pull/4829/files#r6339304
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no good solution either way; its basically checking if the input is 1-d or 2-d, hmm....let me try something..

Copy link
Contributor

Choose a reason for hiding this comment

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

eh, I'm just not a fan of collections in general, because it's slowish, but this is probably the better option because it's more explicit, and, as @y-p notes, allows for objects to register themselves.

@jreback
Copy link
Contributor Author

jreback commented Sep 13, 2013

@jtratner that worked....now not dependent on the type per se only that its list-like and 1dim

…g. list of

    `ollections.Sequence and array.Array objects (GH3783 and GH42971)
@jreback
Copy link
Contributor Author

jreback commented Sep 13, 2013

@jtratner @cpcloud ?

… construction

ENH: add generator support in DataFrame constructor
@jtratner
Copy link
Contributor

👍

jreback added a commit that referenced this pull request Sep 13, 2013
ENH/API: allow DataFrame constructor to better accept list-like collections (GH3783,GH4297)
@jreback jreback merged commit 8b69209 into pandas-dev:master Sep 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants