diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index f9a82801d..6f457422d 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -34,7 +34,7 @@ jobs: sum.golang.org:443 - name: Start Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -48,14 +48,14 @@ jobs: uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0 - name: Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Dependency Review' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index efeb2187a..cfabedff6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,7 +56,7 @@ jobs: pypi.org:443 sum.golang.org:443 - name: Start Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -74,7 +74,7 @@ jobs: run: | python -m pip install --require-hashes -r CI/requirements_ci.txt - name: Setup Python Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Environment setup (Python${{ matrix.python-version }}, lint)' @@ -93,13 +93,13 @@ jobs: run: | python -m tox -e lint - name: Tests measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Lint (Python${{ matrix.python-version }})' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true @@ -133,7 +133,7 @@ jobs: raw.githubusercontent.com:443 sum.golang.org:443 - name: Start Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -151,7 +151,7 @@ jobs: run: | python -m pip install --require-hashes -r CI/requirements_ci.txt - name: Environment Setup Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Environment setup (Python${{ matrix.python-version }}, standard)' @@ -171,13 +171,13 @@ jobs: COVERALLS_FLAG_NAME: run-${{ matrix.python-version }}-ubuntu-latest-preliminary COVERALLS_PARALLEL: true - name: Tests measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Testing with tox (Python${{ matrix.python-version }})' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true @@ -260,7 +260,7 @@ jobs: sum.golang.org:443 - name: Start Energy Measurement if : ${{ matrix.os == 'ubuntu-latest' }} - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -284,7 +284,7 @@ jobs: python -m pip install --require-hashes -r CI/requirements_ci.txt - name: Environment Setup Energy Measurement if : ${{ matrix.os == 'ubuntu-latest' }} - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Environment setup (Python${{ matrix.python-version }}, ${{ matrix.tox-env }})' @@ -316,14 +316,14 @@ jobs: COVERALLS_PARALLEL: true - name: Tests measurement if : ${{ matrix.os == 'ubuntu-latest' }} - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Testing with tox (Python${{ matrix.python-version }}, ${{ matrix.tox-env }})' continue-on-error: true - name: Show Energy Results if : ${{ matrix.os == 'ubuntu-latest' }} - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true @@ -366,7 +366,7 @@ jobs: raw.githubusercontent.com:443 sum.golang.org:443 - name: Start Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -398,7 +398,7 @@ jobs: xclim show_version_info python -m pip check || true - name: Environment Setup Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Environment setup (conda, Python${{ matrix.python-version }})' @@ -414,13 +414,13 @@ jobs: COVERALLS_FLAG_NAME: run-{{ matrix.python-version }}-conda COVERALLS_PARALLEL: true - name: Tests measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Testing with pytest (conda, Python${{ matrix.python-version }})' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true @@ -454,23 +454,23 @@ jobs: pypi.org:443 sum.golang.org:443 - name: Start Energy Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} continue-on-error: true - name: Coveralls Finished - uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 # v2.3.4 + uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 with: parallel-finished: true - name: Finish measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Finish Run' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 91d30dfee..daefc9575 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -43,4 +43,4 @@ jobs: run: | python -m flit build - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 + uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 diff --git a/.github/workflows/tag-testpypi.yml b/.github/workflows/tag-testpypi.yml index 9db0c33aa..83ede6ac0 100644 --- a/.github/workflows/tag-testpypi.yml +++ b/.github/workflows/tag-testpypi.yml @@ -43,7 +43,7 @@ jobs: run: | python -m flit build - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 + uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 with: repository-url: https://test.pypi.org/legacy/ skip-existing: true diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 6f1f92047..23d497d72 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -61,7 +61,7 @@ jobs: repo.anaconda.com:443 sum.golang.org:443 - name: Start Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: start-measurement branch: ${{ github.head_ref || github.ref_name }} @@ -98,7 +98,7 @@ jobs: xclim show_version_info python -m pip check || true - name: Setup Python Measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Environment Setup (Upstream, Python${{ matrix.python-version }})' @@ -125,13 +125,13 @@ jobs: issue-title: "⚠️ Nightly upstream-dev CI failed for Python${{ matrix.python-version }} ⚠️" log-path: output-${{ matrix.python-version }}-log.jsonl - name: Tests measurement - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: get-measurement label: 'Testing and Reporting (Upstream, Python${{ matrix.python-version }})' continue-on-error: true - name: Show Energy Results - uses: green-coding-solutions/eco-ci-energy-estimation@e79d33b08b0c47de4438c161d432730fce23f246 # v4.2.0 + uses: green-coding-solutions/eco-ci-energy-estimation@2c74a687e9cc4cc4579ae752404a8d54cc46a06a # v4.3.0 with: task: display-results continue-on-error: true diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b745beb6a..e05e3742a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,11 +15,13 @@ New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * New function ``ensemble.partition.general_partition``. (:pull:`2035`). * Added a new ``xclim.indices.generic.bivariate_count_occurrences`` function to count instances where operations and performed and validated for two variables. (:pull:`2030`). +* `xclim` now tracks energy usage and carbon emissions ("last run", "average", and "total") during CI workflows using the `eco-ci-energy-estimation` GitHub Action. (:pull:`2046`). Internal changes ^^^^^^^^^^^^^^^^ * `sphinx-codeautolink` and `pygments` have been temporarily pinned due to breaking API changes. (:pull:`2030`). * Adjusted the ``TestOfficialYaml`` test to use a dynamic method for finding the installed location of `xclim`. (:pull:`2028`). +* Adjusted two tests for better handling when running in Windows environments. (:pull:`2057`). * There is now a warning stating that `fitkwargs` are not employed when using the `lmoments3` distribution. One exception is the use of `'floc'` which is allowed with the gamma distribution. `'floc'` is used to shift the distribution before computing fitting parameters with the `lmoments3` distribution since ``loc=0`` is always assumed in the library. (:issue:`2043`, :pull:`2045`). * The `PWM` method (from `lmoments3`) is now available to be used with the `gamma` distribution in ``xclim.indices.standardized_precipitation_index`` and ``xclim.indices.standardized_precipitation_evapotranspiration_index``. (:issue:`2043`, :pull:`2045`). diff --git a/CI/requirements_ci.in b/CI/requirements_ci.in index 204e832d5..50dd99990 100644 --- a/CI/requirements_ci.in +++ b/CI/requirements_ci.in @@ -1,7 +1,7 @@ -bump-my-version==0.29.0 -deptry==0.22.0 +bump-my-version==0.30.0 +deptry==0.23.0 flit==3.10.1 -pip==24.3.1 +pip==25.0 pylint==3.3.3 -tox==4.23.2 -tox-gh==1.4.4 +tox==4.24.1 +tox-gh==1.5.0 diff --git a/CI/requirements_ci.txt b/CI/requirements_ci.txt index 7dcb2c2ea..737da5a7c 100644 --- a/CI/requirements_ci.txt +++ b/CI/requirements_ci.txt @@ -16,9 +16,9 @@ bracex==2.4 \ --hash=sha256:a27eaf1df42cf561fed58b7a8f3fdf129d1ea16a81e1fadd1d17989bc6384beb \ --hash=sha256:efdc71eff95eaff5e0f8cfebe7d01adf2c8637c8c92edaf63ef348c241a82418 # via wcmatch -bump-my-version==0.29.0 \ - --hash=sha256:6566ab25bd3eeeec109f4ac7e4464227a3ac1fd57f847d259a24800423cd9037 \ - --hash=sha256:e4149ed63b4772f5868b3fcabb8fa5e1191b8abae6d35effd0be980d4b0f55e3 +bump-my-version==0.30.0 \ + --hash=sha256:b0d683a1cb97fbc2f46adf8eb39ff1f0bdd72866c3583fe01f9837d6f031e5e3 \ + --hash=sha256:d53e784c73abc4bb5759e296f510bc71878e1df078eb525542ec9291b5ceb195 # via -r CI/requirements_ci.in cachetools==5.5.0 \ --hash=sha256:02134e8439cdc2ffb62023ce1debca2944c3f289d66bb17ead3ab3dede74b292 \ @@ -135,23 +135,23 @@ colorama==0.4.6 \ --hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \ --hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6 # via tox -deptry==0.21.2 \ - --hash=sha256:019167b35301edd2bdd4719c8b8f44769be4507cb8a1cd46fff4393cdbe8d31b \ - --hash=sha256:06d48e9fa460aad02f9e1b079d9f5a69d622d291b3a0525b722fc91c88032042 \ - --hash=sha256:1012a88500f242489066f811f6ec0c93328d9340bbf0f87f0c7d2146054d197e \ - --hash=sha256:186ddbc69c1f70e684e83e202795e1054d0c2dfc03b8acc077f65dc3b6a7f4ce \ - --hash=sha256:3080bb88c16ebd35f59cba7688416115b7aaf4630dc5a051dff2649cbf129a1b \ - --hash=sha256:3ef8aed33a2eac357f9565063bc1257bcefa03a37038299c08a4222e28f3cd34 \ - --hash=sha256:4e870553c7a1fafcd99a83ba4137259525679eecabeff61bc669741efa201541 \ - --hash=sha256:7479d3079be69c3bbf5913d8e21090749c1139ee91f81520ffce90b5322476b0 \ - --hash=sha256:769bb658172586d1b03046bdc6b6c94f6a98ecfbac04ff7f77ec61768c75e1c2 \ - --hash=sha256:917745db5f8295eb5048e43d9073a9a675ffdba865e9b294d2e7aa455730cb06 \ - --hash=sha256:adb12d6678fb5dbd320a0a2e37881059d0a45bec6329df4250c977d803fe7f96 \ - --hash=sha256:d76bbf48bd62ecc44ca3d414769bd4b7956598d23d9ccb42fd359b831a31cab2 \ - --hash=sha256:d8add495f0dd19a38aa6d1e09b14b1441bca47c9d945bc7b322efb084313eea3 \ - --hash=sha256:e3b9e0c5ee437240b65e61107b5777a12064f78f604bf9f181a96c9b56eb896d \ - --hash=sha256:f3686e86ad7063b5a6e5253454f9d9e4a7a6b1511a99bd4306fda5424480be48 \ - --hash=sha256:fb2f43747b58abeec01dc277ef22859342f3bca2ac677818c94940a009b436c0 +deptry==0.23.0 \ + --hash=sha256:04afae204654542406318fd3dd6f4a6697579597f37195437daf84a53ee0ebbf \ + --hash=sha256:1cfa4b3a46ee8a026eaa38e4b9ba43fe6036a07fe16bf0a663cb611b939f6af8 \ + --hash=sha256:1f2a6817a37d76e8f6b667381b7caf6ea3e6d6c18b5be24d36c625f387c79852 \ + --hash=sha256:40706dcbed54141f2d23afa70a272171c8c46531cd6f0f9c8ef482c906b3cee2 \ + --hash=sha256:4915a3590ccf38ad7a9176aee376745aa9de121f50f8da8fb9ccec87fa93e676 \ + --hash=sha256:583154732cfd438a4a090b7d13d8b2016f1ac2732534f34fb689345768d8538b \ + --hash=sha256:5f7e4b1a5232ed6d352fca7173750610a169377d1951d3e9782947191942a765 \ + --hash=sha256:736e7bc557aec6118b2a4d454f0d81f070782faeaa9d8d3c9a15985c9f265372 \ + --hash=sha256:889541844092f18e7b48631852195f36c25c5afd4d7e074b19ba824b430add50 \ + --hash=sha256:9601b64cc0aed42687fdd5c912d5f1e90d7f7333fb589b14e35bfdfebae866f3 \ + --hash=sha256:9a46f78098f145100dc582a59af8548b26cdfa16cf0fbd85d2d44645e724cb6a \ + --hash=sha256:9d03cc99a61c348df92074a50e0a71b28f264f0edbf686084ca90e6fd44e3abe \ + --hash=sha256:aff9156228eb16cd81792f920c1623c00cb59091ae572600ba0eac587da33c0c \ + --hash=sha256:d53e803b280791d89a051b6183d9dc40411200e22a8ab7e6c32c6b169822a664 \ + --hash=sha256:da7678624f4626d839c8c03675452cefc59d6cf57d25c84a9711dae514719279 \ + --hash=sha256:e6172b2205f6e84bcc9df25226693d4deb9576a6f746c2ace828f6d13401d357 # via -r CI/requirements_ci.in dill==0.3.8 \ --hash=sha256:3ebe3c479ad625c4553aca177444d89b486b1d84982eeacded644afc0cf797ca \ @@ -165,9 +165,9 @@ docutils==0.21.2 \ --hash=sha256:3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f \ --hash=sha256:dafca5b9e384f0e419294eb4d2ff9fa826435bf15f15b7bd45723e8ad76811b2 # via flit -filelock==3.16.1 \ - --hash=sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0 \ - --hash=sha256:c249fbfcd5db47e5e2d6d62198e565475ee65e4831e2561c8e313fa7eb961435 +filelock==3.17.0 \ + --hash=sha256:533dc2f7ba78dc2f0f531fc6c4940addf7b70a481e269a5a3b93be94ffbe8338 \ + --hash=sha256:ee4e77401ef576ebb38cd7f13b9b28893194acc20a8e68e18730ba9c0e54660e # via # tox # virtualenv @@ -361,9 +361,39 @@ rich-click==1.8.3 \ --hash=sha256:636d9c040d31c5eee242201b5bf4f2d358bfae4db14bb22ec1cafa717cfd02cd \ --hash=sha256:6d75bdfa7aa9ed2c467789a0688bc6da23fbe3a143e19aa6ad3f8bac113d2ab3 # via bump-my-version -tomli==2.0.1 \ - --hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \ - --hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f +tomli==2.2.1 \ + --hash=sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6 \ + --hash=sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd \ + --hash=sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c \ + --hash=sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b \ + --hash=sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8 \ + --hash=sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6 \ + --hash=sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77 \ + --hash=sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff \ + --hash=sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea \ + --hash=sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192 \ + --hash=sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249 \ + --hash=sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee \ + --hash=sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4 \ + --hash=sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98 \ + --hash=sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8 \ + --hash=sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4 \ + --hash=sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281 \ + --hash=sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744 \ + --hash=sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69 \ + --hash=sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13 \ + --hash=sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140 \ + --hash=sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e \ + --hash=sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e \ + --hash=sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc \ + --hash=sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff \ + --hash=sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec \ + --hash=sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2 \ + --hash=sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222 \ + --hash=sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106 \ + --hash=sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272 \ + --hash=sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a \ + --hash=sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7 # via # deptry # pylint @@ -379,15 +409,15 @@ tomlkit==0.13.0 \ # via # bump-my-version # pylint -tox==4.23.2 \ - --hash=sha256:452bc32bb031f2282881a2118923176445bac783ab97c874b8770ab4c3b76c38 \ - --hash=sha256:86075e00e555df6e82e74cfc333917f91ecb47ffbc868dcafbd2672e332f4a2c +tox==4.24.1 \ + --hash=sha256:083a720adbc6166fff0b7d1df9d154f9d00bfccb9403b8abf6bc0ee435d6a62e \ + --hash=sha256:57ba7df7d199002c6df8c2db9e6484f3de6ca8f42013c083ea2d4d1e5c6bdc75 # via # -r CI/requirements_ci.in # tox-gh -tox-gh==1.4.4 \ - --hash=sha256:4ea585f66585b90f5826b1677cfc9453747792a0f9ff83d468603bc17556e07b \ - --hash=sha256:b962e0f8c4619e98d11c2a135939876691e148b843b7dac4cff7de1dc4f7c215 +tox-gh==1.5.0 \ + --hash=sha256:bd4c56d1ebcde4ca2450fed347610a739614a7225945bdc89a67c8395eac9d63 \ + --hash=sha256:fd7e8c826f4576a02af4737fd4b738817660b63898c161d6ee8f658c885f7fa1 # via -r CI/requirements_ci.in types-setuptools==75.6.0.20241126 \ --hash=sha256:7bf25ad4be39740e469f9268b6beddda6e088891fa5a27e985c6ce68bf62ace0 \ @@ -406,9 +436,9 @@ urllib3==2.2.2 \ --hash=sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472 \ --hash=sha256:dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168 # via requests -virtualenv==20.26.6 \ - --hash=sha256:280aede09a2a5c317e409a00102e7077c6432c5a38f0ef938e643805a7ad2c48 \ - --hash=sha256:7345cc5b25405607a624d8418154577459c3e0277f5466dd79c49d5e492995f2 +virtualenv==20.29.1 \ + --hash=sha256:4e4cb403c0b0da39e13b46b1b2476e505cb0046b25f242bee80f62bf990b2779 \ + --hash=sha256:b8b8970138d32fb606192cb97f6cd4bb644fa486be9308fb9b63f81091b5dc35 # via tox wcmatch==8.5.2 \ --hash=sha256:17d3ad3758f9d0b5b4dedc770b65420d4dac62e680229c287bf24c9db856a478 \ diff --git a/README.rst b/README.rst index b56a3ff32..05a2369a9 100644 --- a/README.rst +++ b/README.rst @@ -11,7 +11,7 @@ xclim: Climate services library |logo| |logo-dark| |logo-light| +----------------------------+-----------------------------------------------------+ | Coding Standards | |black| |ruff| |pre-commit| |ossf-bp| |fossa| | +----------------------------+-----------------------------------------------------+ -| Development Status | |status| |build| |coveralls| |energy| | +| Development Status | |status| |build| |coveralls| | +----------------------------+-----------------------------------------------------+ `xclim` is an operational Python library for climate services, providing numerous climate-related indicator tools @@ -20,7 +20,7 @@ adjustment of climate model simulations, as well as climate model ensemble analy `xclim` is built using `xarray`_ and can seamlessly benefit from the parallelization handling provided by `dask`_. Its objective is to make it as simple as possible for users to perform typical climate services data treatment workflows. -Leveraging xarray and dask, users can easily bias-adjust climate simulations over large spatial domains or compute indices from large climate datasets. +Leveraging `xarray` and `dask`, users can easily bias-adjust climate simulations over large spatial domains or compute indices from large climate datasets. For example, the following would compute monthly mean temperature from daily mean temperature: @@ -32,7 +32,7 @@ For example, the following would compute monthly mean temperature from daily mea ds = xr.open_dataset(filename) tg = xclim.atmos.tg_mean(ds.tas, freq="MS") -For applications where metadata and missing values are important to get right, xclim provides a class for each index +For applications where metadata and missing values are important to get right, `xclim` provides a class for each index that validates inputs, checks for missing values, converts units and assigns metadata attributes to the output. This also provides a mechanism for users to customize the indices to their own specifications and preferences. `xclim` currently provides over 150 indices related to mean, minimum and maximum daily temperature, daily precipitation, @@ -110,6 +110,19 @@ This is free software: you can redistribute it and/or modify it under the terms .. _Apache License 2.0: https://opensource.org/license/apache-2-0/ .. _LICENSE: https://github.com/Ouranosinc/xclim/blob/main/LICENSE +Energy and Carbon Usage +----------------------- +The `xclim` development team is interested in thoroughly testing our software while also reducing the environmental impact of the software we develop. +This repository uses the `ECO-CI`_ tool to estimate and track the energy use and carbon emissions of our continuous integration workflows. + ++---------------------------------------------------------------------------------------+ +| `ECO-CI`_ Energy Use and Carbon Emissions from CI Workflows (since November 2024) | ++------------------+------------------+-------------------------------------------------+ +| Testing suite | Energy Usage | |energy-last| |energy-average| |energy-total| | +| +------------------+-------------------------------------------------+ +| (*main* branch) | Carbon Emissions | |carbon-last| |carbon-average| |carbon-total| | ++------------------+------------------+-------------------------------------------------+ + Credits ------- `xclim` development is funded through Ouranos_, Environment and Climate Change Canada (ECCC_), the `Fonds vert`_ and the Fonds d'électrification et de changements climatiques (FECC_), the Canadian Foundation for Innovation (CFI_), and the Fonds de recherche du Québec (FRQ_). @@ -120,6 +133,7 @@ This package was created with Cookiecutter_ and the `audreyfeldroy/cookiecutter- .. _CFI: https://www.innovation.ca/ .. _Cookiecutter: https://github.com/cookiecutter/cookiecutter/ .. _ECCC: https://www.canada.ca/en/environment-climate-change.html +.. _ECO-CI: https://www.green-coding.io/ .. _FECC: https://www.environnement.gouv.qc.ca/ministere/fonds-electrification-changements-climatiques/index.htm .. _Fonds vert: https://www.environnement.gouv.qc.ca/ministere/fonds-vert/index.htm .. _FRQ: https://frq.gouv.qc.ca/ @@ -169,10 +183,6 @@ This package was created with Cookiecutter_ and the `audreyfeldroy/cookiecutter- :target: https://bestpractices.coreinfrastructure.org/projects/6041 :alt: Open Source Security Foundation Best Practices -.. |energy| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=47013755 - :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=47013755 - :alt: Energy Consumption - .. |ossf-score| image:: https://api.securityscorecards.dev/projects/github.com/Ouranosinc/xclim/badge :target: https://securityscorecards.dev/viewer/?uri=github.com/Ouranosinc/xclim :alt: Open Source Security Foundation Scorecard @@ -215,3 +225,30 @@ This package was created with Cookiecutter_ and the `audreyfeldroy/cookiecutter- .. |versions| image:: https://img.shields.io/pypi/pyversions/xclim.svg :target: https://pypi.python.org/pypi/xclim :alt: Supported Python Versions + +.. + Energy Metrics by https://github.com/green-coding-solutions/eco-ci-energy-estimation + +.. |energy-total| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641&mode=totals + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :alt: Energy Consumption (Total) + +.. |energy-last| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :alt: Energy Consumption (Last run) + +.. |energy-average| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641&mode=avg&duration_days=90 + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :alt: Energy Consumption (Last 90 days moving average) + +.. |carbon-total| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641&mode=totals&metric=carbon + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=festive-indices&workflow=5828641 + :alt: Carbon Emissions (Total) + +.. |carbon-last| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641&metric=carbon + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :alt: Carbon Emissions (Last run) + +.. |carbon-average| image:: https://api.green-coding.io/v1/ci/badge/get?repo=Ouranosinc/xclim&branch=main&workflow=5828641&mode=avg&duration_days=90&metric=carbon + :target: https://metrics.green-coding.io/ci.html?repo=Ouranosinc/xclim&branch=main&workflow=5828641 + :alt: Carbon Emissions (Last 90 days moving average) diff --git a/pyproject.toml b/pyproject.toml index 597552261..e7b8dc577 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,11 +61,11 @@ dev = [ # Dev tools and testing "black[jupyter] ==24.10.0", "blackdoc ==0.3.9", - "bump-my-version ==0.29.0", - "codespell ==2.3.0", + "bump-my-version ==0.30.0", + "codespell ==2.4.0", "coverage[toml] >=7.5.0", "coveralls >=4.0.1", # coveralls is not yet compatible with Python 3.13 - "deptry ==0.22.0", + "deptry ==0.23.0", "flake8 >=7.1.1", "flake8-rst-docstrings >=0.3.0", "h5netcdf>=1.3.0", @@ -140,7 +140,7 @@ target-version = [ ] [tool.bumpversion] -current_version = "0.54.1-dev.3" +current_version = "0.54.1-dev.6" commit = true commit_args = "--no-verify --signoff" tag = false diff --git a/src/xclim/__init__.py b/src/xclim/__init__.py index bb48837c2..316c86698 100644 --- a/src/xclim/__init__.py +++ b/src/xclim/__init__.py @@ -13,7 +13,7 @@ __author__ = """Travis Logan""" __email__ = "logan.travis@ouranos.ca" -__version__ = "0.54.1-dev.3" +__version__ = "0.54.1-dev.6" with _resources.as_file(_resources.files("xclim.data")) as _module_data: diff --git a/src/xclim/core/dataflags.py b/src/xclim/core/dataflags.py index eb574b91d..54bcba821 100644 --- a/src/xclim/core/dataflags.py +++ b/src/xclim/core/dataflags.py @@ -8,7 +8,6 @@ from __future__ import annotations from collections.abc import Callable, Sequence -from decimal import Decimal from functools import reduce from inspect import signature @@ -674,7 +673,7 @@ def _get_variable_name(function, _kwargs): format_args[arg] = "array" else: val = str2pint(val).magnitude - if Decimal(val) % 1 == 0: + if val == int(val): val = str(int(val)) else: val = str(val).replace(".", "point") diff --git a/src/xclim/core/indicator.py b/src/xclim/core/indicator.py index 7d417e2e1..37543fec6 100644 --- a/src/xclim/core/indicator.py +++ b/src/xclim/core/indicator.py @@ -1311,7 +1311,7 @@ def _format( # Add formatting {} around values to be able to replace them with _attrs_mapping using format. for k, v in args.items(): if isinstance(v, units.Quantity): - mba[k] = f"{v:g~P}" + mba[k] = f"{v:gcf}" elif isinstance(v, int | float): mba[k] = f"{v:g}" # TODO: What about InputKind.NUMBER_SEQUENCE diff --git a/src/xclim/core/units.py b/src/xclim/core/units.py index 2bdb233a4..036835d3e 100644 --- a/src/xclim/core/units.py +++ b/src/xclim/core/units.py @@ -22,7 +22,6 @@ import pint import xarray as xr from boltons.funcutils import wraps -from pint import UndefinedUnitError from yaml import safe_load from xclim.core._exceptions import ValidationError @@ -64,28 +63,21 @@ units = deepcopy(cf_xarray.units.units) # Changing the default string format for units/quantities. # CF is implemented by cf-xarray, g is the most versatile float format. -# The following try/except logic can be removed when xclim drops support numpy <2.0. -try: - units.formatter.default_format = "gcf" -except UndefinedUnitError: - units.default_format = "gcf" -# Switch this flag back to False. Not sure what that implies, but it breaks some tests. -units.force_ndarray_like = False # noqa: F841 -# Another alias not included by cf_xarray -units.define("@alias percent = pct") - -# Default context. -null = pint.Context("none") -units.add_context(null) +units.formatter.default_format = "gcf" +# CF-xarray forces numpy arrays even for scalar values, not sure why. +# We don't want that in xclim, the magnitude of a scalar is a scalar (float). +units.force_ndarray_like = False -# Precipitation units. This is an artificial unit that we're using to verify that a given unit can be converted into -# a precipitation unit. Ideally this could be checked through the `dimensionality`, but I can't get it to work. +# Define dimensionalities for convenience with the `declare_units` decorator units.define("[precipitation] = [mass] / [length] ** 2 / [time]") -units.define("mmday = 1 kg / meter ** 2 / day") - units.define("[discharge] = [length] ** 3 / [time]") -units.define("cms = meter ** 3 / second") +units.define("[radiation] = [power] / [length]**2") +# Default context. This is essentially a convenience, so that we can pass a context systemtically to pint's methods. +null = pint.Context("none") +units.add_context(null) + +# Convenience context for common transformation involving liquid water hydro = pint.Context("hydro") hydro.add_transformation( "[mass] / [length]**2", @@ -109,6 +101,9 @@ ) units.add_context(hydro) +# Set as application registry +pint.set_application_registry(units) + with (files("xclim.data") / "variables.yml").open() as variables: CF_CONVERSIONS = safe_load(variables)["conversions"] @@ -136,10 +131,6 @@ def _func_register(func: Callable) -> Callable: return _func_register -# Radiation units -units.define("[radiation] = [power] / [length]**2") - - def units2pint( value: xr.DataArray | units.Unit | units.Quantity | dict | str, ) -> pint.Unit: diff --git a/src/xclim/indices/_threshold.py b/src/xclim/indices/_threshold.py index a3580b212..c027da0ea 100644 --- a/src/xclim/indices/_threshold.py +++ b/src/xclim/indices/_threshold.py @@ -2963,7 +2963,7 @@ def maximum_consecutive_tx_days( @declare_units(siconc="[]", areacello="[area]", thresh="[]") def sea_ice_area( - siconc: xarray.DataArray, areacello: xarray.DataArray, thresh: Quantified = "15 pct" + siconc: xarray.DataArray, areacello: xarray.DataArray, thresh: Quantified = "15 %" ) -> xarray.DataArray: """ Total sea ice area. @@ -2994,7 +2994,7 @@ def sea_ice_area( "What is the difference between sea ice area and extent?" - :cite:cts:`nsidc_frequently_2008` """ t = convert_units_to(thresh, siconc) - factor = convert_units_to("100 pct", siconc) + factor = convert_units_to("100 %", siconc) sia = xarray.dot(siconc.where(siconc >= t, 0), areacello) / factor sia = sia.assign_attrs(units=areacello.units) return sia @@ -3002,7 +3002,7 @@ def sea_ice_area( @declare_units(siconc="[]", areacello="[area]", thresh="[]") def sea_ice_extent( - siconc: xarray.DataArray, areacello: xarray.DataArray, thresh: Quantified = "15 pct" + siconc: xarray.DataArray, areacello: xarray.DataArray, thresh: Quantified = "15 %" ) -> xarray.DataArray: """ Total sea ice extent. diff --git a/src/xclim/indices/fire/_cffwis.py b/src/xclim/indices/fire/_cffwis.py index e59dc2cb6..bb2c3a0c6 100644 --- a/src/xclim/indices/fire/_cffwis.py +++ b/src/xclim/indices/fire/_cffwis.py @@ -1397,7 +1397,7 @@ def cffwis_indices( tas = convert_units_to(tas, "C") pr = convert_units_to(pr, "mm/day") sfcWind = convert_units_to(sfcWind, "km/h") - hurs = convert_units_to(hurs, "pct") + hurs = convert_units_to(hurs, "%") if snd is not None: snd = convert_units_to(snd, "m") diff --git a/src/xclim/indices/fire/_ffdi.py b/src/xclim/indices/fire/_ffdi.py index 5c06ee0b2..f8ba04bb1 100644 --- a/src/xclim/indices/fire/_ffdi.py +++ b/src/xclim/indices/fire/_ffdi.py @@ -394,7 +394,7 @@ def mcarthur_forest_fire_danger_index( :cite:cts:`ffdi-noble_1980,ffdi-dowdy_2018,ffdi-holgate_2017` """ tasmax = convert_units_to(tasmax, "C") - hurs = convert_units_to(hurs, "pct") + hurs = convert_units_to(hurs, "%") sfcWind = convert_units_to(sfcWind, "km/h") ffdi = drought_factor**0.987 * np.exp( diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 8df70f4dd..20f71fdac 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -564,18 +564,18 @@ def test_formatting(pr_series): # pint 0.10 now pretty print day as d. assert ( out.attrs["long_name"] - == "Number of days with daily precipitation at or above 1 mm/d" + == "Number of days with daily precipitation at or above 1 mm d-1" ) assert out.attrs["description"] in [ - "Annual number of days with daily precipitation at or above 1 mm/d." + "Annual number of days with daily precipitation at or above 1 mm d-1." ] out = atmos.wetdays(pr_series(np.arange(366)), thresh=1.5 * units.mm / units.day) assert ( out.attrs["long_name"] - == "Number of days with daily precipitation at or above 1.5 mm/d" + == "Number of days with daily precipitation at or above 1.5 mm d-1" ) assert out.attrs["description"] in [ - "Annual number of days with daily precipitation at or above 1.5 mm/d." + "Annual number of days with daily precipitation at or above 1.5 mm d-1." ] diff --git a/tests/test_indices.py b/tests/test_indices.py index 18e2ef760..cede4beef 100644 --- a/tests/test_indices.py +++ b/tests/test_indices.py @@ -3407,19 +3407,19 @@ def test_simple(self): np.arange(4).reshape(1, 2, 2), dims=["time", "lat", "lon"], coords={"time": [1], "lat": [-45, 45], "lon": [30, 60]}, - attrs={"units": "mmday"}, + attrs={"units": "mm/day"}, ) tas_baseline = xr.DataArray( np.arange(4).reshape(1, 2, 2), dims=["time", "lat", "lon"], coords={"time": [1], "lat": [-45, 45], "lon": [30, 60]}, - attrs={"units": "C"}, + attrs={"units": "degC"}, ) tas_future = xr.DataArray( np.arange(40).reshape(10, 2, 2), dims=["time_fut", "lat", "lon"], coords={"time_fut": np.arange(10), "lat": [-45, 45], "lon": [30, 60]}, - attrs={"units": "C"}, + attrs={"units": "degC"}, ) delta_tas = tas_future - tas_baseline delta_tas.attrs["units"] = "delta_degC" diff --git a/tests/test_modules.py b/tests/test_modules.py index ba1697b18..970e2a1ed 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -1,5 +1,6 @@ from __future__ import annotations +import platform from importlib.util import find_spec from inspect import _empty # noqa from pathlib import Path @@ -273,8 +274,10 @@ def test_all(self): assert self.validate() -# It's not really slow, but this is an unstable test (when it fails) and we might not want to execute it on all builds -@pytest.mark.slow +@pytest.mark.xfail(reason="This test is relatively unstable.", strict=False) +@pytest.mark.skipif( + platform.system() == "Windows", reason="nl_langinfo not available on Windows." +) def test_encoding(): import _locale import sys diff --git a/tests/test_sdba/conftest.py b/tests/test_sdba/conftest.py index 3732a2eca..9f38e9dfe 100644 --- a/tests/test_sdba/conftest.py +++ b/tests/test_sdba/conftest.py @@ -105,13 +105,8 @@ def qds_month(): @pytest.fixture -def ref_hist_sim_tuto(socket_enabled): # noqa: F841 - """Return ref, hist, sim time series of air temperature. - - socket_enabled is a fixture that enables the use of the internet to download the tutorial dataset while the - `--disable-socket` flag has been called. This fixture will crash if the `air_temperature` tutorial file is - not on disk while the internet is unavailable. - """ +def ref_hist_sim_tuto(): + """Return ref, hist, sim time series of air temperature.""" def _ref_hist_sim_tuto(sim_offset=3, delta=0.1, smth_win=3, trend=True): ds = xr.tutorial.load_dataset("air_temperature") diff --git a/tests/test_sdba/test_adjustment.py b/tests/test_sdba/test_adjustment.py index 8466bd9ca..d9a348ea7 100644 --- a/tests/test_sdba/test_adjustment.py +++ b/tests/test_sdba/test_adjustment.py @@ -131,6 +131,7 @@ def test_time_and_from_ds(self, series, group, dec, tmp_path, random, open_datas np.testing.assert_array_equal(p, p2) @pytest.mark.requires_internet + @pytest.mark.enable_socket def test_reduce_dims(self, ref_hist_sim_tuto): ref, hist, _sim = ref_hist_sim_tuto() hist = hist.expand_dims(member=[0, 1]) diff --git a/tests/test_units.py b/tests/test_units.py index a0781ad4e..fbffbf391 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -43,7 +43,6 @@ def test_hydro(self): with units.context("hydro"): q = 1 * units.kg / units.m**2 / units.s assert q.to("mm/day") == q.to("mm/d") - assert q.to("mmday").magnitude == 24 * 60**2 def test_lat_lon(self): assert 100 * units.degreeN == 100 * units.degree @@ -55,19 +54,15 @@ def test_pcic(self): np.isclose(1 * fu, 1 * tu) def test_dimensionality(self): + # Check that the hydro context allows flux to rate conversion with units.context("hydro"): fu = 1 * units.parse_units("kg / m**2 / s") - tu = 1 * units.parse_units("mm / d") - fu.to("mmday") - tu.to("mmday") + fu.to("mm/day") def test_fraction(self): q = 5 * units.percent assert q.to("dimensionless") == 0.05 - q = 5 * units.parse_units("pct") - assert q.to("dimensionless") == 0.05 - class TestConvertUnitsTo: def test_deprecation(self, tas_series): @@ -135,9 +130,6 @@ def test_pint2cfunits(self): u = units("percent") assert pint2cfunits(u.units) == "%" - u = units("pct") - assert pint2cfunits(u.units) == "%" - def test_units2pint(self, pr_series): u = units2pint(pr_series([1, 2])) assert pint2cfunits(u) == "kg m-2 s-1" @@ -168,11 +160,9 @@ def test_str2pint(self): class TestCheckUnits: def test_basic(self): check_units("%", "[]") - check_units("pct", "[]") check_units("mm/day", "[precipitation]") check_units("mm/s", "[precipitation]") check_units("kg/m2/s", "[precipitation]") - check_units("cms", "[discharge]") check_units("m3/s", "[discharge]") check_units("m/s", "[speed]") check_units("km/h", "[speed]")