Skip to content

[MNT] BaseTransform: replace ValueError with NotImplementedError for abstract methods and add missing module-level attributes #636

@Ishiezz

Description

@Ishiezz

Describe the maintenance task

pyaptamer/trafos/base/_base.py has three issues that should be addressed together:

1. Abstract methods raise ValueError instead of NotImplementedError

_fit, _transform, and _transform_element are abstract methods that raise
ValueError when called directly. Python's convention — and the convention used
by skbase.BaseEstimator which BaseTransform inherits from — is to raise
NotImplementedError for unimplemented abstract methods.

# Current (wrong):
def _fit(self, X, y=None):
    raise ValueError("abstract method _fit called, this should be implemented in the subclass")

# Should be:
def _fit(self, X, y=None):
    raise NotImplementedError("abstract method _fit called, this should be implemented in the subclass")

Using ValueError is misleading because it suggests the error is caused by bad
input values rather than a missing implementation. It can also cause issues if any
upstream code has a bare except ValueError clause that would silently swallow it.

The same applies to _transform and _transform_element.

2. Missing __author__ tag

Every other module in pyaptamer has __author__ = [...]. This file has none.

3. Missing __all__ tag

Every other public module in pyaptamer has __all__ = [...]. This file has none.

Files affected

  • pyaptamer/trafos/base/_base.py

Fix

  • Replace 3x raise ValueError(...)raise NotImplementedError(...) for the abstract methods
  • Add __author__ = ["nennomp", "fkiraly"] (consistent with _tags["authors"] in GreedyEncoder)
  • Add __all__ = ["BaseTransform"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions