sel with method 'nearest' fails with AssertionError
See original GitHub issueThe following fails
def test_sel_nearest():
"""Test `sel` with method='nearest'"""
# create test data
times = pd.date_range('2000-01-01', periods=4)
foo = xr.DataArray([1,2,3,4], coords=dict(time=times), dims='time')
# works
expected = foo.sel(time='2000-01-01')
# fails
assert foo.sel(time='2000-01-01', method='nearest') == expected
with an AssertionError
in xarray/core/variable.py
:
C:\Users\uuu\AppData\Local\Continuum\Miniconda2\lib\site-packages\xarray\core\dataarray.pyc in sel(self, method, tolerance, **indexers)
623 self, indexers, method=method, tolerance=tolerance
624 )
--> 625 return self.isel(**pos_indexers)._replace_indexes(new_indexes)
626
627 def isel_points(self, dim='points', **indexers):
C:\Users\uuu\AppData\Local\Continuum\Miniconda2\lib\site-packages\xarray\core\dataarray.pyc in isel(self, **indexers)
608 DataArray.sel
609 """
--> 610 ds = self._to_temp_dataset().isel(**indexers)
611 return self._from_temp_dataset(ds)
612
C:\Users\uuu\AppData\Local\Continuum\Miniconda2\lib\site-packages\xarray\core\dataset.pyc in isel(self, **indexers)
910 for name, var in iteritems(self._variables):
911 var_indexers = dict((k, v) for k, v in indexers if k in var.dims)
--> 912 variables[name] = var.isel(**var_indexers)
913 return self._replace_vars_and_dims(variables)
914
C:\Users\uuu\AppData\Local\Continuum\Miniconda2\lib\site-packages\xarray\core\variable.pyc in isel(self, **indexers)
539 if dim in indexers:
540 key[i] = indexers[dim]
--> 541 return self[tuple(key)]
542
543 def _shift_one_dim(self, dim, count):
C:\Users\uuu\AppData\Local\Continuum\Miniconda2\lib\site-packages\xarray\core\variable.pyc in __getitem__(self, key)
377 # orthogonal indexing should ensure the dimensionality is consistent
378 if hasattr(values, 'ndim'):
--> 379 assert values.ndim == len(dims), (values.ndim, len(dims))
380 else:
381 assert len(dims) == 0, len(dims)
AssertionError: (0, 1)
It does not matter which type the dimension has that is indexed:
def test_sel_nearest_int():
"""Test `sel` with method='nearest'"""
bar = xr.DataArray([1, 2, 3, 4], coords=dict(dummy=range(4)), dims='dummy')
# works
expected = bar.sel(dummy=3)
# fails
assert bar.sel(dummy=3, method='nearest') == expected
This is on Miniconda for Windows 64 bit with conda-forge and IOOS builds and
- xarray=0.8.2
- pandas=0.19.1
- numpy=1.11.2
Why might this be? Am I doing something wrong?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
JUnit test case failure. java.lang.AssertionError - Stack Overflow
When I run the test case against this method, it reports: There was 1 failure: 1) nearestKTest(SelectorTest) java.lang.AssertionError: ...
Read more >AssertionError in Python - Javatpoint
Examples to Use Assert Statement. Assertion error with an error message. Here is a method that changes a temperature from Kelvin to Fahrenheit....
Read more >AssertionError (Java Platform SE 7 ) - Oracle Help Center
Constructs a new AssertionError with the specified detail message and cause. Method Summary. Methods inherited from class java.lang.Throwable · addSuppressed, ...
Read more >Assertion Error when running code - PyTorch Forums
Dear all, When I tried running my code, cuda throws device-asserted error as below 05/20 20:42:13 Epoch: 1, LR: [0.1] F0 size: torch....
Read more >Python assert Keyword - W3Schools
The assert keyword lets you test if a condition in your code returns True, if not, the program will raise an AssertionError. You...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sounds like we need to add 64-bit Python 2.7 on Windows to our build matrix!
And also a more robust check for integer types in variable.py.
At our institute we use Python (both v2.7 and 3.x) exclusively on x64 systems to make use of the entire memory on our workstations. Since all relevant (binary) scientific packages are released as 64-bit versions, 32 bit Python is obsolete for our use cases.
As some binary dependencies are involved, both have to be tested.