WIP: floordiv, mod, divmod #943#946
Closed
westurner wants to merge 2 commits into
Closed
Conversation
Contributor
Author
|
The e.g. |
Contributor
Author
Here's the output from `pytest ./test_quantity.py`:$ pytest test_quantity.py
==================================================================== test session starts =====================================================================
platform linux -- Python 3.6.8, pytest-5.3.0, py-1.8.0, pluggy-0.12.0
rootdir: /home/wturner/-wrk/-ce37/woodworking/src/pint
collected 436 items
test_quantity.py .....................................FFF............................................................................................. [ 30%]
...................................................................................................................................................... [ 64%]
...................................................................................................................................................... [ 99%]
... [100%]
========================================================================== FAILURES ==========================================================================
______________________________________________________________ TestQuantityBasicMath.test_float ______________________________________________________________
self = <pint.testsuite.test_quantity.TestQuantityBasicMath testMethod=test_float>
def test_float(self):
> self._test_numeric(1.0, self._test_not_inplace)
test_quantity.py:798:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_quantity.py:794: in _test_numeric
self._test_quantity_divmod()
test_quantity.py:785: in _test_quantity_divmod
self._test_quantity_divmod_one("10*meter", 3)
test_quantity.py:752: in _test_quantity_divmod_one
self.assertEqual(q, math.floor(q))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Quantity(3, 'meter')>
def __float__(self):
if self.dimensionless:
return float(self._convert_magnitude_not_inplace(UnitsContainer()))
# else: # ( for math.floor !? )
# return float(self._magnitude)
> raise DimensionalityError(self._units, "dimensionless")
E pint.errors.DimensionalityError: Cannot convert from 'meter' to 'dimensionless'
../quantity.py:669: DimensionalityError
____________________________________________________________ TestQuantityBasicMath.test_fraction _____________________________________________________________
self = <pint.testsuite.test_quantity.TestQuantityBasicMath testMethod=test_fraction>
def test_fraction(self):
import fractions
> self._test_numeric(fractions.Fraction(1, 1), self._test_not_inplace)
test_quantity.py:803:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_quantity.py:794: in _test_numeric
self._test_quantity_divmod()
test_quantity.py:785: in _test_quantity_divmod
self._test_quantity_divmod_one("10*meter", 3)
test_quantity.py:752: in _test_quantity_divmod_one
self.assertEqual(q, math.floor(q))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Quantity(3, 'meter')>
def __float__(self):
if self.dimensionless:
return float(self._convert_magnitude_not_inplace(UnitsContainer()))
# else: # ( for math.floor !? )
# return float(self._magnitude)
> raise DimensionalityError(self._units, "dimensionless")
E pint.errors.DimensionalityError: Cannot convert from 'meter' to 'dimensionless'
../quantity.py:669: DimensionalityError
_____________________________________________________________ TestQuantityBasicMath.test_nparray _____________________________________________________________
self = <pint.testsuite.test_quantity.TestQuantityBasicMath testMethod=test_nparray>
@helpers.requires_numpy()
def test_nparray(self):
> self._test_numeric(np.ones((1, 3)), self._test_inplace)
test_quantity.py:807:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_quantity.py:792: in _test_numeric
self._test_quantity_floordiv(unit, self._test_not_inplace)
test_quantity.py:725: in _test_quantity_floordiv
func(op.ifloordiv, unit * 10, 3, 3 * unit, unit)
test_quantity.py:650: in _test_not_inplace
self.assertQuantityAlmostEqual(value1, value1_cpy)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pint.testsuite.test_quantity.TestQuantityBasicMath testMethod=test_nparray>, first = array([[3., 3., 3.]]), second = array([[10., 10., 10.]])
rtol = 1e-07, atol = 0, msg = 'Comparing array([[3., 3., 3.]]) and array([[10., 10., 10.]]). '
def assertQuantityAlmostEqual(self, first, second, rtol=1e-07, atol=0, msg=None):
if msg is None:
msg = "Comparing %r and %r. " % (first, second)
m1, m2 = self._get_comparable_magnitudes(first, second, msg)
if isinstance(m1, ndarray) or isinstance(m2, ndarray):
> np.testing.assert_allclose(m1, m2, rtol=rtol, atol=atol, err_msg=msg)
E AssertionError:
E Not equal to tolerance rtol=1e-07, atol=0
E Comparing array([[3., 3., 3.]]) and array([[10., 10., 10.]]).
E Mismatch: 100%
E Max absolute difference: 7.
E Max relative difference: 0.7
E x: array([[3., 3., 3.]])
E y: array([[10., 10., 10.]])
__init__.py:114: AssertionError
====================================================================== warnings summary ======================================================================
pint/testsuite/test_quantity.py::TestQuantity::test_convert_numpy
/home/wturner/-wrk/-ce37/woodworking/src/pint/pint/quantity.py:200: BehaviorChangeWarning: The way Pint handles NumPy operations has changed with the
implementation of NEP 18. Unimplemented NumPy operations will now fail instead of making
assumptions about units. Some functions, eg concat, will now return Quanties with units, where
they returned ndarrays previously. See https://github.com/hgrecco/pint/pull/905.
To hide this warning, wrap your first creation of an array Quantity with
warnings.catch_warnings(), like the following:
import numpy as np
import warnings
from pint import Quantity
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Quantity([])
To disable the new behavior, see
https://www.numpy.org/neps/nep-0018-array-function-protocol.html#implementation
warnings.warn(array_function_change_msg, BehaviorChangeWarning)
pint/testsuite/test_quantity.py::TestCompareZero::test_equal_zero_NP
pint/testsuite/test_quantity.py::TestCompareZero::test_equal_zero_NP
/home/wturner/-wrk/-ce37/woodworking/src/pint/pint/compat.py:143: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
out = first == second
-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================================================= 3 failed, 433 passed, 3 warnings in 5.58s ==========================================================
# pytest test_quantity.py |
Contributor
|
@westurner Now that #954 is merged, |
Contributor
Author
|
Owner
|
@westurner Any chance of getting this fixed in the upcoming days? It would be great to include this in 0.10 |
Contributor
Author
|
I am away from the computer for the next day. Please feel free to pull and
modify.
The previous questions in the PR and,
I'm not sure that the hasattr() check approach is correct, and the `__r*__`
methods could probably just swap arguments and call the same @classmethod /
@staticmethod?
…On Mon, Dec 30, 2019, 5:03 PM Hernan Grecco ***@***.***> wrote:
@westurner <https://github.com/westurner> Any chance of getting this
fixed in the upcoming days? It would be great to include this in 0.10
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#946?email_source=notifications&email_token=AAAMNS5YPQWWU6PCLDRTTX3Q3J45VA5CNFSM4J6HV4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH3MU3Y#issuecomment-569821807>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAMNS5H277VEQE45L764ZDQ3J45VANCNFSM4J6HV4PA>
.
|
|
Please do not merge this PR. I is wrong, as I commented at the corresponding issue. |
Collaborator
|
Closing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
black -t py36 . && isort -rc . && flake8with no errors...
This is surely the wrong way to do this:
The
hasattr(obj, 'dimensionless')check is probably not correct?IDK how to get math.floor to return a quantity. Modifying
__float__to return a non-Quantity float results in further errors.Why is floordiv returning 10.0 in TestQuantityBasicMath.test_nparray?
@pytest.mark.parametrize might make it easier to identify the test failures by creating named test cases for each combination. There's probably a historical or a technical reason for the current approach?
This is already beyond my level of comprehension of the pint internal API. I'd be grateful for any help or "just move" https://stackoverflow.com/questions/14947789/github-clone-from-pull-request