diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml new file mode 100644 index 00000000..326ffaad --- /dev/null +++ b/.github/workflows/python-package-conda.yml @@ -0,0 +1,22 @@ +name: Python Package using Conda + +on: [push] + +jobs: + build-linux: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + matrix: + python: ["3.7", "3.8", "3.9", "3.10"] + steps: + - uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: Install tox and any other packages + run: pip install tox + - name: Run tox + # Run tox using the version of Python in `PATH` + run: tox -e py diff --git a/.gitignore b/.gitignore index 3305fc93..4f77975c 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ venv/ docs/build/ build/ dist/ +.vscode/settings.json diff --git a/src/pycel/excelformula.py b/src/pycel/excelformula.py index 23ab237a..a8031b63 100644 --- a/src/pycel/excelformula.py +++ b/src/pycel/excelformula.py @@ -525,6 +525,7 @@ class ExcelFormula: default_modules = ( 'pycel.excellib', 'pycel.lib.date_time', + 'pycel.lib.financial', 'pycel.lib.engineering', 'pycel.lib.information', 'pycel.lib.logical', diff --git a/src/pycel/excellib.py b/src/pycel/excellib.py index 9c31c96e..ad62e8c2 100644 --- a/src/pycel/excellib.py +++ b/src/pycel/excellib.py @@ -406,6 +406,20 @@ def trunc(number, num_digits=0): return int(number * factor) / factor +@excel_math_func +def rand(*args): + # Excel reference: https://support.microsoft.com/en-us/office/ + # rand-function-4cbfa695-8869-4788-8d90-021ea9f5be73 + return np.random.random() + + +@excel_math_func +def randbetween(low, high, *args): + # Excel reference: https://support.microsoft.com/en-us/office/ + # randbetween-function-4cc7f0d1-87dc-4eb7-987f-a469ab381685 + return np.random.randint(low, high) + + # Older mappings for excel functions that match Python built-in and keywords x_abs = abs_ xatan2 = atan2_ diff --git a/tests/test_excellib.py b/tests/test_excellib.py index 74f94a7c..5085f1a2 100644 --- a/tests/test_excellib.py +++ b/tests/test_excellib.py @@ -35,6 +35,8 @@ odd, power, pv, + rand, + randbetween, round_, rounddown, roundup, @@ -43,7 +45,7 @@ sumif, sumifs, sumproduct, - trunc, + trunc ) from pycel.excelutil import ( DIV0, @@ -598,3 +600,19 @@ def test_sum_(): assert DIV0 == sum_(DIV0) assert DIV0 == sum_((2, DIV0)) + + +def test_rand(): + assert 1 >= rand() + assert 0 <= rand() + + +@pytest.mark.parametrize( + 'low, high', ( + (2, 5), + (3, 4), + ) +) +def test_randbetween(low, high): + assert high >= randbetween(low, high) + assert low <= randbetween(low, high)