-
-
Notifications
You must be signed in to change notification settings - Fork 65
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃挭馃徏 making orjson serialization more robust, see #118 #131
Conversation
Codecov Report
@@ Coverage Diff @@
## main #131 +/- ##
==========================================
- Coverage 97.44% 93.87% -3.58%
==========================================
Files 11 11
Lines 862 865 +3
==========================================
- Hits 840 812 -28
- Misses 22 53 +31
馃摚 We鈥檙e building smart automated test selection to slash your CI/CD build times. Learn more |
plotly_resampler/figure_resampler/figure_resampler_interface.py
Outdated
Show resolved
Hide resolved
# NOTE: | ||
# * float16 and float128 aren't supported with latest orjson versions (3.8.1) | ||
# * this method assumes that the it will not get a float128 series | ||
if series.dtype in [np.float16]: |
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.
Hmmm, actually this allows for weird / unexpected behavior - see below
y = np.randon.randn(3_000).astype(np.float16)
When len(y) > default_n_shown_samples
=> works like a charm 馃敟
When len(y) <= default_n_shown_samples
=> crashes 馃挜
The eventual error is quite clean tho
TypeError: unsupported datatype in numpy array
What is your opinion on this? @jonasvdd
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.
Maybe we better add smth to the FAQ?
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.
I think you've cut of the error message, will try to reproduce this locally and see how clean the error message actually is.
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.
After giving it some more thought. I see two paths forward;
So I'll go forward with removing the code that makes orjson "more robust". On another note, I think the key to add |
I think if we make @staticmethod
def _parse_dtype_orjson(series: np.ndarray) -> np.ndarray:
"""Verify the orjson compatibility of the series and convert it if needed."""
# NOTE:
# * float16 and float128 aren't supported with latest orjson versions (3.8.1)
# * this method assumes that the it will not get a float128 series
if series.dtype in [np.float16]:
return series.astype(np.float32)
# orjson < 3.8.0 encoding cannot encode with int16 & uint16 dtype
if series.dtype in [np.int16, np.uint16]:
major_v, minor_v = list(map(int, orjson.__version__.split(".")))[:2]
if major_v < 3 or major_v == 3 and minor_v < 8:
if series.dtype == np.uint16:
return series.astype("uint32")
return series.astype(np.int32)
return series to this code: @staticmethod
def _parse_dtype_orjson(series: np.ndarray) -> np.ndarray:
"""Verify the orjson compatibility of the series and convert it if needed."""
# NOTE:
# * float16 and float128 aren't supported with latest orjson versions (3.8.1)
# * this method assumes that the it will not get a float128 series
if series.dtype in [np.float16]:
return series.astype(np.float32)
return series Note that we do not provide any support for the |
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.
If you agree with my latest changes @jonasvdd we can merge it and create a new release
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.
LGTM
No description provided.