Skip to content
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

libpysal/weights/raster.py missing test coverage #657

Open
jGaboardi opened this issue Nov 16, 2023 · 2 comments
Open

libpysal/weights/raster.py missing test coverage #657

jGaboardi opened this issue Nov 16, 2023 · 2 comments
Labels
bug functionality that: returns invalid, erroneous, or meaningless results; or doesn't work at all. code coverage needs testing a pull request which needs testing added, or a bug/rough edge which exposes a functional testing gap weights

Comments

@jGaboardi
Copy link
Member

xref #655 (review)

Although pytest claims that this chunk is being tested in libpysal/weights/raster.py, it is in fact not. As an example:

from libpysal.weights import raster
pytest.importorskip("xarray")
da2_missing_in = raster.testDataArray((1, 4, 4), missing_vals=True)
w2_missing = raster.da2W(da2_missing_in, "rook", n_jobs=-1)
da2_missing_out = raster.w2da(
    da2_missing_in.data.flatten(), w2_missing, da2_missing_in.attrs, None
)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 6
      4 da2_missing_in = raster.testDataArray((1, 4, 4), missing_vals=True)
      5 w2_missing = raster.da2W(da2_missing_in, "rook", n_jobs=-1)
----> 6 da2_missing_out = raster.w2da(
      7     da2_missing_in.data.flatten(), w2_missing, da2_missing_in.attrs, None
      8 )

File ~/libpysal/libpysal/weights/raster.py:343, in w2da(data, w, attrs, coords)
    341     raise TypeError("w must be an instance of weights.W")
    342 if hasattr(w, "index"):
--> 343     da = _index2da(data, w.index, attrs, coords)
    344 else:
    345     raise AttributeError(
    346         "This method requires `w` object to include `index` "
    347         "attribute that is built as a `pandas.MultiIndex` object."
    348     )

File ~/libpysal/libpysal/weights/raster.py:570, in _index2da(data, index, attrs, coords)
    568 else:
    569     data_complete = np.empty(shape, data.dtype)
--> 570 data_complete[indexer] = data
    571 coords = {}
    572 for dim, lev in zip(dims, idx.levels, strict=True):

ValueError: shape mismatch: value array of shape (16,) could not be broadcast to indexing result of shape (6,)
@jGaboardi jGaboardi added needs testing a pull request which needs testing added, or a bug/rough edge which exposes a functional testing gap weights tests code coverage labels Nov 16, 2023
@martinfleis
Copy link
Member

Well, this is probably not just a missing coverage but a bug, no?

@jGaboardi
Copy link
Member Author

Well, this is probably not just a missing coverage but a bug, no?

Yes, maybe all of the above and more. That's the scary part...

@jGaboardi jGaboardi added bug functionality that: returns invalid, erroneous, or meaningless results; or doesn't work at all. and removed tests labels Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug functionality that: returns invalid, erroneous, or meaningless results; or doesn't work at all. code coverage needs testing a pull request which needs testing added, or a bug/rough edge which exposes a functional testing gap weights
Projects
None yet
Development

No branches or pull requests

2 participants