-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Serializing Date parameters does not support allow_None #578
Comments
I've changed the title, because >>> import param, json
>>> class User(param.Parameterized):
signup_ts = param.Date(allow_None=True, doc="""The sign up time of the user""")
>>> u = User()
>>> print(u.signup_ts)
None Your example above is specifically about serializing Date Parameters whose value is None, and it does look like there is an issue there. @jlstevens?
Right. As pydantic/pydantic#578 says, Pydantic is a parsing library, not a validation library like Param. Pydantic is designed to ensure that usable values are extracted from what is provided by the user, while Param tries to give feedback to the user that what they provided is not suitable. E.g. sure, the user might have meant 3 when they put in the string " 3" or the float 3.14 for an integer, but are we sure? Should it also be 3 for "3..."? or "3 feet" or "three"? At some point you have to give up and stop making assumptions. Param gives up quickly, rejecting anything that's not clearly the right object, while Pydantic will bend over backwards to make it fit. At a downstream level, code with either approach can rest assured that only the indicated type will be provided, but Param takes the position that users need feedback when they do crazy things, not for the program to blindly go forward with potentially undetected issues. Param offers a separate mechanism |
I've not yet investigated deeply but the scheme should be fine as it is implemented like this which means the fix should be trivial |
BTW, I think the serialization support is a red herring for the specific task of comparison with Pydantic. I've added an equivalent to the Pydantic getting started example to https://discourse.holoviz.org/t/creating-an-optional-datetime-parameter-using-param/3147/10, which does not depend on serialization and does support None. |
@jlstevens can this issue be closed? |
Based on the merged PR, I think so... |
Param: 1.12.0
I'm trying to help a user that wants to implement the Pydantic getting started example using Param. https://discourse.holoviz.org/t/creating-an-optional-datetime-parameter-using-param/3147.
He asks how to implement
signup_ts: Optional[datetime] = None
. I think its not possible with the existing parameters as I get the below error.Additional Context
If you look at the Pydantic getting started example you will realize that its
deserializing
is much more flexible/ forgiving as it will be able to converts string to ints for integer parameters, not care so much about the date time format for datetime parameters etc.The text was updated successfully, but these errors were encountered: