-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dataset constructor can take pandas objects #677
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
shoyer
merged 3 commits into
pydata:master
from
SixtyCapital:allow-pandas-to-ds-constructor
Jan 2, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,7 +205,7 @@ def __init__(self, data_vars=None, coords=None, attrs=None, | |
data_vars = {} | ||
if coords is None: | ||
coords = set() | ||
if data_vars or coords: | ||
if data_vars is not None or coords is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was easier than I thought! |
||
self._set_init_vars_and_dims(data_vars, coords, compat) | ||
if attrs is not None: | ||
self.attrs = attrs | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You should also be able to supply DataArrays (and maybe pandas objects?) as coords
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.
@shoyer Should we define something as "DataArray-like" if it's:
~xray.DataArray
(dims, data[, attrs])
dim0
,dim1
, etc...and then use that definition throughout? There are currently a few references to that (although currently written differently in different places).
I think the only exception is a
dim
, which is a 1D version of those.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.
It would indeed be worth formalizing what it means to be "DataArray-like". The trouble is that it depends a bit on context:
For
coords
ordata_vars
, you can supply:xray.DataArray
orxray.Variable
We don't automatically labeled dimensions (except for 1D arrays), because that's probably user error rather than what they would like to see.
For casting with the
DataArray
constructor, you can use:xray.DataArray
orxray.Variable
dim0
,dim1
, etc (unlessdims
orcoords
is supplied)Here, we don't accept tuples
(dims, data[, attrs])
because there's another, more explicit place for such arguments in theDataArray
constructor.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.
Super, thanks for that.
I'll use those lists. Do you think it would make sense to define the first list as 'DataArray-like', and use it for
coords
&data_vars
? I don't think it's a problem that the DataArray constructor can't be constructed with all of them. But introducing terms tends to be a one-way process, so let's do it deliberately if we do.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.
@shoyer gentle ping on this