Skip to content

Commit 7a299a6

Browse files
authored
small fix for js ints (#182)
1 parent 3683203 commit 7a299a6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

jupyterlab_sql_editor/outputters/util.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,14 @@ def rows_to_html(rows, columns, show_nonprinting, truncate):
676676
return html
677677

678678

679+
def check_js_integer_safety(data, warnings):
680+
if data <= JS_MAX_SAFE_INTEGER and data >= JS_MIN_SAFE_INTEGER:
681+
return data
682+
else:
683+
warnings.append(f"int {data} was cast to string to avoid loss of precision.")
684+
return str(data)
685+
686+
679687
def sanitize_results(data, warnings=[], safe_js_ints=False):
680688
result = dict()
681689

@@ -690,18 +698,17 @@ def sanitize_results(data, warnings=[], safe_js_ints=False):
690698
# For Oracle "integers"
691699
elif isinstance(data, Decimal):
692700
if data == data.to_integral_value():
693-
return int(data)
694-
return data
701+
data = int(data)
702+
if safe_js_ints:
703+
return check_js_integer_safety(data, warnings)
704+
else:
705+
return data
695706
elif isinstance(data, datetime64):
696707
return pd.Timestamp(data)
697708
elif isinstance(data, (bytearray, bytes)):
698709
return data.hex(" ").upper().split().__str__()
699-
elif safe_js_ints and isinstance(data, (int, Decimal)):
700-
if data <= JS_MAX_SAFE_INTEGER and data >= JS_MIN_SAFE_INTEGER:
701-
return data
702-
else:
703-
warnings.append(f"int {data} was cast to string to avoid loss of precision.")
704-
return str(data)
710+
elif safe_js_ints and isinstance(data, (int)):
711+
return check_js_integer_safety(data, warnings)
705712
elif isinstance(data, pt.Row):
706713
for key, value in data.asDict().items():
707714
result[key] = sanitize_results(value, warnings, safe_js_ints)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab-sql-editor",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "SQL editor support for formatting, syntax highlighting and code completion of SQL in cell magic, line magic, python string and file editor.",
55
"keywords": [
66
"jupyter",

0 commit comments

Comments
 (0)