lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.21k stars 1.78k forks source link

__eq__ Method Fails for QuantLib.Date with None Comparison #2051

Open sergioUjo opened 1 month ago

sergioUjo commented 1 month ago

Description:

I recently updated QuantLib from version 1.32 to 1.35, and noticed that a comparison in my code suddenly broke. The issue suggests that the eq method for QuantLib.Date may not be working as expected.

Steps to Reproduce:

Here's a minimal reproducible example:

import QuantLib as ql

ql_date = ql.Date(1, 1, 2021)

is_false = ql_date == None

Expected Behavior: The comparison ql_date == None should return False, indicating that the ql_date is not equal to None, as None is not a valid Date object.

Actual Behavior: Instead, the code raises the following error:

ValueError: invalid null reference in method 'Date_eq', argument 2 of type 'Date const &'

boring-cyborg[bot] commented 1 month ago

Thanks for posting! It might take a while before we look at your issue, so don't worry if there seems to be no feedback. We'll get to it.

lballabio commented 1 month ago

Hi—it turns out this changed with release 1.34 due to upgrading to SWIG 4.2 (which was necessary to enable Python stable API). I've opened an issue with the SWIG people (https://github.com/swig/swig/issues/2987) to see if that's an intentional change.

In the meantime, if you want to compare with None explicitly, the idiomatic if date is None works.