Skip to content

Commit 32b4360

Browse files
committed
fix(rsc): preview error when displaying missing data
1 parent 20bd962 commit 32b4360

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pins/boards.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,21 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
943943

944944
if isinstance(x, pd.DataFrame):
945945
# TODO(compat) is 100 hard-coded?
946+
# Note that we go df -> json -> dict, to take advantage of pandas type conversions
946947
data = json.loads(x.head(100).to_json(orient="records"))
947948
columns = [
948949
{"name": [col], "label": [col], "align": ["left"], "type": [""]}
949950
for col in x
950951
]
951952

952-
context["data_preview"] = json.dumps({"data": data, "columns": columns})
953+
# this reproduces R pins behavior, by omitting entries that would be null
954+
data_no_nulls = [
955+
{k: v for k, v in row.items() if v is not None} for row in data
956+
]
957+
958+
context["data_preview"] = json.dumps(
959+
{"data": data_no_nulls, "columns": columns}
960+
)
953961
else:
954962
# TODO(compat): set display none in index.html
955963
context["data_preview"] = json.dumps({})

pins/tests/test_boards.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
100100
if board.fs.protocol != "rsc":
101101
pytest.skip()
102102

103-
df = pd.DataFrame({"x": [1, 2, 3], "y": ["a", "b", "c"]})
103+
df = pd.DataFrame({"x": [1, 2, None], "y": ["a", "b", "c"]})
104104

105105
pin_name = "test_rsc_pin"
106106

@@ -113,6 +113,7 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
113113
description="some description",
114114
created=DEFAULT_CREATION_DATE,
115115
)
116+
assert False
116117

117118
snapshot.assert_equal_dir(tmp_dir2)
118119

0 commit comments

Comments
 (0)