Skip to content

Commit

Permalink
Merge pull request #6 from brian-team/new_version
Browse files Browse the repository at this point in the history
Modify tests
  • Loading branch information
mstimberg authored Aug 25, 2024
2 parents 9737ce6 + 13fa0a9 commit a6e9fe3
Show file tree
Hide file tree
Showing 34 changed files with 457 additions and 802 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish
on: [push, pull_request]

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-18.04
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pytest-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: Run tests
run: |
pytest
pytest --doctest-modules
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# version
_version.py
3 changes: 0 additions & 3 deletions unitSI/__init__.py → QuantSI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@
Gwatt,
Twatt,
)
from .unitsafefunctions import *
from .unitsafefunctions import __all__ as unitsafefunctions_all

from .fundamentalunits import *
from .fundamentalunits import __all__ as fundamentalunits_all
Expand Down Expand Up @@ -371,6 +369,5 @@
"Gwatt",
"Twatt",
]
__all__.extend(unitsafefunctions_all)
__all__.extend(fundamentalunits_all)
__all__.extend(stdunits_all)
2 changes: 1 addition & 1 deletion unitSI/allunits.py → QuantSI/allunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7922,7 +7922,7 @@ class _Celsius:
"ambiguities when mixed with absolute temperatures defined"
"in Kelvin. Directly use 'kelvin' when you are only"
"interested in temperature differences, and add the"
"'zero_celsius' constant from the brian2.units.constants"
"'zero_celsius' constant from the QuantSI.constants"
"module if you want to convert a temperature from Celsius to"
"Kelvin."
)
Expand Down
15 changes: 15 additions & 0 deletions QuantSI/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

def pytest_collection_modifyitems(config, items):
# List of function names whose doctests should be skipped
functions_to_skip = {
"QuantSI.fundamentalunits.Quantity.fill",
"QuantSI.fundamentalunits.Quantity.trace",
}

for item in items:
function_name = item.location[2] # The third element often contains the name in doctests
# Skip specific functions' doctests
if any(fn in function_name for fn in functions_to_skip):
item.add_marker(pytest.mark.skip(reason="Skipping doctest for specific function due to known documentation issues"))

