Skip to content

Give quantify errors context #43

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

Merged
merged 12 commits into from
Apr 14, 2021

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented Nov 2, 2020

Fix for #42

  • tests added
  • update what's new

@keewis
Copy link
Collaborator

keewis commented Nov 2, 2020

thanks, @TomNicholas. A test checking that the name of the variable that is supposed to get the invalid unit appears in the error message would be great, but otherwise this looks good to me.

I just noticed that since #41 the "Github Action per Pipeline" works. Did you do anything?

@TomNicholas
Copy link
Member Author

A test checking that the name of the variable that is supposed to get the invalid unit appears in the error message would be great

Done.

I just noticed that since #41 the "Github Action per Pipeline" works. Did you do anything?

Not that I'm aware of!

Should there be an equivalent check for DataArray.pint.quantify? What are we even iterating over there - coordinates?

Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we even iterating over there - coordinates?

coordinates and data:

variables = itertools.chain([(obj.name, obj)], obj.coords.items())

I tried to get only a combined code path for both data and coords.

You will probably have to check against self.da.name to find out if the error was raised for a coordinate or the data.

@@ -222,6 +222,11 @@ def test_error_on_nonsense_units(self, example_unitless_ds):
with pytest.raises(UndefinedUnitError):
ds.pint.quantify(units={"users": "aecjhbav"})

def test_error_indicates_problematic_variable(self, example_unitless_ds):
ds = example_unitless_ds
with raises_regex(UndefinedUnitError, "users"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between raises_regex and pytest.raises' match parameter?

@keewis
Copy link
Collaborator

keewis commented Jan 19, 2021

I guess we can replace the DataArray call with a _to_temp_dataset / _from_temp_dataset` cycle (after asking whether these could be promoted to semi-public, of course).

Would you have the time to finish this PR, @TomNicholas? If not, I can try pushing to your branch.

@TomNicholas
Copy link
Member Author

Hi @keewis , I'm afraid I don't have time to finish this right now, I can do in a month or two though probably. I remember this stalled because I was seeing some behaviour I didn't understand with my solution, so best not to merge without being confident about how it handles all cases...

@keewis
Copy link
Collaborator

keewis commented Feb 2, 2021

no worries. I tried to refactor the code in #56 (joining the DataArray and Dataset code paths makes the code much simpler), so you will probably have to update this PR.

@keewis keewis mentioned this pull request Feb 20, 2021
Merged
This was referenced Mar 4, 2021
@keewis
Copy link
Collaborator

keewis commented Apr 9, 2021

@TomNicholas, would you have time to finish this? It is one of the major issues blocking the release of v0.2

@TomNicholas
Copy link
Member Author

Hi @keewis , that should work now, but I did have to change the raised error type to just a ValueError - trying to raise type(e) gives a weird nonsensical concatenated error message like
UndefinedUnitError: Failed to assign units to variable users is not defined in the unit registry

Raising just a ValueError gives a result that is more like "X was the cause of Y`, with X and Y presented on different lines, which I think is clear enough.

Copy link
Collaborator

@keewis keewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thanks, @TomNicholas. I have a few comments, but nothing major.

@keewis keewis merged commit 7518c84 into xarray-contrib:master Apr 14, 2021
@keewis
Copy link
Collaborator

keewis commented Apr 14, 2021

thanks again, @TomNicholas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants