Skip to content

Commit f8d7c13

Browse files
committed
Add note about narwhals inspecting only the first sentence
1 parent 71ead9f commit f8d7c13

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

shiny/render/_data_frame.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,30 @@ class data_frame(
124124
the user's edits, sorting, and filtering will be lost. We hope to improve upon this
125125
in the future.
126126
127+
Narwhals
128+
-------------------
129+
130+
Shiny uses [`narwhals`](https://narwhals-dev.github.io/narwhals/) to manage data
131+
frame interactions. From their website: "Extremely lightweight and extensible
132+
compatibility layer between dataframe libraries!". This allows for seamless
133+
integration between pandas, polars, and any other eagerly defined data frame type.
134+
135+
There are some reasonable limitations to the narwhals compatibility layer. As they
136+
are found, they will be added to this list:
137+
* When converting the column type who does not have a 1:1 mapping between libraries
138+
(such as pandas' columns containing `str` and `dict` items both share the same
139+
`object` data type), narwhals will only inspect the first row to disambiguate the
140+
cell type. This could lead to false negatives in the data type conversion. Shiny
141+
could inspect each column in an attempt to disambiguate the cell type, but this
142+
would be a costly operation. The best way to avoid this is to use consistent
143+
typing. For example, if your first row of the pandas column contains a string and
144+
the second row of the same column contains a `ui.TagList`, the column will
145+
incorrectly be interpreted as a string. To get around this, you can wrap all cells
146+
(or at the very lest the first cell) in the same column within a `ui.TagList` as
147+
it will not insert any tags, but it will cause the column to be interpreted as
148+
`html` where possible. (tl/dr: Use consistent typing in your columns!)
149+
150+
127151
Tip
128152
---
129153
This decorator should be applied **before** the ``@output`` decorator (if that

0 commit comments

Comments
 (0)