QuantLib-SWIG icon indicating copy to clipboard operation
QuantLib-SWIG copied to clipboard

__eq__ Method Fails for QuantLib.Date with None Comparison

Open sergioUjo opened this issue 1 year ago • 5 comments

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 &'

sergioUjo avatar Aug 05 '24 16:08 sergioUjo

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.

boring-cyborg[bot] avatar Aug 05 '24 16:08 boring-cyborg[bot]

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.

lballabio avatar Aug 06 '24 14:08 lballabio

Fixed on the SWIG side. We'll have to wait for the next SWIG release.

lballabio avatar Sep 16 '24 14:09 lballabio

Moving the issue to the QuantLib-SWIG repo.

lballabio avatar Sep 22 '24 15:09 lballabio

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.

boring-cyborg[bot] avatar Sep 22 '24 15:09 boring-cyborg[bot]

This issue was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.

github-actions[bot] avatar Nov 22 '24 02:11 github-actions[bot]

Fixed in SWIG 4.3, which will be used to produce the wheels for next release.

lballabio avatar Nov 22 '24 09:11 lballabio