Skip to content

Improve error messages when comparing against objects vs strings#4928

Merged
rcomer merged 6 commits into
SciTools:mainfrom
stephenworsley:coord_error_message
Nov 1, 2022
Merged

Improve error messages when comparing against objects vs strings#4928
rcomer merged 6 commits into
SciTools:mainfrom
stephenworsley:coord_error_message

Conversation

@stephenworsley

Copy link
Copy Markdown
Contributor

A simple change to error messages to address #4898.

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

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.

Comment thread lib/iris/cube.py Outdated
@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

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

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)

Comment thread lib/iris/cube.py Outdated
Comment thread lib/iris/cube.py Outdated
@rcomer rcomer self-assigned this Oct 26, 2022

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

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

rcomer commented Nov 1, 2022

Copy link
Copy Markdown
Member

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