Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FixedScaleOffset doc: change scale parameter type to float #356

Merged
merged 3 commits into from
Aug 24, 2024

Conversation

bogovicj
Copy link
Contributor

@bogovicj bogovicj commented Oct 5, 2022

This PR is a small change to the documentation of the FixedScaleOffset:
changing the type of the scale parameter from int to float.

The filter currently behaves reasonably and as I would expect if a passing a float to the scale parameter:

# random angles in the range [-pi,pi]
x = (np.random.random([64]) * 2 * np.pi) - np.pi

# encode in the range [0,255] with a byte
f = FixedScaleOffset(scale= (255.0 / (2.0 * np.pi) ), offset=-np.pi, dtype='float64', astype='uint8')

# behaves as expected
x_enc = f.encode(x)
x_dec = f.decode(x_enc)

and is a potentially useful application of this filter.

As well, this documentation change makes this filter's description consistent with the scale_factor and add_offset attributes of NetCDF.

When scale_factor and add_offset are used for packing, the associated variable (containing the packed data) is typically of type byte or short, whereas the unpacked values are intended to be of type float or double. The attributes scale_factor and add_offset should both be of the type intended for the unpacked data, e.g. float or double.

(emphasis mine)

TODO:

  • Unit tests and/or doctests in docstrings
  • tox -e py310 passes locally
  • Docstrings and API docs for any new/modified user-facing classes and functions
  • Changes documented in docs/release.rst
  • tox -e docs passes locally
  • GitHub Actions CI passes
  • Test coverage to 100% (Coveralls passes)

@jakirkham
Copy link
Member

Thanks John! 🙏

This makes sense to me. Should we add an example in the docstring and maybe a test filter here?

Copy link
Contributor

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an improvement I think worth getting it in, even without an example.

@dstansby dstansby enabled auto-merge (squash) August 24, 2024 07:17
Copy link

codecov bot commented Aug 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.91%. Comparing base (4784a52) to head (862c846).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #356   +/-   ##
=======================================
  Coverage   99.91%   99.91%           
=======================================
  Files          59       59           
  Lines        2334     2334           
=======================================
  Hits         2332     2332           
  Misses          2        2           
Files Coverage Δ
numcodecs/fixedscaleoffset.py 100.00% <ø> (ø)

@dstansby dstansby merged commit 2a7bf9c into zarr-developers:main Aug 24, 2024
25 of 26 checks passed
@jakirkham
Copy link
Member

Adding a test to this file would be good though. As currently this is untested behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants