Skip to content

Commit 2b24db3

Browse files
committed
Don't bother serializing pandas index
Dropping the index saves bandwidth and prevents an error if the index has non-serializable values in it.
1 parent 1d8bb33 commit 2b24db3

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

js/dataframe/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface ShinyDataGridProps<TIndex> {
5858

5959
const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {
6060
const { id, data, bgcolor } = props;
61-
const { columns, index, type_hints, data: rowData } = data;
61+
const { columns, type_hints, data: rowData } = data;
6262
const { width, height, filters: withFilters } = data.options;
6363

6464
const containerRef = useRef<HTMLDivElement>(null);

js/dataframe/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface DataGridOptions {
2020

2121
export interface PandasData<TIndex> {
2222
columns: ReadonlyArray<string>;
23-
index: ReadonlyArray<TIndex>;
23+
// index: ReadonlyArray<TIndex>;
2424
data: unknown[][];
2525
type_hints?: ReadonlyArray<TypeHint>;
2626
options: DataGridOptions;

shiny/render/_dataframe.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ def to_payload(self) -> object:
207207

208208

209209
def serialize_pandas_df(df: "pd.DataFrame") -> dict[str, Any]:
210+
# Currently, we don't make use of the index; drop it so we don't error trying to
211+
# serialize it or something
212+
df = df.reset_index(drop=True)
213+
210214
res = json.loads(
211215
# {index: [index], columns: [columns], data: [values]}
212216
df.to_json(None, orient="split") # pyright: ignore[reportUnknownMemberType]

0 commit comments

Comments
 (0)