holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.74k stars 516 forks source link

Tabulator logs 'A value is trying to be set on a copy of a slice from a DataFrame.' #5847

Closed MarcSkovMadsen closed 2 months ago

MarcSkovMadsen commented 11 months ago

I'm on Panel 1.3.1 using Tabulator with pagination='remote' and header_filters. When filtering I get

/home/jovyan/repos/.../.venv/lib/python3.10/site-packages/panel/widgets/tables.py:353: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df['_index_'] = np.arange(len(df)).astype(str)
/home/jovyan/repos/mt-uk-ippa/.venv/lib/python3.10/site-packages/panel/widgets/tables.py:382: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df.drop(columns=['_index_'], inplace=True)

The issue is below

image

vaniisgh commented 10 months ago

hey :) I would like to work on this

philippjfr commented 10 months ago

I'll try to create a reproducer.

philippjfr commented 10 months ago

I cannot reproduce this issue using pandas 2.1.1 and panel 1.3.4:

import pandas as pd
import panel as pn

pn.extension('tabulator')

df = pd._testing.makeMixedDataFrame()

pn.widgets.Tabulator(df, pagination='remote', header_filters=True, page_size=2)
philippjfr commented 2 months ago

I think this has now been fixed, either earlier or with https://github.com/holoviz/panel/pull/6889