Skip to content

Conversation

@stephenworsley
Copy link
Contributor

As requested in #3457, Python 2 specific code has been removed.

@stephenworsley stephenworsley added this to the v3.0.0 milestone Nov 4, 2019
return operator.div
except AttributeError:
return operator.truediv
return operator.truediv
Copy link
Member

Choose a reason for hiding this comment

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

@stephenworsley It seems that the whole point of the data_op property was convenience i.e., to do the right thing across Python2 and Python wrt div and truediv.

Now that we're Python3, I'm just questioning the need for the existence of the data_op property.

Can't we just use operator.truediv or / directly inline for the tests? i.e.,

    def test_unmasked_div_zero(self):
        # Ensure cube behaviour matches numpy operator behaviour for the
        # handling of arrays containing 0.
        dat_a = np.array([0., 0., 0., 0.])
        dat_b = np.array([2., 2., 2., 2.])

        cube_a = Cube(dat_a)
        cube_b = Cube(dat_b)

        com = dat_b / dat_a
        res = self.cube_func(cube_b, cube_a).data

        self.assertArrayEqual(com, res)

Also drop the import operator as well 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it looks like what's going on here is that these classes are actually inheriting a bunch of tests from https://github.com/SciTools/iris/blob/master/lib/iris/tests/unit/analysis/maths/__init__.py

data_op is an abstract property in the parent class where it is used in other tests

@abstractproperty
def data_op(self):
# Define an operator to be called, I.E. 'operator.xx'.
pass
It seems like the current usage makes sense in this context.

Copy link
Member

@bjlittle bjlittle Nov 4, 2019

Choose a reason for hiding this comment

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

@stephenworsley Cool.

I guess what I'm pushing is that the whole data_op property as a concept is now defunct and should be removed. For me it's simply technical debt that should be purged, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is defunct, it allows code reuse for the tests in iris.tests.unit.maths.__init__ over multiple different operations, see also addition for example https://github.com/SciTools/iris/blob/master/lib/iris/tests/unit/analysis/maths/test_add.py

Copy link
Member

Choose a reason for hiding this comment

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

Okay, so it's generic and not specific, thanks for clarifying 👍

return operator.div
except AttributeError:
return operator.truediv
return operator.truediv
Copy link
Member

Choose a reason for hiding this comment

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

As the above comment.

@bjlittle bjlittle self-assigned this Nov 4, 2019
@bjlittle
Copy link
Member

bjlittle commented Nov 4, 2019

@stephenworsley So is this good to go? Do you have more changes in-bound?

@stephenworsley
Copy link
Contributor Author

@bjlittle Thats all I can find for the moment, If we find any others they can go in another pull request.

@bjlittle bjlittle merged commit a3519aa into SciTools:py2_strip Nov 4, 2019
@bjlittle
Copy link
Member

bjlittle commented Nov 4, 2019

@stephenworsley Great detective work, thanks 😄

@trexfeathers trexfeathers mentioned this pull request Nov 4, 2019
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