Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
observingClouds authored Apr 6, 2024
2 parents 46a7128 + b92be13 commit 47b97f4
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 73 deletions.
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0

- name: Setup Miniconda
uses: conda-incubator/[email protected].2
uses: conda-incubator/[email protected].3
with:
# installer-url: https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh
installer-url: https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up conda
uses: conda-incubator/[email protected].2
uses: conda-incubator/[email protected].3
with:
auto-update-conda: false
channels: conda-forge
Expand All @@ -60,7 +60,7 @@ jobs:
shell: 'bash -l {0}'
steps:
- uses: actions/[email protected]
- uses: conda-incubator/[email protected].2
- uses: conda-incubator/[email protected].3
with:
channels: conda-forge
miniforge-variant: Mambaforge
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
steps:
- uses: actions/[email protected]
- name: Set up conda
uses: conda-incubator/[email protected].2
uses: conda-incubator/[email protected].3
with:
auto-update-conda: false
channels: conda-forge
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v5.0.0
uses: actions/setup-python@v5.1.0
with:
python-version: '3.11'
- name: Set up Julia
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/[email protected]

- name: Set up Python
uses: actions/setup-python@v5.0.0
uses: actions/setup-python@v5.1.0
with:
python-version: "3.10"

Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Publish a Python distribution to PyPI
if: success() && github.event_name == 'release'
uses: pypa/[email protected].11
uses: pypa/[email protected].14
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
46 changes: 7 additions & 39 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ ci:
autoupdate_schedule: quarterly


# https://pre-commit.com/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -12,52 +11,21 @@ repos:
- id: check-yaml
- id: debug-statements
- id: mixed-line-ending
# This wants to go before isort & flake8
- repo: https://github.com/PyCQA/autoflake
rev: "v2.3.1"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
- id: autoflake # isort should run before black as black sometimes tweaks the isort output
args: ["--in-place", "--ignore-init-module-imports"]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- "--py38-plus"
# https://github.com/python/black#version-control-integration
# run the linter
- id: ruff
args: [--fix, --ignore-noqa]

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- id: black-jupyter

- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
hooks:
- id: blackdoc
exclude: docs/index.rst
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
exclude: "properties|asv_bench"
# This is slow and so we take it out of the fast-path; requires passing
# `--hook-stage manual` to pre-commit
stages: [manual]
additional_dependencies: [
# Type stubs
types-python-dateutil,
types-pkg_resources,
types-PyYAML,
types-pytz,
typing-extensions,
numpy,
]
110 changes: 110 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[build-system]
requires = ["setuptools>=42", "wheel", "pip"]
build-backend = "setuptools.build_meta"

[tool.pytest]
addopts = "--ignore=setup.py"

[tool.pytest.ini_options]
norecursedirs = [
".git",
".github",
"docs",
]

[tool.ruff]
line-length = 120
target-version = "py38"
exclude = [".git", "asv_bench", "docs", "conftest.py"]


[tool.ruff.lint]
select = [
# https://pypi.org/project/pycodestyle
"E",
"W",
# https://pypi.org/project/pyflakes
"F",
# https://pypi.org/project/flake8-bandit
"S",
# https://docs.astral.sh/ruff/rules/#pyupgrade-up
"UP",
"I002", # Missing required imports
"UP008", # Super calls with redundant arguments passed.
"G010", # Deprecated log warn.
"PLR1722", # Use sys.exit() instead of exit() and quit().
"PT014", # pytest-duplicate-parametrize-test-cases.
"PT006", # Checks for the type of parameter names passed to pytest.mark.parametrize.
"PT007", # Checks for the type of parameter values passed to pytest.mark.parametrize.
"PT018", # Checks for assertions that combine multiple independent conditions.
]

extend-select = [
"I", # isort
"C4", # https://pypi.org/project/flake8-comprehensions
]

ignore = [
"S101", # Use of `assert` detected
"E203", # Whitespace-before-punctuation.
"E402", # Module-import-not-at-top-of-file.
"E731", # Do not assign a lambda expression, use a def.
"D100", # Missing docstring in public module.
"D101", # Missing docstring in public class.
"D102", # Missing docstring in public method.
"D103", # Missing docstring in public function.
"D104", # Missing docstring in public package.
"D105", # Missing docstring in magic method.
"D106", # Missing docstring in public nested class.
"D107", # Missing docstring in `__init__`.
"RET504", # Unnecessary variable assignment before `return` statement.
"S101", # Use of `assert` detected.
"S108",
"D203", # 1 blank line required before class docstring.
"D205", # 1 blank line required between summary line and description.
"D212", # Multi-line docstring summary should start at the first line.
"D213", # Multi-line docstring summary should start at the second line.
"D209", # Multi-line docstring closing quotes should be on a separate line.
"D400", # First line should end with a period.
"D413", # Missing blank line after last section of docstrings.
"D401", # First line of docstring should be in imperative mood.
"D415", # First line should end with a period, question mark, or exclamation point.
"D416", # Section name should end with a colon ("Attributes").
"D417", # Missing argument description in the docstring for argument "X".
"RUF100", # https://docs.astral.sh/ruff/rules/unused-noqa/
"C408",
"SIM118",
"RET506",
"TRY004",
"RET505",
"RET507",
"SIM108",
"SIM102",
"E501", # line too long
"E266",
"F403",
"F401",
"F841",
"RET",
"SIM",
"PT",
]
ignore-init-module-imports = true

[tool.ruff.lint.per-file-ignores]

