From ec7718489d8c66f8b4075bd678d12eb614b40c75 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 30 Jan 2025 09:29:07 +0100 Subject: [PATCH 1/2] add baseline comparison to workflow --- .github/workflows/build-ultraplot.yml | 60 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-ultraplot.yml b/.github/workflows/build-ultraplot.yml index e082dd60c..a31a901c8 100644 --- a/.github/workflows/build-ultraplot.yml +++ b/.github/workflows/build-ultraplot.yml @@ -35,27 +35,41 @@ jobs: micromamba activate ultraplot-dev pytest - # Skip pytest-mpl for now as it removes the RC file - # Future should include it though! See https://github.com/matplotlib/pytest-mpl/issues/236 - # - name: Generate baseline from main - # shell: bash -el {0} - # run: | - # mkdir -p baseline - # micromamba activate ultraplot-dev - # git fetch origin ${{ github.event.pull_request.base.sha }} - # git checkout ${{ github.event.pull_request.base.sha }} - # pytest --mpl-generate-path=baseline_images - # git checkout ${{ github.sha }} # Return to PR branch - # - name: Image Comparison Ultraplot - # shell: bash -el {0} - # run: | - # micromamba activate ultraplot-dev - # pytest --mpl --mpl-baseline-path=baseline_images + compare-baseline: + needs: build-ultraplot + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: mamba-org/setup-micromamba@v2.0.4 + with: + environment-file: ./environment.yml + init-shell: bash + create-args: >- + --verbose + python=${{ inputs.python-version }} + cache-environment: true + cache-downloads: false + + - name: Generate baseline from main + shell: bash -el {0} + run: | + mkdir -p baseline + micromamba activate ultraplot-dev + git fetch origin ${{ github.event.pull_request.base.sha }} + git checkout ${{ github.event.pull_request.base.sha }} + pytest --mpl-generate-path=baseline_images + git checkout ${{ github.sha }} # Return to PR branch - # # return the images that failed - # - name: Upload comparison failures - # if: failure() - # uses: actions/upload-artifact@v4 - # with: - # name: failed-comparisons - # path: result_images + - name: Image Comparison Ultraplot + shell: bash -el {0} + run: | + micromamba activate ultraplot-dev + pytest --mpl-generate-path=baseline_images --mpl-default-style $(python -c "import ultraplot as plt; print(plt.config.Configurator())") + + # return the images that failed + - name: Upload comparison failures + if: failure() + uses: actions/upload-artifact@v4 + with: + name: failed-comparisons + path: result_images From 967a0383548010fd3563d0eb0e5492f1e2630e20 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 30 Jan 2025 09:53:26 +0100 Subject: [PATCH 2/2] update ticker to prevent empty comparison --- ultraplot/ticker.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ultraplot/ticker.py b/ultraplot/ticker.py index 670f532ef..fefe13170 100644 --- a/ultraplot/ticker.py +++ b/ultraplot/ticker.py @@ -241,9 +241,15 @@ def tick_values(self, vmin, vmax): # noqa: U100 step = step // i break diff = np.abs(np.diff(locs[: step + 1 : step])) - (offset,) = np.where(np.isclose(locs % diff if diff.size else 0.0, 0.0)) - offset = offset[0] if offset.size else np.argmin(np.abs(locs)) - return locs[offset % step :: step] # even multiples from zero or zero-close + + if diff.size: + matches = np.where(np.isclose(locs % diff, 0.0))[0] + offset = matches[0] if len(matches) else np.argmin(np.abs(locs)) + else: + offset = np.argmin(np.abs(locs)) + return locs[ + int(offset) % step :: step + ] # even multiples from zero or zero-close class DegreeLocator(mticker.MaxNLocator):