Skip to content

Commit d66e1de

Browse files
committed
Update docs
1 parent 77d6085 commit d66e1de

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

shiny/_deprecated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class ShinyDeprecationWarning(RuntimeWarning):
2323
warnings.simplefilter("always", ShinyDeprecationWarning)
2424

2525

26-
def warn_deprecated(message: str):
27-
warnings.warn(message, ShinyDeprecationWarning, stacklevel=3)
26+
def warn_deprecated(message: str, stacklevel: int = 3):
27+
warnings.warn(message, ShinyDeprecationWarning, stacklevel=stacklevel)
2828

2929

3030
def render_text():

shiny/render/_data_frame.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ class data_frame(
6464
]
6565
):
6666
"""
67-
Decorator for a function that returns a [pandas](https://pandas.pydata.org/) or
68-
[polars](https://pola.rs/) `DataFrame` object to render as an interactive table or
69-
grid. Features fast virtualized scrolling, sorting, filtering, and row selection
70-
(single or multiple).
67+
Decorator for a function that returns a [pandas](https://pandas.pydata.org/),
68+
[polars](https://pola.rs/), or eager
69+
[`narwhals`](https://narwhals-dev.github.io/narwhals/) compatible `DataFrame` object
70+
to render as an interactive table or grid. Features fast virtualized scrolling,
71+
sorting, filtering, and row selection (single or multiple).
7172
7273
Returns
7374
-------
@@ -77,8 +78,10 @@ class data_frame(
7778
1. A :class:`~shiny.render.DataGrid` or :class:`~shiny.render.DataTable` object,
7879
which can be used to customize the appearance and behavior of the data frame
7980
output.
80-
2. A pandas `DataFrame` object or a polars `DataFrame` object. This object will
81-
be internally upgraded to `shiny.render.DataGrid(df)`.
81+
2. A [pandas](https://pandas.pydata.org/), [polars](https://pola.rs/), or eager
82+
[`narwhals`](https://narwhals-dev.github.io/narwhals/) compatible `DataFrame`
83+
object. This object will be internally upgraded to a default
84+
`shiny.render.DataGrid(df)`.
8285
8386
Row selection
8487
-------------
@@ -228,7 +231,9 @@ def data_view(self, *, selected: bool = False) -> IntoDataFrameT:
228231
229232
See Also
230233
--------
231-
* [`pandas.DataFrame.copy` API documentation]h(ttps://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.copy.html)
234+
* [`pandas.DataFrame.copy` API documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.copy.html)
235+
* [`polars.DataFrame.clone` API documentation](https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.clone.html)
236+
* [`narwhals.DataFrame.clone` API documentation](https://narwhals-dev.github.io/narwhals/api-reference/dataframe/#narwhals.dataframe.DataFrame.clone)
232237
"""
233238
# Return reactive calculations so that they can be cached for other calculations
234239
if selected:

shiny/render/_data_frame_utils/_datagridtable.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TODO-future-barret; Maybe use a `._options()` method to return a `JsonifiableDict` within the DataGrid/DataTable classes?
2+
# TODO-future-barret; Really feals as if we should have a base class that does most of this for us
3+
14
from __future__ import annotations
25

36
import abc
@@ -39,8 +42,9 @@ class DataGrid(AbstractTabularData, Generic[IntoDataFrameT]):
3942
Parameters
4043
----------
4144
data
42-
A pandas or polars `DataFrame` object. If the object has a `.to_pandas()`
43-
method, use the pandas form of your data.
45+
A [pandas](https://pandas.pydata.org/), [polars](https://pola.rs/), or
46+
eager [`narwhals`](https://narwhals-dev.github.io/narwhals/) compatible `DataFrame`
47+
object.
4448
width
4549
A _maximum_ amount of horizontal space for the data grid to occupy, in CSS units
4650
(e.g. `"400px"`) or as a number, which will be interpreted as pixels. The
@@ -136,10 +140,6 @@ def __init__(
136140
styles: StyleInfo | list[StyleInfo] | StyleFn[IntoDataFrameT] | None = None,
137141
row_selection_mode: RowSelectionModeDeprecated = "deprecated",
138142
):
139-
140-
# self._data_is_nw = isinstance(data, NwDataFrameRaw)
141-
# self.data = as_narwhals(data)
142-
# self.data = as_nw_friendly_data_frame(data)
143143
self.data = data
144144

145145
self.width = width
@@ -201,8 +201,9 @@ class DataTable(AbstractTabularData, Generic[IntoDataFrameT]):
201201
Parameters
202202
----------
203203
data
204-
A pandas or polars `DataFrame` object. If the object has a `.to_pandas()`
205-
method, use the pandas form of your data.
204+
A [pandas](https://pandas.pydata.org/), [polars](https://pola.rs/), or
205+
eager [`narwhals`](https://narwhals-dev.github.io/narwhals/) compatible `DataFrame`
206+
object.
206207
width
207208
A _maximum_ amount of vertical space for the data table to occupy, in CSS units
208209
(e.g. `"400px"`) or as a number, which will be interpreted as pixels. The

shiny/render/_data_frame_utils/_tbl_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def as_data_frame(
5555
return nw.from_native(data, eager_only=True)
5656
except TypeError as e:
5757
try:
58-
return nw.from_native(compatible_to_pandas(data), eager_only=True)
58+
compatible_data = compatible_to_pandas(data)
59+
return nw.from_native(compatible_data, eager_only=True)
5960
except TypeError:
6061
# Couldn't convert to pandas, so raise the original error
6162
raise e
@@ -79,7 +80,8 @@ def compatible_to_pandas(
7980
"A `.to_pandas()` was found on your object and will be called. "
8081
"To remove this warning, please call `.to_pandas()` on your data "
8182
"and use the pandas result in your returned value. "
82-
"In the future, this will raise an error."
83+
"In the future, this will raise an error.",
84+
stacklevel=3,
8385
)
8486
return data.to_pandas()
8587

0 commit comments

Comments
 (0)