Comments (3)
As discussed, the function works as intended with correct inputs, but can have improper validation in the demonstrated example, accepting improper input causing a downstream error.
This is due to the automatic structuring of a string as list. If its possible to avoid this automatic conversion this loophole should be fixable.
from baybe.
There is an ugly and a nice solution to this. The core of the problem is that we convert the input of values/active_values to tuple and once this is done, there is no way you can tell whether the original input was a string or any other iterable. That is:
- `tuple("ABC") --> ("A", "B", "C") (which we don't want to happen)
- `tuple(["A", "B", "C"]) --> ("A", "B", "C") (which we do want to happen)
So the only way to catch that first case is to do a check before the conversion happens. It attrs speech, that would mean before calling the converter or as part of the converter.
So the "ugly" solution would be to write a converter utility that does the check and use it instead:
def nonstring2tuple(x: Iterable) -> Tuple:
if isinstance(x, str):
raise ValueError("Input must not be a string.")
return tuple(x)
This would only require to replace converter=tuple
with converter=nonstring2tuple
in placed where we want that check to happen. However, the downside (which I think is a critical one) is that we can hardly raise specific error messages that way.
The "nice" solution would be to use a three-argument converter that also gets the respective context like the validators (i.e., not only the to-be-converted value but also self
and field
), such that we can build a context-specific error message inside the converter. However, this is not (yet) supported by attrs and has been raised in tickets since long time ago. Luckily, there's now an open PR since 4 days that seems about to be merged (perfect timing 😄). So I suggest we wait until the next attrs version is released and solve the problem then 👍🏼
from baybe.
@AdrianSosic I don't consider the second solution ugly
and would support that as an immediate fix. In fact we could debate whether we can also explicitly allow a single str
and and return (x,)
or so if isinstance(x, str)
instead of the raise. But even if not it would solve stuff immediately
from baybe.
Related Issues (20)
- Cannot import 'get_canonical_smiles' from 'baybe.utils' HOT 3
- Update baybe/examples/Basics /campaign.py and baybe/examples/Serialization /basic_serialization.py HOT 3
- Handling of Infinity in serialization HOT 7
- ONNX Vulnerabilities HOT 6
- Python 3.12 blocked by failing config checks HOT 3
- Batch_size error HOT 10
- Installation with Poetry fails with "Package 'baybe[telemetry]' is listed as a dependency of itself." HOT 4
- Expose underlying model of campaign HOT 4
- Recommendations taking a long time HOT 13
- Minor visual issues in the documentation HOT 14
- Simulation bug in `ignore` mode HOT 12
- Error in match mode when trying to take mean of bounds HOT 7
- Return incomplete results when simulation errors out HOT 10
- Random seed being set somewhere hidden inside baybe? HOT 12
- Published docs use main instead of released version HOT 4
- Estimate shape of search space? HOT 5
- ModuleNotFoundError: No module named 'baybe.objectives' HOT 10
- Telemetry code executes and throws in container, even with telemetry disabled HOT 6
- Best way to represent a feature that is a variable-length vector of integers HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from baybe.