Skip to content

Commit 6157b8a

Browse files
authored
Merge pull request #139 from rstudio/fix-rsc-preview
Fix rsc preview
2 parents 20bd962 + a80b382 commit 6157b8a

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
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/_snapshots/test_board_pin_write_rsc_index_html/data.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ api_version: 1
22
created: 20200113T235859Z
33
description: some description
44
file: test_rsc_pin.csv
5-
file_size: 16
6-
pin_hash: d6820e2d11300a70
5+
file_size: 19
6+
pin_hash: a6cf5331bf3de6c6
77
title: some pin
88
type: csv
99
user: {}

pins/tests/_snapshots/test_board_pin_write_rsc_index_html/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ <h3>derek/test_rsc_pin</h3>
4545
created: 20200113T235859Z
4646
description: some description
4747
file: test_rsc_pin.csv
48-
file_size: 16
49-
pin_hash: d6820e2d11300a70
48+
file_size: 19
49+
pin_hash: a6cf5331bf3de6c6
5050
title: some pin
5151
type: csv
5252
user: {}
@@ -76,7 +76,7 @@ <h3>Code</h3>
7676
<h3>Preview <small>(up to 100 rows)</small></h3>
7777
<div data-pagedtable style="height: 25em;">
7878
<script data-pagedtable-source type="application/json">
79-
{"data": [{"x": 1, "y": "a"}, {"x": 2, "y": "b"}, {"x": 3, "y": "c"}], "columns": [{"name": ["x"], "label": ["x"], "align": ["left"], "type": [""]}, {"name": ["y"], "label": ["y"], "align": ["left"], "type": [""]}]}
79+
{"data": [{"x": 1.0, "y": "a"}, {"x": 2.0, "y": "b"}, {"y": "c"}], "columns": [{"name": ["x"], "label": ["x"], "align": ["left"], "type": [""]}, {"name": ["y"], "label": ["y"], "align": ["left"], "type": [""]}]}
8080
</script>
8181
</div>
8282
</section>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
x,y
2-
1,a
3-
2,b
4-
3,c
2+
1.0,a
3+
2.0,b
4+
,c

pins/tests/test_boards.py

Lines changed: 1 addition & 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

0 commit comments

Comments
 (0)