Skip to content

Commit df72692

Browse files
committed
Add new narwhals types
1 parent cb960c4 commit df72692

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

shiny/render/_data_frame.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,12 @@ async def _patches_handler(self, patches: tuple[CellPatch, ...]) -> Jsonifiable:
644644
# Add (or overwrite) new cell patches by setting each patch into the cell patch map
645645
self._set_cell_patch_map_patches(patches)
646646

647+
# With the patches applied, any data retrieved while processing cell style
648+
# will use the new patch values.
649+
await self._attempt_update_cell_style()
650+
647651
# Upgrade any HTML-like content to `CellHtml` json objects
652+
# for sending to the client
648653
processed_patches: list[CellPatchProcessed] = [
649654
{
650655
"row_index": patch["row_index"],
@@ -658,14 +663,12 @@ async def _patches_handler(self, patches: tuple[CellPatch, ...]) -> Jsonifiable:
658663
for patch in patches
659664
]
660665

661-
# Prep the processed patches for sending to the client
666+
# Prep the processed patches as dictionaries for sending to the client
662667
jsonifiable_patches: list[Jsonifiable] = [
663668
cell_patch_processed_to_jsonifiable(ret_processed_patch)
664669
for ret_processed_patch in processed_patches
665670
]
666671

667-
await self._attempt_update_cell_style()
668-
669672
# Return the processed patches to the client
670673
return jsonifiable_patches
671674

@@ -715,7 +718,7 @@ async def _attempt_update_cell_style(self) -> None:
715718
if not callable(styles_fn):
716719
return
717720

718-
# TODO-barret; Use the returned data type from the rener function!
721+
# TODO-barret; Use the returned data type from the render function!
719722
to_original_type_fn = self._nw_data_to_original_type_fn()
720723
patched_into_data = to_original_type_fn(self._data_patched())
721724
new_styles = as_browser_style_infos(styles_fn, into_data=patched_into_data)

shiny/render/_data_frame_utils/_tbl_data.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from __future__ import annotations
22

3-
from typing import Any, List, Tuple, TypedDict
3+
from typing import Any, List, Tuple, TypedDict, cast
44

55
import narwhals.stable.v1 as nw
66
import orjson
77
from htmltools import TagNode
88

99
from ..._typing_extensions import TypeIs
10-
from ...session import require_active_session
11-
from ._html import maybe_as_cell_html
10+
from ...session import Session, require_active_session
11+
from ...types import Jsonifiable, JsonifiableDict
12+
from ._html import as_cell_html, cell_contains_htmltoolslike
1213
from ._types import (
1314
CellPatch,
1415
CellValue,
@@ -184,6 +185,9 @@ def apply_frame_patches(
184185
nw_categorical = nw.Categorical()
185186
nw_duration = nw.Duration()
186187
nw_enum = nw.Enum()
188+
nw_struct = nw.Struct()
189+
nw_list = nw.List()
190+
nw_array = nw.Array()
187191
nw_string = nw.String()
188192
nw_date = nw.Date()
189193
nw_datetime = nw.Datetime()
@@ -220,7 +224,8 @@ def serialize_dtype(col: nw.Series) -> FrameDtype:
220224
type_ = "object"
221225
if series_contains_htmltoolslike(col):
222226
type_ = "html"
223-
227+
elif dtype in {nw_struct, nw_list, nw_array}:
228+
type_ = "object"
224229
else:
225230
type_ = "unknown"
226231
if series_contains_htmltoolslike(col):

0 commit comments

Comments
 (0)