Skip to content

UBRE score is shifted by +2 * scale due to incorrect boolean inversion using bitwise #592

Description

@gitishman

When running pyGAM with Python 3.13+, a DeprecationWarning is triggered during model scoring or grid search for models with a known scale (e.g. PoissonGAM or BinomialGAM).

The warning points to pygam/pygam.py at line 1223:
Deprecation Warning: Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.

Upon investigating, using the bitwise inversion operator ~ on the bo0lean parameter add scale is not only deprecated but also introduces a mathematical bug that shifts the calculated UBRE score by exactly + 2 * scale under all settings.

Main Cause -
In Python, bool is a subclass of int. The bitwise negation operator ~ maps x to -(x + 1). Thus:

~True (which is ~1) evaluates to -2 (instead of False or 0).
~False (which is ~0) evaluates to -1 (instead of True or 1).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions