Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4d4b86a
feat: Remove angle as dimension
hpohekar Nov 5, 2024
9556b7d
feat: Remove angle as dimension 1
hpohekar Nov 5, 2024
1362d5b
feat: Support Python 3.13
hpohekar Nov 5, 2024
4a46495
feat: example fix
hpohekar Nov 5, 2024
bb3c1bf
feat: configure angle
hpohekar Nov 5, 2024
a1a3c22
feat: configure angle 1
hpohekar Nov 5, 2024
e8a2730
feat: test update 1
hpohekar Nov 5, 2024
36783df
feat: test update 2
hpohekar Nov 5, 2024
05cd020
feat: test update 3
hpohekar Nov 5, 2024
751ec36
feat: test update 4
hpohekar Nov 5, 2024
da3fe17
feat: test update 5
hpohekar Nov 5, 2024
8f75f05
feat: test update 6
hpohekar Nov 5, 2024
fb4cb48
feat: test update 7
hpohekar Nov 5, 2024
30f20fe
feat: test update 8
hpohekar Nov 5, 2024
1204aab
feat: test update 9
hpohekar Nov 5, 2024
b83d182
feat: test update 10
hpohekar Nov 5, 2024
63af28b
feat: test update 11
hpohekar Nov 5, 2024
36ba7c4
feat: test update 12
hpohekar Nov 5, 2024
fd1315a
feat: test update 13
hpohekar Nov 5, 2024
10b02fa
feat: test update 14
hpohekar Nov 5, 2024
7cb8044
feat: test update 15
hpohekar Nov 5, 2024
5ce4abe
feat: test update 16
hpohekar Nov 5, 2024
f289311
feat: test update 17
hpohekar Nov 5, 2024
7d086d0
feat: test update 18
hpohekar Nov 5, 2024
6bb2819
feat: Contributors
hpohekar Nov 5, 2024
8ab140e
feat: refactoring 1
hpohekar Nov 5, 2024
51e988d
feat: refactoring 2
hpohekar Nov 5, 2024
54952f0
feat: refactoring 3
hpohekar Nov 5, 2024
72b68bb
feat: refactoring 4
hpohekar Nov 5, 2024
2e253cf
feat: refactoring 5
hpohekar Nov 6, 2024
0247775
feat: refactoring 6
hpohekar Nov 6, 2024
a3a00c1
feat: refactoring 7
hpohekar Nov 6, 2024
50e3c94
feat: refactoring 8
hpohekar Nov 6, 2024
9b8b6a0
feat: test fix 1
hpohekar Nov 6, 2024
9166bbd
feat: test fix 2
hpohekar Nov 6, 2024
fb31f20
feat: test fix 3
hpohekar Nov 6, 2024
d398625
remove maintenance changes
hpohekar Nov 6, 2024
0135640
Merge branch 'main' into feat/configure_angles_as_dimensions
hpohekar Nov 7, 2024
28a61cf
add more tests
hpohekar Nov 7, 2024
79060b3
Merge branch 'feat/configure_angles_as_dimensions' of https://github.…
hpohekar Nov 7, 2024
907c371
update license
hpohekar Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ jobs:
uses: ansys/actions/doc-deploy-stable@v8
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* [Mainak Kundu](https://github.com/mkundu1)
* [Prithwish Mukherjee](https://github.com/prmukherj)
* [Alexander Carvalho](https://github.com/acarvalh-work)
* [Adam Boutin]([https:](https://github.com/ansaboutin))
* [Adam Boutin]([https:](https://github.com/ansaboutin))
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
11 changes: 11 additions & 0 deletions src/ansys/units/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import annotations

import os
from typing import Optional, Union

from ansys.units import (
Expand Down Expand Up @@ -99,10 +100,12 @@ def __init__(
self._dimensions = Dimensions(_dimensions)
if dimensions and self._dimensions != dimensions:
raise InconsistentDimensions()
self._dimensions = self._remove_angle_as_dim(self._dimensions)

elif dimensions:
self._dimensions = dimensions
self._name = _dim_to_units(dimensions=dimensions, system=system)
self._dimensions = self._remove_angle_as_dim(self._dimensions)
else:
self._name = ""
self._dimensions = Dimensions()
Expand All @@ -117,6 +120,14 @@ def __init__(
units=self.name
)

def _remove_angle_as_dim(self, dimensions):
if not os.getenv("PYANSYS_UNITS_ANGLE_AS_DIMENSION", None):
if BaseDimensions.ANGLE in dimensions._dimensions:
del dimensions._dimensions[BaseDimensions.ANGLE]
if BaseDimensions.SOLID_ANGLE in dimensions._dimensions:
del dimensions._dimensions[BaseDimensions.SOLID_ANGLE]
return dimensions

def _to_string(self):
"""
Creates a string representation of the unit.
Expand Down
28 changes: 25 additions & 3 deletions tests/lib_compare/test_angle_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def test_pint_angles_are_dimensionless():
assert str(angle_in_radians_dimensions) == "dimensionless"


def test_pyunits_angles_have_angle_dimensions():
def test_pyunits_angles_have_angle_dimensions(monkeypatch):
monkeypatch.setenv("PYANSYS_UNITS_ANGLE_AS_DIMENSION", "1")
from ansys.units import BaseDimensions, Dimensions
from ansys.units.quantity import Quantity

Expand Down Expand Up @@ -79,7 +80,8 @@ def test_pint_angle_and_dimensionless_are_convertible():
assert num_deg_rom_rad == util.one_degree_in_radians


def test_pyunits_angle_and_dimensionless_are_not_convertible():
def test_pyunits_angle_and_dimensionless_are_not_convertible(monkeypatch):
monkeypatch.setenv("PYANSYS_UNITS_ANGLE_AS_DIMENSION", "1")
from ansys.units.quantity import IncompatibleDimensions, Quantity

no_dim = Quantity(1.0, "")
Expand Down Expand Up @@ -169,7 +171,8 @@ def test_pint_conversion_between_Hz_and_rps_and_radians_per_second():
# mean is "This is the inevitable outcome of the way we do things."


def test_ansunits_frequency_and_angular_frequency_are_not_convertible():
def test_ansunits_frequency_and_angular_frequency_are_not_convertible(monkeypatch):
monkeypatch.setenv("PYANSYS_UNITS_ANGLE_AS_DIMENSION", "1")
from ansys.units.quantity import IncompatibleDimensions, Quantity

# ansunits avoids the pint complications by simply not allowing
Expand All @@ -180,3 +183,22 @@ def test_ansunits_frequency_and_angular_frequency_are_not_convertible():
rad_per_s = Quantity(1.0, "radian s^-1")
with pytest.raises(IncompatibleDimensions):
rad_per_s.to("Hz")


def test_degree_addition():
import ansys.units as pyunits

degree = pyunits.Quantity(1.0, "degree")
assert not degree.dimensions
assert degree.is_dimensionless
assert degree + 1 == pyunits.Quantity(58.29577951308232, "degree")


def test_radian_addition():
import ansys.units as pyunits

radian = pyunits.Quantity(1.0, "radian")
assert not radian.dimensions
assert radian.is_dimensionless
assert radian + 1 == pyunits.Quantity(2.0, "radian")
assert (radian + 1).to("degree") == pyunits.Quantity(114.59155902616465, "degree")
3 changes: 2 additions & 1 deletion tests/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ def test_quantity_table():
assert api_test.units == Unit("kg m^-1.5 s^-2.5 A^3 cd W^2 K^-2")


def testing_units_to_dimensions():
def testing_units_to_dimensions(monkeypatch):
monkeypatch.setenv("PYANSYS_UNITS_ANGLE_AS_DIMENSION", "1")
print(f"{'*' * 25} {testing_units_to_dimensions.__name__} {'*' * 25}")
dims = BaseDimensions

Expand Down
Loading