From 09d1d145cedf0eb6c9d0e5a6f518353ff217f677 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:20:54 +0100 Subject: [PATCH 01/11] Add Rand and RandBetween with tests --- .gitignore | 1 + src/pycel/excellib.py | 13 +++++++++++++ tests/test_excellib.py | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) 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/excellib.py b/src/pycel/excellib.py index 9c31c96e..3bdabe0e 100644 --- a/src/pycel/excellib.py +++ b/src/pycel/excellib.py @@ -405,6 +405,19 @@ def trunc(number, num_digits=0): factor = 10 ** int(num_digits) 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_ diff --git a/tests/test_excellib.py b/tests/test_excellib.py index 74f94a7c..597a0cc6 100644 --- a/tests/test_excellib.py +++ b/tests/test_excellib.py @@ -44,6 +44,8 @@ sumifs, sumproduct, trunc, + rand, + randbetween ) 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), + (5, 3), + (2.149, 3), + ) +) +def test_randbetween(low, high): + assert high >= randbetween(low, high) + assert low <= randbetween(low, high) From e4329e232182f0107710f4e8ee8fd776e9731105 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:34:16 +0100 Subject: [PATCH 02/11] Create python-package-conda.yml --- .github/workflows/python-package-conda.yml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/python-package-conda.yml diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml new file mode 100644 index 00000000..57940bdb --- /dev/null +++ b/.github/workflows/python-package-conda.yml @@ -0,0 +1,34 @@ +name: Python Package using Conda + +on: [push] + +jobs: + build-linux: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: 3.10 + - name: Add conda to system path + run: | + # $CONDA is an environment variable pointing to the root of the miniconda directory + echo $CONDA/bin >> $GITHUB_PATH + - name: Install dependencies + run: | + conda env update --file environment.yml --name base + - name: Lint with flake8 + run: | + conda install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + conda install pytest + pytest From 32b82416b700604e9c982c93be9cc9e43ae04c6d Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:48:30 +0100 Subject: [PATCH 03/11] Update python-package-conda.yml --- .github/workflows/python-package-conda.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 57940bdb..28f2e436 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -7,7 +7,6 @@ jobs: runs-on: ubuntu-latest strategy: max-parallel: 5 - steps: - uses: actions/checkout@v3 - name: Set up Python 3.10 @@ -29,6 +28,4 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest - run: | - conda install pytest - pytest + run: tox From ef36bbb719276afe44c82d3fdef4665e23326170 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:51:59 +0100 Subject: [PATCH 04/11] Update python-package-conda.yml --- .github/workflows/python-package-conda.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 28f2e436..2712505a 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -10,9 +10,9 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.10 - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: - python-version: 3.10 + python-version: ${{ matrix.python }} - name: Add conda to system path run: | # $CONDA is an environment variable pointing to the root of the miniconda directory From 726995612f27f9f206ff07b72d4e2c54713f4c83 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:55:39 +0100 Subject: [PATCH 05/11] Update python-package-conda.yml --- .github/workflows/python-package-conda.yml | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 2712505a..d0579359 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -7,25 +7,16 @@ jobs: runs-on: ubuntu-latest strategy: max-parallel: 5 + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - name: Add conda to system path - run: | - # $CONDA is an environment variable pointing to the root of the miniconda directory - echo $CONDA/bin >> $GITHUB_PATH - - name: Install dependencies - run: | - conda env update --file environment.yml --name base - - name: Lint with flake8 - run: | - conda install flake8 - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: tox + - 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 From 8bc89416a2014da2c102532720cc8e86a273042b Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Fri, 1 Jul 2022 23:57:14 +0100 Subject: [PATCH 06/11] Update python-package-conda.yml --- .github/workflows/python-package-conda.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index d0579359..fd74a593 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 5 matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] + python: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 - name: Setup Python From 15fae9d7a3666ddb247beb4435b76e991cbedb30 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Sat, 2 Jul 2022 00:05:29 +0100 Subject: [PATCH 07/11] TOX Update --- src/pycel/excellib.py | 3 ++- tests/test_excellib.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pycel/excellib.py b/src/pycel/excellib.py index 3bdabe0e..ad62e8c2 100644 --- a/src/pycel/excellib.py +++ b/src/pycel/excellib.py @@ -405,12 +405,14 @@ def trunc(number, num_digits=0): factor = 10 ** int(num_digits) 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/ @@ -418,7 +420,6 @@ def randbetween(low, high, *args): 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 597a0cc6..3cb0ee57 100644 --- a/tests/test_excellib.py +++ b/tests/test_excellib.py @@ -300,6 +300,7 @@ def test_log(expected, value): class TestMod: + def test_first_argument_validity(self): assert mod(VALUE_ERROR, 1) == VALUE_ERROR assert mod('x', 1) == VALUE_ERROR @@ -601,16 +602,16 @@ 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), - (5, 3), - (2.149, 3), ) ) def test_randbetween(low, high): From d095bfbd036d13b291321437740c5e29b2d84083 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Sat, 2 Jul 2022 00:16:28 +0100 Subject: [PATCH 08/11] Flake8 --- tests/test_excellib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_excellib.py b/tests/test_excellib.py index 3cb0ee57..0ce891bb 100644 --- a/tests/test_excellib.py +++ b/tests/test_excellib.py @@ -300,7 +300,6 @@ def test_log(expected, value): class TestMod: - def test_first_argument_validity(self): assert mod(VALUE_ERROR, 1) == VALUE_ERROR assert mod('x', 1) == VALUE_ERROR From d6937f53a84be459c0dc6c371eac4a21ef5b29ce Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Sat, 2 Jul 2022 00:22:12 +0100 Subject: [PATCH 09/11] Flake8 --- tests/test_excellib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_excellib.py b/tests/test_excellib.py index 0ce891bb..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,9 +45,7 @@ sumif, sumifs, sumproduct, - trunc, - rand, - randbetween + trunc ) from pycel.excelutil import ( DIV0, From a5a6667d11543481963996823f85a8b35077c1b3 Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Sat, 2 Jul 2022 10:06:41 +0100 Subject: [PATCH 10/11] Update python-package-conda.yml Added python 3.7 --- .github/workflows/python-package-conda.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index fd74a593..326ffaad 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 5 matrix: - python: ["3.8", "3.9", "3.10"] + python: ["3.7", "3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 - name: Setup Python From 382cd8b0b789aa709cb507a6291f5082dc5e777b Mon Sep 17 00:00:00 2001 From: Javier Boncompte G Date: Tue, 5 Jul 2022 10:50:39 +0100 Subject: [PATCH 11/11] Update excelformula.py --- src/pycel/excelformula.py | 1 + 1 file changed, 1 insertion(+) 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',