From 10b0c84ddb28a1dd9c2bd58e9b6af148dbd6c9dc Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Thu, 25 Jan 2024 14:54:00 +0000 Subject: [PATCH 01/14] :bug: GenericArrayFormatter and IntArrayFormatter renamed - now private methods -> check with pandas devs if there is a better way --- src/njab/pandas/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/njab/pandas/__init__.py b/src/njab/pandas/__init__.py index a70405f..4d7a618 100644 --- a/src/njab/pandas/__init__.py +++ b/src/njab/pandas/__init__.py @@ -16,14 +16,15 @@ def set_pandas_options() -> None: pd.options.display.min_rows = 20 pd.options.display.float_format = '{:,.3f}'.format - class IntArrayFormatter(pf.GenericArrayFormatter): + # https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/format.py#L1475 + class IntArrayFormatter(pf._GenericArrayFormatter): def _format_strings(self): formatter = self.formatter or '{:,d}'.format fmt_values = [formatter(x) for x in self.values] return fmt_values - pf.IntArrayFormatter = IntArrayFormatter + pf._IntArrayFormatter = IntArrayFormatter def replace_with(string_key: str, From 372b0fdacadccee457fb3be975dff63ac71b5815 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 31 Jan 2024 17:52:40 +0100 Subject: [PATCH 02/14] :art: try to make the new syntax in pandas 2.2 backward compatible - styler supports option for thousands separator - not available for default display? --- src/njab/pandas/__init__.py | 18 ++++++++++++++---- test/test_pandas.py | 8 ++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/test_pandas.py diff --git a/src/njab/pandas/__init__.py b/src/njab/pandas/__init__.py index 4d7a618..5c4bfda 100644 --- a/src/njab/pandas/__init__.py +++ b/src/njab/pandas/__init__.py @@ -15,16 +15,26 @@ def set_pandas_options() -> None: pd.options.display.max_rows = 30 pd.options.display.min_rows = 20 pd.options.display.float_format = '{:,.3f}'.format + # https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.describe_option.html#pandas.describe_option + pd.options.styler.format.thousands = ',' + # # https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/format.py#L1475 + # Originally found: https://stackoverflow.com/a/29663750/9684872 - # https://github.com/pandas-dev/pandas/blob/main/pandas/io/formats/format.py#L1475 - class IntArrayFormatter(pf._GenericArrayFormatter): + try: + base_class = pf.GenericArrayFormatter + except AttributeError: + base_class = pf._GenericArrayFormatter + + class IntArrayFormatter(base_class): def _format_strings(self): formatter = self.formatter or '{:,d}'.format fmt_values = [formatter(x) for x in self.values] return fmt_values - - pf._IntArrayFormatter = IntArrayFormatter + try: + pf.IntArrayFormatter = IntArrayFormatter + except AttributeError: + pf._IntArrayFormatter = IntArrayFormatter def replace_with(string_key: str, diff --git a/test/test_pandas.py b/test/test_pandas.py new file mode 100644 index 0000000..b117f72 --- /dev/null +++ b/test/test_pandas.py @@ -0,0 +1,8 @@ +import pandas as pd +import njab + + +def test_thousands_display(): + njab.pandas.set_pandas_options() + s = pd.Series([1_000_000]) + assert str(s)[4:13] == '1,000,000' From 79b0c5ad5c805c31b643b856eb448445b32097a8 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Fri, 2 Feb 2024 11:38:39 +0000 Subject: [PATCH 03/14] :art: format with yapf --- src/njab/pandas/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/njab/pandas/__init__.py b/src/njab/pandas/__init__.py index 5c4bfda..b7fc484 100644 --- a/src/njab/pandas/__init__.py +++ b/src/njab/pandas/__init__.py @@ -31,6 +31,7 @@ def _format_strings(self): formatter = self.formatter or '{:,d}'.format fmt_values = [formatter(x) for x in self.values] return fmt_values + try: pf.IntArrayFormatter = IntArrayFormatter except AttributeError: From 5e607dd4ec58754039b2e8b66feac72b956c2de9 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Fri, 2 Feb 2024 11:59:57 +0000 Subject: [PATCH 04/14] :bug: try to add all version to tox (which are in Github Action) --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 7838a47..07ba0a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -88,7 +88,7 @@ source = ######################### [tox:tox] -envlist = py38 +envlist = py38,py39,py310,py311 isolated_build = True [testenv] From 9dab04db96806759daf9e244bae553f630721a25 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Fri, 2 Feb 2024 12:16:43 +0000 Subject: [PATCH 05/14] :bug: missing attribute can always be set -> check first it exits --- src/njab/pandas/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/njab/pandas/__init__.py b/src/njab/pandas/__init__.py index b7fc484..9af3096 100644 --- a/src/njab/pandas/__init__.py +++ b/src/njab/pandas/__init__.py @@ -33,6 +33,7 @@ def _format_strings(self): return fmt_values try: + pf.IntArrayFormatter pf.IntArrayFormatter = IntArrayFormatter except AttributeError: pf._IntArrayFormatter = IntArrayFormatter From f546e76e6c6e9f775622257b9dfb2004d20a5f36 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Thu, 22 Feb 2024 13:24:32 +0100 Subject: [PATCH 06/14] :sparkles: Add wheels, distributions and pypi upload (#5) * :sparkles: Add wheels, distributions and pypi upload * :bug: pure python package does not need wheels - python code runs as is (no binaries needed) * :art: only build wheels for main repository * :arrow_up: checkout v4 * :arrow_up: update python action --- .github/workflows/packaging.yml | 76 +++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 3255f0d..1a12d3e 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -10,7 +10,7 @@ jobs: name: Check formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4.0.0 with: @@ -26,7 +26,7 @@ jobs: name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4.0.0 with: @@ -52,9 +52,9 @@ jobs: - version: "3.8" toxenv: "py38" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v4.0.0 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python.version }} @@ -72,3 +72,71 @@ jobs: papermill log_reg.ipynb --help-notebook papermill explorative_analysis.ipynb explorative_analysis_tested.ipynb papermill log_reg.ipynb log_reg_tested.ipynb + + build_source_dist: + name: Build source distribution + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Install build + run: python -m pip install build + + - name: Run build + run: python -m build --sdist + + - uses: actions/upload-artifact@v3 + with: + path: ./dist/*.tar.gz + + # build_wheels: + # name: Build wheels on ${{ matrix.os }} + # if: github.ref == 'refs/heads/main' + # runs-on: ${{ matrix.os }} + # strategy: + # matrix: + # os: [ubuntu-20.04, windows-2019, macOS-10.15] + + # steps: + # - uses: actions/checkout@v3 + + # - uses: actions/setup-python@v5 + # with: + # python-version: "3.10" + + # - name: Install cibuildwheel + # run: python -m pip install cibuildwheel==2.3.1 + + # - name: Build wheels + # run: python -m cibuildwheel --output-dir wheels + + # - uses: actions/upload-artifact@v3 + # with: + # path: ./wheels/*.whl + + publish: + name: Publish package + if: startsWith(github.ref, 'refs/tags') + needs: + - format + - lint + - test + - build_source_dist + # - build_wheels + runs-on: ubuntu-latest + + steps: + - uses: actions/download-artifact@v4 + with: + name: artifact + path: ./dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file From f6002fded423896fe8082775a3c3c9250366c3aa Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 22 Feb 2024 14:04:55 +0100 Subject: [PATCH 07/14] :bug: fix READTHEDOCS build --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 8935ab5..fbc9e74 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,7 @@ 'sphinx.ext.viewcode', 'myst_nb', 'sphinx.ext.napoleon', - 'sphinx_new_tab_link', + # 'sphinx_new_tab_link', # create infinite loop error ] # https://myst-nb.readthedocs.io/en/latest/computation/execute.html From b30cbc8a1d2163854e05ce832b1831fc45d83ce9 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 22 Feb 2024 14:25:01 +0100 Subject: [PATCH 08/14] :bookmark: version 0.0.4 (pandas 2.2 compability) - minor refactors --- CHANGELOG.md | 5 +++++ setup.cfg | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e7131c..d0d4207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Version 0.0.4 + +- [x] Add `pandas` styling compability with pandas v2.2 (PR #4) +- [x] moved `get_lr_multiplicative_decomposition` function to package [78b0c2](https://github.com/RasmussenLab/njab/commit/78b0c27c3ab11489fb81ca320e03485cdc0b1344) + ## Version 0.0.3 - [x] Add pandas styling diff --git a/setup.cfg b/setup.cfg index 07ba0a7..534cfde 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = njab -version = 0.0.3 +version = 0.0.4 description = not Just Another Biomarker long_description = file: README.md long_description_content_type = text/markdown From 9e2a68057c8148c0c8a25452ec7f0aea18876f3a Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 22 Feb 2024 14:46:12 +0100 Subject: [PATCH 09/14] :art::bug: use latest python action everywhere, build dists --- .github/workflows/packaging.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 1a12d3e..04303f6 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4.0.0 + - uses: actions/setup-python@v5 with: python-version: "3.10" @@ -28,7 +28,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4.0.0 + - uses: actions/setup-python@v5 with: python-version: "3.10" @@ -103,7 +103,7 @@ jobs: # os: [ubuntu-20.04, windows-2019, macOS-10.15] # steps: - # - uses: actions/checkout@v3 + # - uses: actions/checkout@v4 # - uses: actions/setup-python@v5 # with: From 52e47d02d85f8ed3a2c7fdd7ef222bb46e4ec937 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 22 Feb 2024 19:01:47 +0100 Subject: [PATCH 10/14] :bug: also distribution job for tags --- .github/workflows/packaging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 04303f6..4b681c5 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -75,7 +75,7 @@ jobs: build_source_dist: name: Build source distribution - if: github.ref == 'refs/heads/main' + if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -96,7 +96,7 @@ jobs: # build_wheels: # name: Build wheels on ${{ matrix.os }} - # if: github.ref == 'refs/heads/main' + # if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags') # runs-on: ${{ matrix.os }} # strategy: # matrix: From e873a6d34869051f19f8ca8346c2c015e5ddbad9 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 23 Feb 2024 09:47:27 +0100 Subject: [PATCH 11/14] :bug: align upload and download version of artifacts - v4 download not compatible with version 3 upload --- .github/workflows/packaging.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index 4b681c5..45f6dc1 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -90,7 +90,7 @@ jobs: - name: Run build run: python -m build --sdist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: ./dist/*.tar.gz @@ -115,7 +115,7 @@ jobs: # - name: Build wheels # run: python -m cibuildwheel --output-dir wheels - # - uses: actions/upload-artifact@v3 + # - uses: actions/upload-artifact@v4 # with: # path: ./wheels/*.whl From ee29a2dd997da4f6ff4decda279cf889d41d4528 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Fri, 23 Feb 2024 11:11:33 +0100 Subject: [PATCH 12/14] :bug: exclude latest version of extension sphinx-new-tab-link - recurssion error introduced into 0.2.2 of sphinx-new-tab-link: https://github.com/ftnext/sphinx-new-tab-link/issues/11 (#6) --- docs/conf.py | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index fbc9e74..8935ab5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,7 @@ 'sphinx.ext.viewcode', 'myst_nb', 'sphinx.ext.napoleon', - # 'sphinx_new_tab_link', # create infinite loop error + 'sphinx_new_tab_link', ] # https://myst-nb.readthedocs.io/en/latest/computation/execute.html diff --git a/setup.cfg b/setup.cfg index 534cfde..bdd1cac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ docs = sphinx-book-theme myst-nb ipywidgets - sphinx-new-tab-link + sphinx-new-tab-link!=0.2.2 [options.packages.find] where = src From a2fb32743bbd2fc46dd363e6de6dd462ff04b52c Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Tue, 5 Mar 2024 19:06:50 +0100 Subject: [PATCH 13/14] Action colab tutorial (#7) * :construction: try to add colab docker container and run tutorial * :bug: try to increase disk space * :bug: kernel restart required. move installation to bash - papermill start the kernel, so installation shoudl work --- .github/workflows/colab.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/colab.yml diff --git a/.github/workflows/colab.yml b/.github/workflows/colab.yml new file mode 100644 index 0000000..8293dcf --- /dev/null +++ b/.github/workflows/colab.yml @@ -0,0 +1,25 @@ +name: Test that tutorial runs on latest colab image + +on: + push: + schedule: + - cron: '0 2 * * 3' + +jobs: + test: + name: Test + runs-on: ubuntu-latest-4core # increase disk space + # https://console.cloud.google.com/artifacts/docker/colab-images/europe/public/runtime + container: + image: europe-docker.pkg.dev/colab-images/public/runtime:latest + steps: + - uses: actions/checkout@v4 + - name: Test tutorials + run: | + python3 -m pip install papermill ipykernel njab + cd docs/tutorial + papermill explorative_analysis.ipynb --help-notebook + papermill log_reg.ipynb --help-notebook + papermill explorative_analysis.ipynb explorative_analysis_tested.ipynb + pip install njab heatmapz openpyxl "matplotlib<3.7" plotly + papermill log_reg.ipynb log_reg_tested.ipynb From 1c546f49f0ef64e2212d5923cd4d71b8c96f9470 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 5 Mar 2024 19:17:02 +0100 Subject: [PATCH 14/14] :memo: add log. reg. tutorial to docs --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index c322ef7..f7c2254 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,7 +9,7 @@ functionality used two papers. .. include:: ../README.md :parser: myst_parser.sphinx_ :start-line: 1 - :end-line: 54 + :end-line: 69