question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sel with method 'nearest' fails with AssertionError

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
shoyercommented, Feb 20, 2017

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.

0reactions
joschkazjcommented, Feb 22, 2017

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.

Just for reference (I don’t develop on Windows), do we need to test both 32 and 64 bit Windows installs?

As some binary dependencies are involved, both have to be tested.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found