-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: add undefined type #966
Closed
Closed
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0f4e776
undefined
wusteven815 12f4d1e
Merge branch 'main' into 549-python-undefined
wusteven815 6b7cf89
fix ci
wusteven815 b150c3a
fix
wusteven815 ee210e5
fix
wusteven815 0a33478
add review change
wusteven815 219f640
fix test
wusteven815 f5744dd
fix missing refactors
wusteven815 8785672
copy magic methods
wusteven815 cc90950
Merge branch 'main' into 549-python-undefined
wusteven815 76235ab
fix
wusteven815 3235785
refactor
wusteven815 f338845
fix
wusteven815 d0bcedd
add none type
wusteven815 cff17df
add other none types
wusteven815 ffc5ded
Merge branch 'deephaven:main' into 549-python-undefined
wusteven815 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,6 @@ | |||||
import sys | ||||||
from functools import partial | ||||||
from deephaven.time import to_j_instant, to_j_zdt, to_j_local_date, to_j_local_time | ||||||
from deephaven.dtypes import ZonedDateTime, Instant | ||||||
|
||||||
from ..types import ( | ||||||
Date, | ||||||
|
@@ -15,6 +14,7 @@ | |||||
JavaTime, | ||||||
LocalDateConvertible, | ||||||
LocalDate, | ||||||
Undefined, | ||||||
) | ||||||
|
||||||
T = TypeVar("T") | ||||||
|
@@ -36,6 +36,21 @@ | |||||
} | ||||||
|
||||||
|
||||||
def is_nullish(value: Any) -> bool: | ||||||
""" | ||||||
Check if the value is None or Undefined. Although the `__eq__` method for Undefined exists, Python uses the | ||||||
`__eq__` method of the left hand side object. If that method is defined, such as afor Java wrapped types, the | ||||||
behaviour is unexpected. | ||||||
|
||||||
Args: | ||||||
value: The value to check. | ||||||
|
||||||
Returns: | ||||||
If the value is nullish. | ||||||
""" | ||||||
return value is None or value is Undefined | ||||||
|
||||||
|
||||||
def get_component_name(component: Any) -> str: | ||||||
""" | ||||||
Get the name of the component | ||||||
|
@@ -163,7 +178,7 @@ def remove_empty_keys(dict: dict[str, Any]) -> dict[str, Any]: | |||||
Returns: | ||||||
The dict with keys removed. | ||||||
""" | ||||||
return {k: v for k, v in dict.items() if v is not None} | ||||||
return {k: v for k, v in dict.items() if v is not Undefined} | ||||||
|
||||||
|
||||||
def _wrapped_callable( | ||||||
|
@@ -481,7 +496,7 @@ def _get_first_set_key(props: dict[str, Any], sequence: Sequence[str]) -> str | | |||||
The first non-None prop, or None if all props are None. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
for key in sequence: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
return key | ||||||
return None | ||||||
|
||||||
|
@@ -666,11 +681,11 @@ def convert_date_props( | |||||
The converted props. | ||||||
""" | ||||||
for key in simple_date_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = _convert_to_java_date(props[key]) | ||||||
|
||||||
for key in date_range_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = convert_date_range(props[key], _convert_to_java_date) | ||||||
|
||||||
# the simple props must be converted before this to simplify the callable conversion | ||||||
|
@@ -680,25 +695,25 @@ def convert_date_props( | |||||
# Local Dates will default to DAY but we need to default to SECOND for the other types | ||||||
if ( | ||||||
granularity_key is not None | ||||||
and props.get(granularity_key) is None | ||||||
and is_nullish(props.get(granularity_key)) | ||||||
and converter != to_j_local_date | ||||||
): | ||||||
props[granularity_key] = "SECOND" | ||||||
|
||||||
# now that the converter is set, we can convert simple props to strings | ||||||
# no.w that the converter is set, we can convert simple props to strings | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for key in simple_date_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = str(props[key]) | ||||||
|
||||||
# and convert the date range props to strings | ||||||
for key in date_range_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = convert_date_range(props[key], str) | ||||||
|
||||||
# wrap the date callable with the convert | ||||||
# if there are date range props, we need to convert as a date range | ||||||
for key in callable_date_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
if not callable(props[key]): | ||||||
raise TypeError(f"{key} must be a callable") | ||||||
if len(date_range_props) > 0: | ||||||
|
@@ -730,20 +745,20 @@ def convert_time_props( | |||||
The converted props. | ||||||
""" | ||||||
for key in simple_time_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = _convert_to_java_time(props[key]) | ||||||
|
||||||
# the simple props must be converted before this to simplify the callable conversion | ||||||
converter = _prioritized_time_callable_converter(props, priority, default_converter) | ||||||
|
||||||
# now that the converter is set, we can convert simple props to strings | ||||||
for key in simple_time_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
props[key] = str(props[key]) | ||||||
|
||||||
# wrap the date callable with the convert | ||||||
for key in callable_time_props: | ||||||
if props.get(key) is not None: | ||||||
if not is_nullish(props.get(key)): | ||||||
if not callable(props[key]): | ||||||
raise TypeError(f"{key} must be a callable") | ||||||
props[key] = _wrap_time_callable(props[key], converter) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory after this change, this should be the only place that really needs to check for
Undefined
... we should be removing it at this point so it shouldn't need to be known at theElementMessageStream
level or anything.