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

PI-3677: Remove regex from standard names check #3679

Merged
merged 6 commits into from
Jun 3, 2020

Conversation

jvegreg
Copy link

@jvegreg jvegreg commented Mar 6, 2020

The regex in get_valid_standard_name was an overkill as the function was already checking the values against a list that contained all the possible values.

This pull request replaces it with a simple split and fixes the bug that was making iris not to accept atmosphere_optical_thickness_due_to_pm1_ambient_aerosol as a valid standard_name

Fixes #3677

@jvegreg
Copy link
Author

jvegreg commented Mar 6, 2020

I updated master, but final changes must be propagated to 2.4.x to fix ESMValGroup/ESMValTool#1561

@pp-mo
Copy link
Member

pp-mo commented Mar 10, 2020

👍
I'd like to say this is good to go, but I'm not the best expert.
The extra testing is useful, and passing the existing ones is certainly encouraging !

@bjlittle @lbdreyer do we have any further comment on this ?
I felt that this was over-complicated as was, but I could have missed something ..

@pp-mo pp-mo added this to the v3.0.0 milestone Jun 3, 2020
@pp-mo pp-mo changed the title Remove regex from standard names check PI-3677: Remove regex from standard names check Jun 3, 2020
@pp-mo pp-mo self-requested a review June 3, 2020 09:44
@bjlittle bjlittle self-assigned this Jun 3, 2020
Comment on lines 72 to 73
else:
name_is_valid = False
Copy link
Member

@bjlittle bjlittle Jun 3, 2020

Choose a reason for hiding this comment

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

@jvegasbsc There is no need for the else as name_is_valid is not used outside the scope of the if statement

@@ -19,10 +19,26 @@ class Test(tests.IrisTest):
def setUp(self):
self.emsg = "'{}' is not a valid standard_name"

def test_none_is_valid(self):
Copy link
Member

@bjlittle bjlittle Jun 3, 2020

Choose a reason for hiding this comment

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

@jvegasbsc I'm going to be a tad fussy here, sorry... None is valid in the sense that no exception is raised by get_valid_standard_name, but obviously it's not an actual valid standard name.

Could we change the intent of this test name to be something like test_pass_thru_none instead?

name = None
self.assertEqual(get_valid_standard_name(name), name)

def test_empty_is_not_valid(self):
Copy link
Member

@bjlittle bjlittle Jun 3, 2020

Choose a reason for hiding this comment

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

@jvegasbsc Same here, change test name to be test_pass_thru_empty...

name = ''
self.assertEqual(get_valid_standard_name(name), name)

def test_only_whitespace_is_not_valid(self):
Copy link
Member

@bjlittle bjlittle Jun 3, 2020

Choose a reason for hiding this comment

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

@jvegasbsc Same here, change test name to be test_pass_thru_whitespace...

def test_valid_standard_name(self):
name = "air_temperature"
self.assertEqual(get_valid_standard_name(name), name)

def test_standard_name_alias(self):
name = "atmosphere_optical_thickness_due_to_pm1_ambient_aerosol"
self.assertEqual(get_valid_standard_name(name), name)
Copy link
Member

@bjlittle bjlittle Jun 3, 2020

Choose a reason for hiding this comment

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

@jvegasbsc Nice, covers your test case, thanks! 👍

@bjlittle bjlittle self-requested a review June 3, 2020 11:17
Copy link
Member

@bjlittle bjlittle left a comment

Choose a reason for hiding this comment

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

@jvegasbsc Awesome PR, thanks @jvegasbsc.

I've suggested some minor tweaks, so if you could service them then we'll get this merged asap.

Also, you may need to rebase the PR to pick up some other changes to fix some tests that are failing in travis-ci.

Thanks 👍

@bjlittle
Copy link
Member

bjlittle commented Jun 3, 2020

@jvegasbsc almost there... you just have a couple of travis-ci failures.

black, version 19.10b0
would reformat /home/travis/build/SciTools/iris/lib/iris/_cube_coord_common.py
would reformat /home/travis/build/SciTools/iris/lib/iris/tests/unit/cube_coord_common/test_get_valid_standard_name.py
Oh no! 💥 💔 💥

We've now adopted the black coding standard for iris. To fix your failing issues please install black into your environment e.g., conda install -c conda-forge black or pip install black, then go to the root directory of iris and perform the following command black .. This will reformat the non-compliant files _cube_coord_common.py or test_get_valid_standard_name.py.

Alternatively, you can could also install pre-commit into your environment from either conda-forge or PyPI, then go to the root directory of iris and perform the command pre-commit install... and this will install our git pre-commit hooks, which will perform a whole host of checks for each git commit on iris - thus catching such issues automatically

@bjlittle
Copy link
Member

bjlittle commented Jun 3, 2020

@jvegreg
Copy link
Author

jvegreg commented Jun 3, 2020

Done!

@bjlittle bjlittle merged commit e54e2ff into SciTools:master Jun 3, 2020
@bjlittle
Copy link
Member

bjlittle commented Jun 3, 2020

@jvegasbsc Awesome, thanks for your patience and fixing this issue, much appreciated 👍

tkknight pushed a commit to tkknight/iris that referenced this pull request Jun 29, 2020
* Remove regex from standard names check

* remove duplicated test

* Added test cases for none, empty and only spaces

* Remove duplicated test

* Address comments

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

Successfully merging this pull request may close these issues.

Valid standard_name (present in STD_NAMES dict) is still rejected because of formatting maflormation
4 participants