Contributing¶
Guidelines for contributing to the Counterfactuals library.
Code Style¶
- Follow PEP 8 style guidelines
- Use Ruff for linting and formatting
- Maximum line length: 100 characters
- Use type hints for all function signatures
Docstrings¶
Use Google-style docstrings:
def explain(self, X: np.ndarray, y_origin: int, y_target: int) -> ExplanationResult:
"""Generate counterfactual explanations.
Args:
X: Input instances to explain. Shape (n_samples, n_features).
y_origin: Original class label.
y_target: Target class label.
Returns:
ExplanationResult containing counterfactuals and metadata.
Raises:
ValueError: If X has wrong shape.
"""
Testing¶
Run tests with pytest:
Write tests for: - New methods - Bug fixes - Edge cases
Pull Request Process¶
- Fork the repository
- Create a feature branch
- Make changes with tests
- Run linting:
ruff check . - Run tests:
pytest - Submit PR with description
Adding New Methods¶
- Create method class inheriting from
BaseCounterfactualMethod - Implement
fit()andexplain()methods - Add tests in
tests/ - Create pipeline in
pipelines/ - Add documentation
Adding New Metrics¶
- Create metric class inheriting from
Metric - Use
@register_metricdecorator - Implement
required_inputs()and__call__() - Add tests