-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Enable resampling on PeriodIndex #2687
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1789,12 +1789,17 @@ class IndexVariable(Variable): | |
unless another name is given. | ||
""" | ||
|
||
def __init__(self, dims, data, attrs=None, encoding=None, fastpath=False): | ||
def __init__(self, dims, data, attrs=None, encoding=None, fastpath=False, name=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. I would rather not add an explicit If anything, I would think about removing the |
||
super(IndexVariable, self).__init__(dims, data, attrs, encoding, | ||
fastpath) | ||
if self.ndim != 1: | ||
raise ValueError('%s objects must be 1-dimensional' % | ||
type(self).__name__) | ||
|
||
if name is None: | ||
self._name = self.dims[0] | ||
else: | ||
self._name = name | ||
|
||
# Unlike in Variable, always eagerly load values into memory | ||
if not isinstance(self._data, PandasIndexAdapter): | ||
|
@@ -1956,7 +1961,7 @@ def get_level_variable(self, level): | |
|
||
@property | ||
def name(self): | ||
return self.dims[0] | ||
return self._name | ||
|
||
@name.setter | ||
def name(self, value): | ||
|
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 we could alternatively fix this by replace
dim_coord
in thedata
argument withdim_coord.to_index()
, e.g., compare:We go to some effort to preserve pandas.Index classes when passed into DataArray/Variable but apparently don't do it consistently everywhere. So there's also probably a lower level fix somewhere (perhaps in
xarray.core.variable.as_compatible_data
?) to ensure that this happens more consistently.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.
Great! I'll have a look