4 changes: 2 additions & 2 deletions unitSI/constants.py → QuantSI/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
r"""
A module providing some physical units as `Quantity` objects. Note that these
units are not imported by wildcard imports (e.g. `from brian2 import *`), they
units are not imported by wildcard imports (e.g. `from QuantSI.constants import *`), they
have to be imported explicitly. You can use ``import ... as ...`` to import them
with shorter names, e.g.::
from brian2.units.constants import faraday_constant as F
from QuantSI.constants import faraday_constant as F
The available constants are:
Expand Down
90 changes: 20 additions & 70 deletions unitSI/fundamentalunits.py → QuantSI/fundamentalunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def fail_for_dimension_mismatch(
return dim1, dim2

# We do another check here, this should allow Brian1 units to pass as
# having the same dimensions as a Brian2 unit
# having the same dimensions as a QuantSI unit
if dim1 == dim2:
return dim1, dim2

Expand Down Expand Up @@ -656,7 +656,7 @@ def get_or_create_dimension(*args, **kwds):
--------
The following are all definitions of the dimensions of force
>>> from brian2 import *
>>> from QuantSI import *
>>> get_or_create_dimension(length=1, mass=1, time=-2)
metre * kilogram * second ** -2
>>> get_or_create_dimension(m=1, kg=1, s=-2)
Expand Down Expand Up @@ -879,13 +879,13 @@ def in_unit(x, u, precision=None):
Examples
--------
>>> from brian2 import *
>>> from QuantSI import *
>>> in_unit(3 * volt, mvolt)
'3000. mV'
>>> in_unit(123123 * msecond, second, 2)
'123.12 s'
>>> in_unit(10 * uA/cm**2, nA/um**2)
'1.00000000e-04 nA/(um^2)'
'1.e-04 nA/(um^2)'
>>> in_unit(10 * mV, ohm * amp)
'0.01 ohm A'
>>> in_unit(10 * nS, ohm) # doctest: +NORMALIZE_WHITESPACE
Expand Down Expand Up @@ -925,7 +925,7 @@ def in_best_unit(x, precision=None):
Examples
--------
>>> from brian2.units import *
>>> from QuantSI.allunits import *
>>> in_best_unit(0.00123456 * volt)
'1.23456 mV'
>>> in_best_unit(0.00123456 * volt, 2)
Expand Down Expand Up @@ -970,7 +970,7 @@ def quantity_with_dimensions(floatval, dims):
Examples
--------
>>> from brian2 import *
>>> from QuantSI import *
>>> quantity_with_dimensions(0.001, volt.dim)
1. * mvolt
Expand Down Expand Up @@ -1013,7 +1013,7 @@ class Quantity(np.ndarray):
Examples
--------
>>> from brian2 import *
>>> from QuantSI import *
>>> I = 3 * amp # I is a Quantity object
>>> R = 2 * ohm # same for R
>>> I * R
Expand All @@ -1028,9 +1028,9 @@ class Quantity(np.ndarray):
DimensionMismatchError: Addition, dimensions were (A) (m^2 kg s^-3 A^-2)
>>> Is = np.array([1, 2, 3]) * amp
>>> Is * R
array([ 2., 4., 6.]) * volt
array([2., 4., 6.]) * volt
>>> np.asarray(Is * R) # gets rid of units
array([ 2., 4., 6.])
array([2., 4., 6.])
See also
--------
Expand Down Expand Up @@ -1280,7 +1280,7 @@ def with_dimensions(value, *args, **keywords):
--------
All of these define an equivalent `Quantity` object:
>>> from brian2 import *
>>> from QuantSI import *
>>> Quantity.with_dimensions(2, get_or_create_dimension(length=1))
2. * metre
>>> Quantity.with_dimensions(2, length=1)
Expand Down Expand Up @@ -1357,8 +1357,8 @@ def in_unit(self, u, precision=None, python_code=False):
Examples
--------
>>> from brian2.units import *
>>> from brian2.units.stdunits import *
>>> from QuantSI.allunits import *
>>> from QuantSI.stdunits import *
>>> x = 25.123456 * mV
>>> x.in_unit(volt)
'0.02512346 V'
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def in_best_unit(self, precision=None, python_code=False, *regs):
Examples
--------
>>> from brian2.units import *
>>> from QuantSI.allunits import *
>>> x = 0.00123456 * volt
Expand Down Expand Up @@ -1652,59 +1652,8 @@ def __format__(self, format_spec):
return super().__format__(format_spec)

#### Mathematic methods ####

cumsum = wrap_function_keep_dimensions(np.ndarray.cumsum)
diagonal = wrap_function_keep_dimensions(np.ndarray.diagonal)
max = wrap_function_keep_dimensions(np.ndarray.max)
mean = wrap_function_keep_dimensions(np.ndarray.mean)
min = wrap_function_keep_dimensions(np.ndarray.min)
ptp = wrap_function_keep_dimensions(np.ndarray.ptp)

# To work around an issue in matplotlib 1.3.1 (see
# https://github.com/matplotlib/matplotlib/pull/2591), we make `ravel`
# return a unitless array and emit a warning explaining the issue.
use_matplotlib_units_fix = False
try:
import matplotlib

if matplotlib.__version__ == "1.3.1":
use_matplotlib_units_fix = True
except ImportError:
pass

if use_matplotlib_units_fix:

def ravel(self, *args, **kwds):
# Note that we don't use Brian's logging system here as we don't want
# the unit system to depend on other parts of Brian
warn(
"As a workaround for a bug in matplotlib 1.3.1, calling "
'"ravel()" on a quantity will return unit-less values. If you '
"get this warning during plotting, consider removing the units "
"before plotting, e.g. by dividing by the unit. If you are "
'explicitly calling "ravel()", consider using "flatten()" '
"instead."
)
return np.asarray(self).ravel(*args, **kwds)

ravel._arg_units = [None]
ravel._return_unit = 1
ravel.__name__ = np.ndarray.ravel.__name__
ravel.__doc__ = np.ndarray.ravel.__doc__
else:
ravel = wrap_function_keep_dimensions(np.ndarray.ravel)

round = wrap_function_keep_dimensions(np.ndarray.round)
std = wrap_function_keep_dimensions(np.ndarray.std)
sum = wrap_function_keep_dimensions(np.ndarray.sum)
trace = wrap_function_keep_dimensions(np.ndarray.trace)
var = wrap_function_change_dimensions(np.ndarray.var, lambda ar, d: d**2)
all = wrap_function_remove_dimensions(np.ndarray.all)
any = wrap_function_remove_dimensions(np.ndarray.any)
nonzero = wrap_function_remove_dimensions(np.ndarray.nonzero)
argmax = wrap_function_remove_dimensions(np.ndarray.argmax)
argmin = wrap_function_remove_dimensions(np.ndarray.argmin)
argsort = wrap_function_remove_dimensions(np.ndarray.argsort)
trace = wrap_function_keep_dimensions(np.trace)

def fill(self, values): # pylint: disable=C0111
fail_for_dimension_mismatch(self, values, "fill")
Expand Down Expand Up @@ -1836,8 +1785,8 @@ class Unit(Quantity):
purposes. So for example, to define the newton metre, you
write
>>> from brian2 import *
>>> from brian2.units.allunits import newton
>>> from QuantSI import *
>>> from QuantSI.allunits import newton
>>> Nm = newton * metre
You can then do
Expand Down Expand Up @@ -2396,7 +2345,7 @@ def register_new_unit(u):
Examples
--------
>>> from brian2 import *
>>> from QuantSI import *
>>> 2.0*farad/metre**2
2. * metre ** -4 * kilogram ** -1 * second ** 4 * amp ** 2
>>> register_new_unit(pfarad / mmetre**2)
Expand Down Expand Up @@ -2468,7 +2417,8 @@ def check_units(**au):
Examples
--------
>>> from brian2.units import *
>>> from QuantSI import mV, nA
>>> from QuantSI.allunits import *
>>> @check_units(I=amp, R=ohm, wibble=metre, result=volt)
... def getvoltage(I, R, **k):
... return I*R
Expand Down Expand Up @@ -2541,7 +2491,7 @@ def check_units(**au):
>>> multiply_sum(3*nA, 4*mV, 5*nA) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
brian2.units.fundamentalunits.DimensionMismatchError: Function 'multiply_sum' expected the same arguments for arguments 'summand_1', 'summand_2', but argument 'summand_1' has unit V, while argument 'summand_2' has unit A.
QuantSI.fundamentalunits.DimensionMismatchError: Function 'multiply_sum' expected the same arguments for arguments 'summand_1', 'summand_2', but argument 'summand_1' has unit V, while argument 'summand_2' has unit A.
Raises
------
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a6e9fe3

Please sign in to comment.