Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 30, 2024
1 parent 59f2089 commit 8951960
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/test_get_bitinformation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Tests for `xbitinfo` package."""

import os
import warnings

import numpy as np
import pytest
import xarray as xr
import warnings
from numpy.testing import assert_allclose, assert_equal
from xarray.core import formatting
from xarray.core.dataarray import DataArray
Expand Down Expand Up @@ -272,4 +272,4 @@ def test_warn_on_quantized_variables(dataset_name, implementation):

with warnings.catch_warnings():
warnings.simplefilter("error")
_ = xb.get_bitinformation(ds_raw, implementation=implementation)
_ = xb.get_bitinformation(ds_raw, implementation=implementation)
6 changes: 4 additions & 2 deletions xbitinfo/xbitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def get_bitinformation( # noqa: C901
quantized_storage_dtype = ds[var].encoding["dtype"]
warnings.warn(
f"Variable {var} is quantized as {quantized_storage_dtype}, but loaded as {loaded_dtype}. Consider reopening using `mask_and_scale=False` to get sensible results",
category=UserWarning
category=UserWarning,
)

if implementation == "julia":
Expand Down Expand Up @@ -273,7 +273,9 @@ def get_bitinformation( # noqa: C901
def _quantized_variable_is_scaled(ds: xr.DataArray, var: str) -> bool:
loaded_dtype = ds[var].dtype
quantized_storage_dtype = ds[var].encoding["dtype"]
has_scale_or_offset = any(["add_offset" in ds[var].encoding, "scale_factor" in ds[var].encoding])
has_scale_or_offset = any(
["add_offset" in ds[var].encoding, "scale_factor" in ds[var].encoding]
)

if has_scale_or_offset and quantized_storage_dtype != loaded_dtype:
return True
Expand Down

0 comments on commit 8951960

Please sign in to comment.