Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Python custom justifications with Decimal scores #1344

Merged

Conversation

Christopher-Chianelli
Copy link
Contributor

The translator automatically converts the result of Java method calls on Java objects into the corresponding Python types. This is normally wanted, since it allow users to use the result of ConstraintCollectors (which are Java objects).

However, to_python_score does not want this; it expects the normal Java result. It is typically called in an untranslated context and thus usually does not run into this issue. However, when a custom justification function is used, it is called in a translation context. For normal scores, it works, since we don't access any properties of the long when creating the corresponding Python score. For decimal scores, we call toPlainString() so we can create a Python Decimal instance from a Java BigDecimal. Python Decimal does not have a toPlainString method normally, so it causes an attribute lookup failure at runtime.

The fix is to add a toPlainString method to PythonDecimal, that just delegate to the toPlainString method of its value.

The translator automatically converts the result of Java method calls
on Java objects into the corresponding Python types. This is normally
wanted, since it allow users to use the result of ConstraintCollectors
(which are Java objects).

However, `to_python_score` does not want this; it expects the normal
Java result. It is typically called in an untranslated context and
thus usually does not run into this issue. However, when a custom
justification function is used, it is called in a translation
context. For normal scores, it works, since we don't access any
properties of the long when creating the corresponding Python
score. For decimal scores, we call toPlainString() so we can
create a Python Decimal instance from a Java BigDecimal.
Python Decimal does not have a toPlainString method normally,
so it causes an attribute lookup failure at runtime.

The fix is to add a toPlainString method to PythonDecimal,
that just delegate to the toPlainString method of its value.
Copy link

sonarqubecloud bot commented Jan 22, 2025

@triceo triceo added this to the v1.19.0 milestone Jan 22, 2025
@triceo triceo merged commit 8ca431c into TimefoldAI:main Jan 22, 2025
29 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants