-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Only copy datetime64 data if it is using non-nanosecond precision. #125
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b303744
convert array of netCDF4.datetime objects to numpy.datetime64 array t…
9dfe284
restrict the conversion of netCDF4.datetime objects to numpy.datetime…
edcc854
Handle arbitrary shape time arrays in nctime_to_nptime. Also added t…
0d6a745
initial implementation of support for NetCDF groups
alimanfoo e41048c
cleanup fallback code a bit
c406d2b
use IOError; safer recursion; don't worry about group cycles
alimanfoo ec778a7
Require only numpy 1.7 for the benefit of readthedocs
shoyer 1c6b032
simplify group access to avoid recursion; test missing group error
alimanfoo 8d95d38
Add further testing for single element time ordinals.
e25cfcd
filter warnings from earlier tests
a3f21d3
correct filter message for warnings
69a9aa7
add test to catch fallback warnings, insure returning a numpy array d…
3dd0d69
fix python 3 build; right way to test exception is raised
alimanfoo 3e870e2
Only copy datetime64 data if it is using non-nanosecond precision.
d88e54f
Convert datetime objects to datetime64 upon variable creation in
6bf4cc3
Added utils.safe_timestamp() which avoids issues when datetime[ns]
d09708a
Updated test_variable to deal with python 3 unicode types
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ nosetests.xml | |
.project | ||
.pydevproject | ||
|
||
# PyCharm | ||
.idea | ||
|
||
# xray specific | ||
doc/_build | ||
doc/generated | ||
|
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# only the dependencies required to build xray's docs | ||
# all others (netCDF4, scipy) are mocked out in conf.py | ||
numpy==1.8.1 | ||
numpy>=1.7 | ||
ipython==2.0.0 | ||
pandas==0.13.1 | ||
six | ||
python-dateutil | ||
scipy | ||
six | ||
matplotlib |
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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
from xray import Variable, Dataset, DataArray | ||
from xray.variable import (Coordinate, as_variable, NumpyArrayAdapter, | ||
PandasIndexAdapter) | ||
PandasIndexAdapter, _as_compatible_data) | ||
|
||
from . import TestCase, source_ndarray | ||
|
||
|
@@ -38,11 +38,11 @@ def test_attrs(self): | |
|
||
def test_0d_data(self): | ||
d = datetime(2000, 1, 1) | ||
for value, dtype in [(0, int), | ||
(np.float32(0.5), np.float32), | ||
('foo', np.str_), | ||
(d, None), | ||
(np.datetime64(d), np.datetime64)]: | ||
for value, dtype, expected in [(0, int, 0), | ||
(np.float32(0.5), np.float32, np.float32(0.5)), | ||
('foo', np.str_, 'foo'), | ||
(d, None, np.datetime64(d, 'ns')), | ||
(np.datetime64(d), np.datetime64, np.datetime64(d, 'ns'))]: | ||
x = self.cls(['x'], [value]) | ||
# check array properties | ||
self.assertEqual(x[0].shape, ()) | ||
|
@@ -52,13 +52,17 @@ def test_0d_data(self): | |
self.assertTrue(x.equals(x.copy())) | ||
self.assertTrue(x.identical(x.copy())) | ||
# check value is equal for both ndarray and Variable | ||
self.assertEqual(x.values[0], value) | ||
self.assertEqual(x[0].values, value) | ||
self.assertEqual(x.values[0], expected) | ||
self.assertEqual(x[0].values, expected) | ||
# check type or dtype is consistent for both ndarray and Variable | ||
if dtype is None: | ||
# check output type instead of array dtype | ||
self.assertEqual(type(x.values[0]), type(value)) | ||
self.assertEqual(type(x[0].values), type(value)) | ||
self.assertEqual(type(x.values[0]), type(expected)) | ||
if not x.dtype.kind == 'M': | ||
# unfortunately if x contains datetime64 objects slicing | ||
# out the scalar value will actually result in another | ||
# ndarray, so we skip this test for dates. | ||
self.assertEqual(type(x[0].values), type(expected)) | ||
else: | ||
assert np.issubdtype(x.values[0].dtype, dtype), (x.values[0].dtype, dtype) | ||
assert np.issubdtype(x[0].values.dtype, dtype), (x[0].values.dtype, dtype) | ||
|
@@ -463,3 +467,25 @@ def test_data(self): | |
self.assertIsInstance(x._data, PandasIndexAdapter) | ||
with self.assertRaisesRegexp(TypeError, 'cannot be modified'): | ||
x[:] = 0 | ||
|
||
|
||
class TestCompatibleArray(TestCase): | ||
|
||
def test_as_compatible_array(self): | ||
d = datetime(2000, 1, 1) | ||
for value, dtypes in [(0, [int]), | ||
(np.float32(0.5), [np.float32]), | ||
# String types will depend on | ||
# the version of python. | ||
('foo', ['|S3', '<U3']), | ||
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. Another way to do this would be to check something like 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. If you prefer that you have my permission to change it. |
||
(d, ['<M8[ns]']), | ||
(np.datetime64(d), ['<M8[ns]'])]: | ||
actual = _as_compatible_data(value) | ||
for attr in ['dtype', 'shape', 'size', 'ndim']: | ||
getattr(actual, attr) | ||
self.assertIn(actual.dtype, dtypes) | ||
# now do the same but as a 1-d array | ||
actual = _as_compatible_data([value]) | ||
for attr in ['dtype', 'shape', 'size', 'ndim']: | ||
getattr(actual, attr) | ||
self.assertIn(actual.dtype, dtypes) |
Oops, something went wrong.
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.
I'm not so sure about making this exception... it leaves us returning non-datetime-datetimes like: