man-group / dtale

Visualizer for pandas data structures
http://alphatechadmin.pythonanywhere.com
GNU Lesser General Public License v2.1
4.76k stars 405 forks source link

Changing values on a filtered table (with inplace=True) does not update the underlying DataFrame #745

Open DiegoF90 opened 1 year ago

DiegoF90 commented 1 year ago

Pretty much what the issue tittle says. For example use the below (e.g. in Jupyter Notebook):

import pandas as pd
import dtale

df = pd.DataFrame({'a': ['yes', 'no', 'no', 'maybe'], 'b': ['foo', 'bar', 'spam', 'eggs']})
dtale.show(
    df,
    inplace=True
)

Then filter column 'a' by those having value 'no'. Than delete the entries of column 'b'. A pandas warning on setting a value on a copy will appear, and as suggested when printing

df

Column 'b' will still show contents.

aschonfeld commented 1 year ago

@DiegoF90 so inplace=True might be a little misleading. On initial load of a dataframe to D-Tale a call to reset_index occurs (this is to ensure the dataframe is in a normalized format with a standard "natural" index of 0...n). When you call dtale.show with inplace=True it will make that call to reset_index an inplace operation to lower memory usage. Unfortunately, this is where that flag's usage ends.

What you want to do in order to get your updated dataframe would be:

import pandas as pd
import dtale

df = pd.DataFrame({'a': ['yes', 'no', 'no', 'maybe'], 'b': ['foo', 'bar', 'spam', 'eggs']})
d = dtale.show(
    df,
    inplace=True
)

# perform edits using the app

d.data # this retrieves the current state of your dataframe (with regard to edits, not filtering)