From 661f7581b23a5ba99386891df0ad8080a3be952b Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Tue, 25 Jun 2024 21:10:38 +0100 Subject: [PATCH] fix an OverflowError when showing pl.UInt64 values --- docs/changelog.md | 7 +++++++ src/itables/datatables_format.py | 7 +++++-- src/itables/sample_dfs.py | 6 +++--- src/itables/version.py | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 59b07091..6e055a75 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,6 +1,13 @@ ITables ChangeLog ================= +2.1.4-dev (2024-06-22) +------------------ + +**Fixed** +- We have fixed an OverflowError (_can't convert negative int to unsigned_) when displaying Polars DataFrames that contain unsigned integers ([#299](https://github.com/mwouts/itables/issues/299)) + + 2.1.3 (2024-06-22) ------------------ diff --git a/src/itables/datatables_format.py b/src/itables/datatables_format.py index 35232a29..5fb3b861 100644 --- a/src/itables/datatables_format.py +++ b/src/itables/datatables_format.py @@ -114,8 +114,11 @@ def datatables_rows(df, count=None, warn_on_unexpected_types=False, pure_json=Fa import polars as pl has_bigints = any( - x.dtype in [pl.Int64, pl.UInt64] - and ((x > JS_MAX_SAFE_INTEGER).any() or (x < JS_MIN_SAFE_INTEGER).any()) + ( + x.dtype == pl.Int64 + and ((x > JS_MAX_SAFE_INTEGER).any() or (x < JS_MIN_SAFE_INTEGER).any()) + ) + or (x.dtype == pl.UInt64 and (x > JS_MAX_SAFE_INTEGER).any()) for x in (df[col] for col in df.columns) ) js = json.dumps(data, cls=generate_encoder(False), allow_nan=not pure_json) diff --git a/src/itables/sample_dfs.py b/src/itables/sample_dfs.py index 7780ef1c..89c9b523 100644 --- a/src/itables/sample_dfs.py +++ b/src/itables/sample_dfs.py @@ -301,9 +301,9 @@ def get_dict_of_test_series(polars=False): # Add a Polar table with unsigned integers # https://github.com/mwouts/itables/issues/192 - polars_series["u32"] = ( - pl.DataFrame({"foo": [1, 1, 3, 1]}).groupby("foo").count() - ) + # https://github.com/mwouts/itables/issues/299 + polars_series["u32"] = pl.Series([1, 2, 5]).cast(pl.UInt32) + polars_series["u64"] = pl.Series([1, 2, 2**40]).cast(pl.UInt64) return polars_series diff --git a/src/itables/version.py b/src/itables/version.py index 95c7d255..be7b81ad 100644 --- a/src/itables/version.py +++ b/src/itables/version.py @@ -1,3 +1,3 @@ """ITables' version number""" -__version__ = "2.1.3" +__version__ = "2.1.4-dev"