Skip to content

Replace print() with warnings.warn() for warning messages#164

Merged
oliverchampion merged 1 commit into
OSIPI:mainfrom
Devguru-codes:fix-print-to-warnings
May 6, 2026
Merged

Replace print() with warnings.warn() for warning messages#164
oliverchampion merged 1 commit into
OSIPI:mainfrom
Devguru-codes:fix-print-to-warnings

Conversation

@Devguru-codes

Copy link
Copy Markdown
Contributor

Replace all print() calls used for warning/informational messages with proper warnings.warn() calls across the standardized algorithm implementations and OsipiBase.py. This makes warnings suppressible, testable with pytest.warns(), and consistent with Python best practices.

Pattern that i am using here -

# Before:
print('warning, no thresholds were defined, so default threshold are used of 200')

# After:
warnings.warn('No thresholds were defined, so default threshold of 200 is used', UserWarning, stacklevel=2)

stacklevel=2 ensures the warning points to the caller's code, not the library internals and UserWarning category allows users to filter/suppress via warnings.filterwarnings()

Fixes #163

…cross 15 files

- Replace 20 print() calls used for warnings with warnings.warn(UserWarning, stacklevel=2)
- Add 'import warnings' where not already present (8 files)
- Affects 14 standardized algorithm files + OsipiBase.py
- Makes warnings suppressible via warnings.filterwarnings() and testable via pytest.warns()
- Preserves intentional display prints in osipi_print_requirements/bias/citation
@oliverchampion oliverchampion merged commit 1290af0 into OSIPI:main May 6, 2026
9 checks passed
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.

[BUG] Replace print() with warnings.warn() for warning messages

2 participants