-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Conversation
@@ -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]): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
@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)
… construction ENH: add generator support in DataFrame constructor
👍 |
ENH/API: allow DataFrame constructor to better accept list-like collections (GH3783,GH4297)
closes #3783
closes #4297
related to #2305 (as now accept GeneratorType), but just convert to list, don't incrementally create the frame