Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuantLib.Date arithmetic with tuples #609

Open
eltoder opened this issue Jan 27, 2024 · 3 comments
Open

QuantLib.Date arithmetic with tuples #609

eltoder opened this issue Jan 27, 2024 · 3 comments

Comments

@eltoder
Copy link
Contributor

eltoder commented Jan 27, 2024

I've found the following code in the Python SWIG bindigs:

%pythoncode %{
Date._old___add__ = Date.__add__
Date._old___sub__ = Date.__sub__
def Date_new___add__(self,x):
    if type(x) is tuple and len(x) == 2:
        return self._old___add__(Period(x[0],x[1]))
    else:
        return self._old___add__(x)
def Date_new___sub__(self,x):
    if type(x) is tuple and len(x) == 2:
        return self._old___sub__(Period(x[0],x[1]))
    else:
        return self._old___sub__(x)
Date.__add__ = Date_new___add__
Date.__sub__ = Date_new___sub__
%}

This allows adding/subtracting tuples of size 2 to/from Dates as a shortcut for using Period class. As far as I can tell, this is not documented and not tested. It's also not any faster than using Periods, since it is implemented in python. In fact, this is slowing down normal operations and is one of the blockers for using SWIG -builtin option.

Is this feature really needed? If it is desired, it can be implemented more generally and efficiently using typemaps. It seems rather dubious to me though, so if possible I'd vote to remove it altogther.

@lballabio
Copy link
Owner

Huh. That's weird. Git logs tell me that that code is from 2004, but give me no hint about why we wrote it.
I'd deprecate it for a release or two and then remove it.

@lballabio
Copy link
Owner

Deprecation done in #612. Let's circle back in a while.

@eltoder
Copy link
Contributor Author

eltoder commented Jan 29, 2024

Thank you.

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

No branches or pull requests

2 participants