Skip to content

Commit 3ce71f9

Browse files
committed
Remove small and unused narwals wrapper methods
1 parent c397e82 commit 3ce71f9

File tree

6 files changed

+16
-72
lines changed

6 files changed

+16
-72
lines changed

shiny/render/_data_frame.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
apply_frame_patches,
3838
as_data_frame,
3939
data_frame_to_native,
40-
frame_shape,
4140
subset_frame,
4241
)
4342
from ._data_frame_utils._types import (
@@ -442,7 +441,7 @@ def cell_selection(self) -> CellSelection:
442441
selection_modes=self.selection_modes(),
443442
nw_data=self._nw_data(),
444443
data_view_rows=self.data_view_rows(),
445-
data_view_cols=tuple(range(frame_shape(self._nw_data())[1])),
444+
data_view_cols=tuple(range(self._nw_data().shape[1])),
446445
)
447446

448447
return cell_selection
@@ -954,7 +953,7 @@ async def update_sort(
954953
if len(sort) > 0:
955954
with reactive.isolate():
956955
nw_data = self._nw_data()
957-
ncol = frame_shape(nw_data)[1]
956+
ncol = nw_data.shape[1]
958957

959958
for val in sort:
960959
val_dict: ColumnSort
@@ -995,8 +994,7 @@ async def update_filter(
995994
filter = []
996995
else:
997996
with reactive.isolate():
998-
shape = frame_shape(self._nw_data())
999-
ncol = shape[1]
997+
ncol = self._nw_data().shape[1]
1000998

1001999
for column_filter, i in zip(filter, range(len(filter))):
10021000
assert isinstance(column_filter, dict)

shiny/render/_data_frame_utils/_selection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from ..._deprecated import warn_deprecated
99
from ..._typing_extensions import TypedDict
1010
from ...types import ListOrTuple
11-
from ._tbl_data import frame_shape
1211
from ._types import DataFrame, FrameRenderSelectionModes
1312

1413
NoneSelectionMode = Literal["none"]
@@ -240,7 +239,7 @@ def as_browser_cell_selection(
240239
return {"type": "none"}
241240

242241
if x == "all":
243-
row_len, col_len = frame_shape(nw_data)
242+
row_len, col_len = nw_data.shape
244243
# Look at the selection modes to determine what to do
245244
if selection_modes._has_rect():
246245
if selection_modes.rect == "cell":
@@ -379,7 +378,7 @@ def as_cell_selection(
379378
)
380379

381380
# Make sure the rows are within the data
382-
nrow, ncol = frame_shape(nw_data)
381+
nrow, ncol = nw_data.shape
383382
ret["rows"] = tuple(row for row in ret["rows"] if row < nrow)
384383
ret["cols"] = tuple(col for col in ret["cols"] if col < ncol)
385384

shiny/render/_data_frame_utils/_styles.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Callable, List
44

55
from ...types import ListOrTuple
6-
from ._tbl_data import frame_column_names, frame_shape
6+
from ._tbl_data import as_data_frame
77
from ._types import BrowserStyleInfo, IntoDataFrameT, StyleInfo
88

99
StyleFn = Callable[[IntoDataFrameT], List["StyleInfo"]]
@@ -183,7 +183,6 @@ def as_browser_style_infos(
183183
*,
184184
into_data: IntoDataFrameT,
185185
) -> list[BrowserStyleInfo]:
186-
browser_column_names = frame_column_names(into_data)
187186

188187
if callable(infos):
189188
style_infos = infos(into_data)
@@ -195,7 +194,10 @@ def as_browser_style_infos(
195194

196195
if not isinstance(style_infos, list):
197196
style_infos = [style_infos]
198-
nrow = frame_shape(into_data)[0]
197+
198+
nw_data = as_data_frame(into_data)
199+
browser_column_names = nw_data.columns
200+
nrow = nw_data.shape[0]
199201

200202
browser_infos = [
201203
style_info_to_browser_style_info(

shiny/render/_data_frame_utils/_tbl_data.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

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

55
import narwhals.stable.v1 as nw
66
import orjson
@@ -30,10 +30,6 @@
3030
"serialize_dtype",
3131
"serialize_frame",
3232
"subset_frame",
33-
"get_frame_cell",
34-
"frame_shape",
35-
"copy_frame",
36-
"frame_column_names",
3733
)
3834

3935
########################################################################################
@@ -289,6 +285,7 @@ def subset_frame(
289285
# int, or even a tuple of ints)
290286

291287
# The nested if-else structure is used to navigate around narwhals' typing system and lack of `:` operator outside of `[`, `]`.
288+
292289
if cols is None:
293290
if rows is None:
294291
return data
@@ -310,32 +307,6 @@ def subset_frame(
310307
return data[rows, col_names]
311308

312309

313-
# # get_frame_cell -----------------------------------------------------------------------
314-
def get_frame_cell(data: DataFrame[Any], row: int, col: int) -> Any:
315-
return data.item(row, col)
316-
317-
318-
# shape --------------------------------------------------------------------------------
319-
def frame_shape(data: IntoDataFrame) -> Tuple[int, int]:
320-
nw_data = as_data_frame(data)
321-
return nw_data.shape
322-
323-
324-
def column_is_numeric(nw_data: DataFrame[Any], column_index: int) -> bool:
325-
series_dtype: DType = nw_data[:, column_index].dtype
326-
return series_dtype.is_numeric()
327-
328-
329-
# copy_frame ---------------------------------------------------------------------------
330-
def copy_frame(nw_data: DataFrameT) -> DataFrameT:
331-
return nw_data.clone()
332-
333-
334-
# column_names -------------------------------------------------------------------------
335-
def frame_column_names(into_data: IntoDataFrame) -> List[str]:
336-
return as_data_frame(into_data).columns
337-
338-
339310
class ScatterValues(TypedDict):
340311
row_indexes: list[int]
341312
values: list[CellValue]

tests/playwright/shiny/components/data_frame/row_selection/app.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,13 @@ def selected_rows():
7474
# Test for selected rows data
7575
@render.code
7676
def grid_row_count():
77-
grid_data = grid.data()
78-
nrow, _ = ( # pyright: ignore[reportUnknownVariableType]
79-
render._data_frame_utils._tbl_data.frame_shape( # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
80-
grid_data
81-
)
82-
)
83-
return str(nrow) # pyright: ignore[reportUnknownArgumentType]
77+
nrow = grid._nw_data().shape[0]
78+
return str(nrow)
8479

8580
@render.code
8681
def selected_row_count():
87-
grid_selected_data = grid_selected.data()
88-
nrow, _ = ( # pyright: ignore[reportUnknownVariableType]
89-
render._data_frame_utils._tbl_data.frame_shape( # pyright: ignore[reportUnknownMemberType, reportAttributeAccessIssue]
90-
grid_selected_data
91-
)
92-
)
93-
return str(nrow) # pyright: ignore[reportUnknownArgumentType]
82+
nrow = grid_selected._nw_data().shape[0]
83+
return str(nrow)
9484

9585

9686
@module.ui

tests/pytest/test_render_data_frame_tbl_data.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
from shiny.render._data_frame_utils._tbl_data import (
1717
as_data_frame,
18-
copy_frame,
19-
frame_shape,
2018
serialize_dtype,
2119
serialize_frame,
2220
subset_frame,
@@ -321,16 +319,6 @@ def test_subset_frame(df_f: IntoDataFrame):
321319
assert_frame_equal2(res, dst)
322320

323321

324-
def test_get_frame_cell(df_f: IntoDataFrame):
325-
assert as_data_frame(df_f).item(1, 1) == "b"
326-
327-
328-
def test_copy_frame(df_f: IntoDataFrame):
329-
new_df = copy_frame(as_data_frame(df_f))
330-
331-
assert new_df is not df_f
332-
333-
334322
def test_subset_frame_rows_single(small_df_f: IntoDataFrame):
335323
res = subset_frame(as_data_frame(small_df_f), rows=[1])
336324

@@ -350,10 +338,6 @@ def test_subset_frame_cols_single(small_df_f: IntoDataFrame):
350338
)
351339

352340

353-
def test_shape(small_df_f: IntoDataFrame):
354-
assert frame_shape(small_df_f) == (2, 2)
355-
356-
357341
def test_dtype_coverage():
358342
from pathlib import Path
359343

0 commit comments

Comments
 (0)