plotly / dash-table

OBSOLETE: now part of https://github.com/plotly/dash
https://dash.plotly.com
MIT License
419 stars 74 forks source link

[BUG]: native filtering for long number strings returns wrong results #849

Open SimonBirkenheuer opened 3 years ago

SimonBirkenheuer commented 3 years ago

Description

TLDR: The native filter should match the column data type and not attempt to interpret the input as a different data type.

In my application I use a DataTable with a column containing long ids as strings. When filtering for certain ids with the native filter method of the DashTable the expected results are not found. I tracked down the bug to the issue below:

import dash
import dash_html_components as html
import dash_table
import pandas as pd

app = dash.Dash(__name__)

df = pd.DataFrame({'long_ids': ['8672633670679492129','8672633670679493000']})

demo_table = dash_table.DataTable(
    id='demo_table',
    columns=[{'name': 'long_ids', 'id': 'long_ids', 'type': 'text'}],
    data=df.to_dict('records'),
    filter_action='native',
    sort_action="native",
    )  

app.layout = html.Div([
        html.Div("Demonstration Table:"),
        demo_table
    ])

if __name__ == '__main__':
    app.run_server(debug=True, host='0.0.0.0', port=8000)

The minimalistic example above contains one dash DataTable containing a DataFrame with one column ‘long_ids’ and two string entries ‘8672633670679492129’ and ‘8672633670679493000’. The DataTable uses native filtering. Now, when I enter input into the filter the following behaviour occurs:

Filter_Input -> Table Output (which entries are shown)

8672633670679492129 -> 8672633670679493000 #Note: The expected result 8672633670679492129 is missing here! 867263367067949212 -> neither 86726336706794921 -> 8672633670679493000 8672633670679492 -> 8672633670679492129 867263367067949 -> both

‘8672633670679492129’ (with quotations marks) -> 8672633670679492129

Expected Behaviour:

The first three cases should correctly show 8672633670679492129 as the only result.

Probable cause:

8672633670679493000 ist the int64 conversion of 8672633670679492129. I suspect, that somewhere the filter input gets converted to int64 whereby the last digits are lost. However, the filter should respect the column type ‘text’ and not attempt to interpret the input as a number.

Context:

macOS Catalina Version 10.15.07

Tested in both: Firefox 83.0 Safari Version 14.0 (15610.1.28.1.9, 15610)

dash 1.17.0 dash-core-components 1.13.0 dash-html-components 1.1.1 dash-renderer 1.8.3 dash-table 4.11.0