Example #1
0
 def test_sin(self):
     self._test1(np.sin, (np.arange(0, pi/2, pi/4) * self.ureg.dimensionless,
                          np.arange(0, pi/2, pi/4) * self.ureg.radian,
                          np.arange(0, pi/2, pi/4) * self.ureg.mm / self.ureg.m
                         ), (self.ureg.m, ), '', results=(None, None, np.sin(np.arange(0, pi/2, pi/4)*0.001)))
     self._test1(np.sin, (np.rad2deg(np.arange(0, pi/2, pi/4)) * self.ureg.degrees,
                         ), results=(np.sin(np.arange(0, pi/2, pi/4)), ))
Example #2
0
 def test_sin(self):
     self._test1(np.sin, (np.arange(0, pi/2, pi/4) * self.ureg.dimensionless,
                          np.arange(0, pi/2, pi/4) * self.ureg.radian,
                          np.arange(0, pi/2, pi/4) * self.ureg.mm / self.ureg.m
                         ), (1*self.ureg.m, ), '', results=(None, None, np.sin(np.arange(0, pi/2, pi/4)*0.001)))
     self._test1(np.sin, (np.rad2deg(np.arange(0, pi/2, pi/4)) * self.ureg.degrees,
                         ), results=(np.sin(np.arange(0, pi/2, pi/4)), ))
Example #3
0
 def test_issue45b(self):
     self.assertAlmostEqual(
         np.sin([np.pi / 2] * ureg.m / ureg.m),
         np.sin([np.pi / 2] * ureg.dimensionless),
     )
     self.assertAlmostEqual(
         np.sin([np.pi / 2] * ureg.cm / ureg.m),
         np.sin([np.pi / 2] * ureg.dimensionless * 0.01),
     )
Example #4
0
 def test_issue45b(self):
     helpers.assert_quantity_almost_equal(
         np.sin([np.pi / 2] * ureg.m / ureg.m),
         np.sin([np.pi / 2] * ureg.dimensionless),
     )
     helpers.assert_quantity_almost_equal(
         np.sin([np.pi / 2] * ureg.cm / ureg.m),
         np.sin([np.pi / 2] * ureg.dimensionless * 0.01),
     )
Example #5
0
 def test_issue45b(self):
     ureg = UnitRegistry()
     self.assertAlmostEqual(np.sin([np.pi/2] * ureg.m / ureg.m ), np.sin([np.pi/2] * ureg.dimensionless))
     self.assertAlmostEqual(np.sin([np.pi/2] * ureg.cm / ureg.m ), np.sin([np.pi/2] * ureg.dimensionless * 0.01))
Example #6
0
        ureg.define("_home = 4700 * kWh / year")
        with self.assertRaises(AttributeError):
            home_elec_power = 1 * ureg._home  # noqa: F841
        # ... or with *only* underscores
        ureg.define("_ = 45 * km")
        with self.assertRaises(AttributeError):
            one_blank = 1 * ureg._  # noqa: F841


try:

    @pytest.mark.skipif(np is None, reason="NumPy is not available")
    @pytest.mark.parametrize(
        "callable",
        [
            lambda x: np.sin(x / x.units),  # Issue 399
            lambda x: np.cos(x / x.units),  # Issue 399
            np.isfinite,  # Issue 481
            np.shape,  # Issue 509
            np.size,  # Issue 509
            np.sqrt,  # Issue 622
            lambda x: x.mean(),  # Issue 678
            lambda x: x.copy(),  # Issue 678
            np.array,
            lambda x: x.conjugate,
        ],
    )
    @pytest.mark.parametrize(
        "q",
        [
            pytest.param(ureg.Quantity(1, "m"), id="python scalar int"),
Example #7
0
 def test_issue45b(self):
     ureg = UnitRegistry()
     self.assertAlmostEqual(np.sin([np.pi / 2] * ureg.m / ureg.m),
                            np.sin([np.pi / 2] * ureg.dimensionless))
     self.assertAlmostEqual(np.sin([np.pi / 2] * ureg.cm / ureg.m),
                            np.sin([np.pi / 2] * ureg.dimensionless * 0.01))