-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support non-ndarray computations, cache unit calls, and add slots to DataArray #47
base: master
Are you sure you want to change the base?
Changes from all commits
9d8ec5b
12327bb
be38d65
56620ea
9ddcebd
29b5f23
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 |
---|---|---|
|
@@ -43,13 +43,16 @@ def get_numpy_array(data_array, out_dims, dim_lengths): | |
dict of dim_lengths that will give the length of any missing dims in the | ||
data_array. | ||
""" | ||
if len(data_array.values.shape) == 0 and len(out_dims) == 0: | ||
return data_array.values # special case, 0-dimensional scalar array | ||
if len(data_array.data.shape) == 0 and len(out_dims) == 0: | ||
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 change alters the behavior of this function, which is OK, but the variable names, function name, file name, and docstring need to be updated. For example, I would suggest naming the function something like The tests in 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. That's correct. I will rename the function and update the tests. |
||
return data_array.data # special case, 0-dimensional scalar array | ||
else: | ||
missing_dims = [dim for dim in out_dims if dim not in data_array.dims] | ||
for dim in missing_dims: | ||
data_array = data_array.expand_dims(dim) | ||
numpy_array = data_array.transpose(*out_dims).values | ||
if not all(dim1 == dim2 for dim1, dim2 in zip(data_array.dims, out_dims)): | ||
numpy_array = data_array.transpose(*out_dims).data | ||
else: | ||
numpy_array = data_array.data | ||
if len(missing_dims) == 0: | ||
out_array = numpy_array | ||
else: # expand out missing dims which are currently length 1. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ | |
|
||
|
||
def ensure_values_are_arrays(array_dict): | ||
for name, value in array_dict.items(): | ||
if not isinstance(value, np.ndarray): | ||
array_dict[name] = np.asarray(value) | ||
pass | ||
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 is a temporary and dirty solution. We could think of a mechanism to control whether arrays must be coerced or not. 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. We can't merge this change as-is, what problem is being solved here and what other solutions are available for it? 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. The |
||
# for name, value in array_dict.items(): | ||
# if not isinstance(value, np.ndarray): | ||
# array_dict[name] = np.asarray(value) | ||
|
||
|
||
def get_alias_or_name(name, output_properties, input_properties): | ||
|
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.
What are the implications of setting this? What warning is it suppressing, and what behavior does it cause when you set this to an empty list?
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.
This is aimed to suppress
FutureWarning: xarray subclass DataArray should explicitly define __slots__
. Here is a nice explanation of how__slots__
work.