Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ venv/
docs/build/
build/
dist/
.vscode/settings.json
1 change: 1 addition & 0 deletions src/pycel/excelformula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions src/pycel/excellib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
20 changes: 19 additions & 1 deletion tests/test_excellib.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
odd,
power,
pv,
rand,
randbetween,
round_,
rounddown,
roundup,
Expand All @@ -43,7 +45,7 @@
sumif,
sumifs,
sumproduct,
trunc,
trunc
)
from pycel.excelutil import (
DIV0,
Expand Down Expand Up @@ -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)