Skip to content

Commit dfe261c

Browse files
committed
fix an OverflowError when showing pl.UInt64 values
1 parent a2044f4 commit dfe261c

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
ITables ChangeLog
22
=================
33

4+
2.1.4 (2024-07-03)
5+
------------------
6+
7+
**Fixed**
8+
- 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))
9+
10+
411
2.1.3 (2024-06-22)
512
------------------
613

src/itables/datatables_format.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ def datatables_rows(df, count=None, warn_on_unexpected_types=False, pure_json=Fa
114114
import polars as pl
115115

116116
has_bigints = any(
117-
x.dtype in [pl.Int64, pl.UInt64]
118-
and ((x > JS_MAX_SAFE_INTEGER).any() or (x < JS_MIN_SAFE_INTEGER).any())
117+
(
118+
x.dtype == pl.Int64
119+
and ((x > JS_MAX_SAFE_INTEGER).any() or (x < JS_MIN_SAFE_INTEGER).any())
120+
)
121+
or (x.dtype == pl.UInt64 and (x > JS_MAX_SAFE_INTEGER).any())
119122
for x in (df[col] for col in df.columns)
120123
)
121124
js = json.dumps(data, cls=generate_encoder(False), allow_nan=not pure_json)

src/itables/sample_dfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ def get_dict_of_test_series(polars=False):
301301

302302
# Add a Polar table with unsigned integers
303303
# https://github.com/mwouts/itables/issues/192
304-
polars_series["u32"] = (
305-
pl.DataFrame({"foo": [1, 1, 3, 1]}).groupby("foo").count()
306-
)
304+
# https://github.com/mwouts/itables/issues/299
305+
polars_series["u32"] = pl.Series([1, 2, 5]).cast(pl.UInt32)
306+
polars_series["u64"] = pl.Series([1, 2, 2**40]).cast(pl.UInt64)
307307

308308
return polars_series
309309

src/itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "2.1.3"
3+
__version__ = "2.1.4"

0 commit comments

Comments
 (0)