Skip to content

Commit

Permalink
fix an OverflowError when showing pl.UInt64 values
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 25, 2024
1 parent a2044f4 commit 661f758
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
7 changes: 5 additions & 2 deletions src/itables/datatables_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/itables/sample_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/itables/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""ITables' version number"""

__version__ = "2.1.3"
__version__ = "2.1.4-dev"

0 comments on commit 661f758

Please sign in to comment.