"setup.py" = ["S101"]
"**/__init__.py" = ["F401", "F403", "F405", "F811", "F821", "E501", "SIM102"]
"tests/**" = [
"S605", # Starting a process with a shell: seems safe, but may be changed in the future; consider rewriting without `shell`
"S607", # Starting a process with a partial executable path
"RET504", # todo:Unnecessary variable assignment before `return` statement
"PT004", # Fixture `tmpdir_unittest_fixture` does not return anything, add leading underscore
"PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
"PT012", # `pytest.raises()` block should contain a single simple statement
"PT019", # Fixture `_` without value is injected as parameter, use `@pytest.mark.usefixtures` instead
"PT006" # Checks for the type of parameter names passed to pytest.mark.parametrize.
]

[tool.blackdoc]
exclude = "docs/index.rst"
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

8 changes: 4 additions & 4 deletions tests/test_bitround.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ def test_bitround_along_dim(air_temperature):
ds, info_per_bit, dim="lon", inflevels=[1.0, 0.9999, 0.99, 0.975]
)

assert ds_bitrounded_along_lon.air.dtype == "float32"
assert ds_bitrounded_along_lon.air.dtype == "float64"
assert ds_bitrounded_along_lon.lon.size == ds.lon.size
assert ds_bitrounded_along_lon.lat.size == ds.lat.size
assert ds_bitrounded_along_lon.time.size == ds.time.size
assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype

assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001
assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01

# test for keepbits
ds_bitrounded_along_lon = bi.bitround_along_dim(
ds, info_per_bit, dim="lon", inflevels=None, keepbits=2
)

assert ds_bitrounded_along_lon.air.dtype == "float32"
assert ds_bitrounded_along_lon.air.dtype == "float64"
assert ds_bitrounded_along_lon.lon.size == ds.lon.size
assert ds_bitrounded_along_lon.lat.size == ds.lat.size
assert ds_bitrounded_along_lon.time.size == ds.time.size
assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype

assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001
assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01

# Test error when both keepbits and inflevels are provided
with pytest.raises(ValueError):
Expand Down
24 changes: 12 additions & 12 deletions xbitinfo/xbitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def get_bitinformation( # noqa: C901
-------
>>> ds = xr.tutorial.load_dataset("air_temperature")
>>> xb.get_bitinformation(ds, dim="lon") # doctest: +ELLIPSIS
<xarray.Dataset> Size: 652B
Dimensions: (bitfloat32: 32)
<xarray.Dataset> Size: 1kB
Dimensions: (bitfloat64: 64)
Coordinates:
* bitfloat32 (bitfloat32) <U3 384B '±' 'e1' 'e2' 'e3' ... 'm21' 'm22' 'm23'
* bitfloat64 (bitfloat64) <U3 768B '±' 'e1' 'e2' 'e3' ... 'm50' 'm51' 'm52'
dim <U3 12B 'lon'
Data variables:
air (bitfloat32) float64 256B 0.0 0.0 0.0 ... 3.953e-05 0.0006889
air (bitfloat64) float64 512B 0.0 0.0 0.0 ... 0.002847 0.0 0.0005092
Attributes:
xbitinfo_description: bitinformation calculated by xbitinfo.get_bit...
python_repository: https://github.com/observingClouds/xbitinfo
Expand All @@ -167,13 +167,13 @@ def get_bitinformation( # noqa: C901
xbitinfo_version: ...
BitInformation.jl_version: ...
>>> xb.get_bitinformation(ds)
<xarray.Dataset> Size: 1kB
Dimensions: (bitfloat32: 32, dim: 3)
<xarray.Dataset> Size: 2kB
Dimensions: (bitfloat64: 64, dim: 3)
Coordinates:
* bitfloat32 (bitfloat32) <U3 384B '±' 'e1' 'e2' 'e3' ... 'm21' 'm22' 'm23'
* bitfloat64 (bitfloat64) <U3 768B '±' 'e1' 'e2' 'e3' ... 'm50' 'm51' 'm52'
* dim (dim) <U4 48B 'lat' 'lon' 'time'
Data variables:
air (dim, bitfloat32) float64 768B 0.0 0.0 ... 6.327e-06 0.0004285
air (dim, bitfloat64) float64 2kB 0.0 0.0 0.0 ... 0.0 0.0004498
Attributes:
xbitinfo_description: bitinformation calculated by xbitinfo.get_bit...
python_repository: https://github.com/observingClouds/xbitinfo
Expand Down Expand Up @@ -411,23 +411,23 @@ def get_keepbits(info_per_bit, inflevel=0.99):
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 0.99
Data variables:
air (inflevel) int64 8B 7
air (inflevel) int64 8B 6
>>> xb.get_keepbits(info_per_bit, inflevel=0.99999999)
<xarray.Dataset> Size: 28B
Dimensions: (inflevel: 1)
Coordinates:
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 1.0
Data variables:
air (inflevel) int64 8B 14
air (inflevel) int64 8B 7
>>> xb.get_keepbits(info_per_bit, inflevel=1.0)
<xarray.Dataset> Size: 28B
Dimensions: (inflevel: 1)
Coordinates:
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 1.0
Data variables:
air (inflevel) int64 8B 23
air (inflevel) int64 8B 52
>>> info_per_bit = xb.get_bitinformation(ds)
>>> xb.get_keepbits(info_per_bit)
<xarray.Dataset> Size: 80B
Expand All @@ -436,7 +436,7 @@ def get_keepbits(info_per_bit, inflevel=0.99):
* dim (dim) <U4 48B 'lat' 'lon' 'time'
* inflevel (inflevel) float64 8B 0.99
Data variables:
air (dim, inflevel) int64 24B 5 7 6
air (dim, inflevel) int64 24B 5 6 6
"""
if not isinstance(inflevel, list):
inflevel = [inflevel]
Expand Down

0 comments on commit 47b97f4

Please sign in to comment.