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

Improve error messages when comparing against objects vs strings #4928

Merged
merged 6 commits into from
Nov 1, 2022

Conversation

stephenworsley
Copy link
Contributor

A simple change to error messages to address #4898.

Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

Wow, thanks for the fast work @stephenworsley! I agree that trying to list out exactly what didn't match might be more trouble than it's worth, but I have a suggestion to be a bit more explicit for the coord case.

lib/iris/cube.py Outdated Show resolved Hide resolved
@rcomer rcomer linked an issue Aug 24, 2022 that may be closed by this pull request
@stephenworsley stephenworsley marked this pull request as ready for review August 25, 2022 09:43
@stephenworsley stephenworsley force-pushed the coord_error_message branch 2 times, most recently from 3295b8e to 6bd15c1 Compare August 25, 2022 10:01
Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

Hi @stephenworsley, this looks good to me. Some very minor suggestions in line. I also wonder if it is worth updating the relevant tests to use assertRaisesRegex and check the message:

[Can't seem to find them for cube.coord !]

def test_fail_get_cell_measure(self):
with self.assertRaises(CellMeasureNotFoundError):
_ = self.cube.cell_measure("notarea")
def test_fail_get_cell_measures_obj(self):
a_cell_measure = self.a_cell_measure.copy()
a_cell_measure.units = "km2"
with self.assertRaises(CellMeasureNotFoundError):
_ = self.cube.cell_measure(a_cell_measure)

def test_fail_get_ancillary_variables(self):
with self.assertRaises(AncillaryVariableNotFoundError):
self.cube.ancillary_variable("other_ancill_var")
def test_fail_get_ancillary_variables_obj(self):
ancillary_variable = self.ancill_var.copy()
ancillary_variable.long_name = "Number of observations at site"
with self.assertRaises(AncillaryVariableNotFoundError):
self.cube.ancillary_variable(ancillary_variable)

lib/iris/cube.py Outdated Show resolved Hide resolved
lib/iris/cube.py Outdated Show resolved Hide resolved
Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

Thanks @stephenworsley. Just waiting for the CI...

@rcomer
Copy link
Member

rcomer commented Nov 1, 2022

Seems docs are failing because https://docs.scipy.org/ is down, so the intersphinx mapping doesn't work. I'm inclined to merge anyway: the only doc change here is the whatsnew entry and it was fine before rebase.

@rcomer rcomer merged commit 8499fe0 into SciTools:main Nov 1, 2022
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.

Misleading error message from Cube.coord
2 participants