Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerical values in selector with non-numerical column don't work #869

Open
1 task done
antonymilne opened this issue Nov 12, 2024 · 0 comments
Open
1 task done
Labels
Bug Report 🐛 Issue contains a bug report

Comments

@antonymilne
Copy link
Contributor

Which package?

vizro

Package version

0.1.26

Description

Note

Not urgent, let's wait until after pydantic v2 to fix.

If a column contains only numerical values but is object type (as can happen when you load data from a file) then it's correctly considered a categorical variable so given selector vm.Dropdown by default. However, filtering on it won't work.

The root cause is:

  1. pydantic model has OptionsType = Union[list[StrictBool], list[float], list[str], list[date], list[OptionsDictType]] and casts options to float
  2. _filter_isin is then comparing series of objects to float, which doesn't return anything

This is a problem with at least Dropdown, Checklist, RadioItems and probably affects more than just numerical types.

Possible fixes:

How to Reproduce

PyCafe snippet

import vizro.models as vm
import pandas as pd
from vizro import Vizro

from vizro.tables import dash_ag_grid

df = pd.DataFrame({"my_column": ["1", "2", "3"]})
# Uncomment this line to see the bug
# df["my_column"] = df["my_column"].astype(int)

page = vm.Page(
    title="Bug",
    components=[vm.AgGrid(figure=dash_ag_grid(data_frame=df))],
    controls=[vm.Filter(column="my_column", selector=vm.RadioItems())],
)


dashboard = vm.Dashboard(pages=[page])

Vizro().build(dashboard).run()

Output

No response

Code of Conduct

@antonymilne antonymilne added Bug Report 🐛 Issue contains a bug report Needs triage 🔍 Issue needs triaging and removed Needs triage 🔍 Issue needs triaging labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report 🐛 Issue contains a bug report
Projects
None yet
Development

No branches or pull requests

1 participant