Skip to content

Commit

Permalink
Merge pull request #43 from dprada/main
Browse files Browse the repository at this point in the history
Fixing bug in strings compatibility
  • Loading branch information
dprada authored Jun 3, 2023
2 parents 34ab17d + 85a6695 commit 7f22d9d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 13 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ jobs:
# auto-activate-base: false
# show-channel-urls: true


- name: Setup conda env
uses: mamba-org/provision-with-micromamba@main
uses: mamba-org/setup-micromamba@v1
with:
environment-file: devtools/conda-envs/test_env.yaml
environment-name: test
channels: uibcdf, conda-forge, defaults

extra-specs: |
condarc: |
channels:
- uibcdf
- conda-forge
- defaults
channel_priority: strict
create-args: >-
python==${{ matrix.cfg.python-version }}
- name: Install package
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sphinx_docs_to_gh_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Sphinx docs to gh-pages
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -26,7 +26,7 @@ jobs:
with:
environment-file: devtools/conda-envs/docs_env.yaml
environment-name: docs
channels: uibcdf, conda-forge, ambermd, defaults
channels: uibcdf, conda-forge, defaults

extra-specs: |
python=="3.10"
Expand All @@ -52,5 +52,5 @@ jobs:
echo "::endgroup::"
- name: Running the Sphinx to gh-pages Action
uses: uibcdf/[email protected]-beta
uses: uibcdf/[email protected]

2 changes: 1 addition & 1 deletion devtools/README_pip.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Install

## Editable mode
pip install --editable .
pip install --no-deps --editable .

## In a github workflow using a conda env
pip install --no-deps .
Expand Down
2 changes: 0 additions & 2 deletions devtools/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ test:
dependencies: &test_dependencies
- *production_dependencies
- pytest
- pip
- pytest-cov
- codecov
- openmm
Expand Down Expand Up @@ -60,5 +59,4 @@ conda-build:
- *setup_dependencies
- anaconda-client
- conda-build
- boa

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.8.0,<3.11"
requires-python = ">=3.8.0,<3.11.0"
# Declare any run-time dependencies that should be installed with the package.
dependencies = [
"pint",
Expand Down
1 change: 1 addition & 0 deletions pyunitwizard/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.3.1b2+141.g07ee4be.dirty"
4 changes: 2 additions & 2 deletions pyunitwizard/forms/api_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def compatibility(quantity_or_unit_1: str, quantity_or_unit_2: str) -> bool:
True if they are compatible.
"""
from pyunitwizard.kernel import default_form, default_parser
from pyunitwizard import convert as _convert, compatibility as _compatibility
from pyunitwizard import convert as _convert, are_compatible as _are_compatible

tmp_quantity_or_unit_1 = _convert(quantity_or_unit_1, to_form=default_form, parser=default_parser)
tmp_quantity_or_unit_2 = _convert(quantity_or_unit_2, to_form=default_form, parser=default_parser)
return _compatibility(tmp_quantity_or_unit_1, tmp_quantity_or_unit_2)
return _are_compatible(tmp_quantity_or_unit_1, tmp_quantity_or_unit_2)

def make_quantity(value: Union[int, float, ArrayLike],
unit_name: str) -> str:
Expand Down
10 changes: 10 additions & 0 deletions pyunitwizard/tests/test_are_compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ def test_are_compatible_unyt():
q1 = puw.quantity(2.5, unyt.J/unyt.second, form="unyt")
q2 = puw.quantity(3.0, unyt.m/unyt.second, form="unyt")
assert not puw.are_compatible(q1, q2)

def test_are_compatible_string():

puw.configure.reset()
puw.configure.load_library(['pint'])

assert puw.are_compatible('0.0 degrees', '0.0 radians')

assert not puw.are_compatible('2.5 J/s', '3.0 m/s')

17 changes: 17 additions & 0 deletions pyunitwizard/tests/test_are_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ def test_are_equal_unyt_quantity():
equal = puw.are_equal(quantity_1, quantity_2)
assert not equal

def test_are_equal_string():
puw.configure.reset()
puw.configure.load_library(['pint'])

equal = puw.are_equal('0.0 degrees', '0.0 radians')
assert equal

equal = puw.are_equal('4 mm', '0.4 cm')
assert equal

equal = puw.are_equal('4 mm', '0.41 cm')
assert not equal

equal = puw.are_equal('4 m', '4 cm')
assert not equal





Expand Down

0 comments on commit 7f22d9d

Please sign in to comment.