Skip to content

Conversation

@t20100
Copy link
Member

@t20100 t20100 commented Jan 16, 2026

This MR adds API to retrieve the configuration of the filter in a more explicit way than through the filter_options tuple of ints.

  • It adds a get_config() -> dict methods (to do the same as numcodecs) to all filters which returns the kwargs to pass to the given filter to instantiate one with the same configuration.
  • It adds some @property to give access to those parameters to some filters. This is not done for Zfp, Sperr, SZ and SZ3 where the parameter schema is a bit more complex.
  • It adds support for repr

closes #371
closes #370

@t20100 t20100 added this to the 6.1.0 milestone Jan 16, 2026
@t20100 t20100 force-pushed the add-properties-get_config-repr branch 4 times, most recently from 158889b to b08012d Compare January 19, 2026 10:45
@t20100 t20100 force-pushed the add-properties-get_config-repr branch from b08012d to 2bd766c Compare January 20, 2026 10:36
@t20100 t20100 changed the title Added API to get filter config: properties, get_config; Added repr() Added get_config method and repr support to all filters; Add parameter properties to some filters Jan 20, 2026
@t20100 t20100 force-pushed the add-properties-get_config-repr branch from 2bd766c to d63b597 Compare January 20, 2026 10:44
@t20100 t20100 marked this pull request as ready for review January 20, 2026 10:44
filter_id: int
filter_name: str

def _init(
Copy link
Member Author

Choose a reason for hiding this comment

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

Do not use __init__ to avoid providing a typed signature for __init__ since all inherited classes have a different __init__..
Not so nice but working

Copy link
Member

Choose a reason for hiding this comment

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

Fine having _init else to not have it typed you can have something very generic like __init__(self, *args, **kwargs) maybe ?

Comment on lines +194 to +207
@property
def nelems(self) -> int:
"""Number of elements per block"""
return self.filter_options[0]

@property
def cname(self) -> Bitshuffle._CNameType:
"""Compressor name"""
return _cname_from_id(self.filter_options[1], self.__COMPRESSIONS)

@property
def clevel(self) -> int | None:
"""Compression level, only for `zstd` compressor, None for others"""
return self.filter_options[2] if self.cname == "zstd" else None
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding properties for the "simple" filter_options.

Copy link
Member

Choose a reason for hiding this comment

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

if compressor is zstd are we sure filter_options with have at least 3 elements ?

with self.subTest(filter=filter_class.filter_name):
filter_instance = filter_class()
repr_string = repr(filter_instance)
repr_instance = eval(
Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping this test here so it is not installed since it uses eval.

@property
def nelems(self) -> int:
"""Number of elements per block"""
return self.filter_options[0]
Copy link
Member

Choose a reason for hiding this comment

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

filter_options can be empty I think (default value is an empty tuple).

filter_id: int
filter_name: str

def _init(
Copy link
Member

Choose a reason for hiding this comment

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

Fine having _init else to not have it typed you can have something very generic like __init__(self, *args, **kwargs) maybe ?

Comment on lines +194 to +207
@property
def nelems(self) -> int:
"""Number of elements per block"""
return self.filter_options[0]

@property
def cname(self) -> Bitshuffle._CNameType:
"""Compressor name"""
return _cname_from_id(self.filter_options[1], self.__COMPRESSIONS)

@property
def clevel(self) -> int | None:
"""Compression level, only for `zstd` compressor, None for others"""
return self.filter_options[2] if self.cname == "zstd" else None
Copy link
Member

Choose a reason for hiding this comment

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

if compressor is zstd are we sure filter_options with have at least 3 elements ?

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.

Add read-only properties + get_config to filter class to retrieve current filter config Add __repr__ to filter class

2 participants