[!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:
pydantic model has OptionsType = Union[list[StrictBool], list[float], list[str], list[date], list[OptionsDictType]] and casts options to float
_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:
change order of Union in pydantic field definition but without breaking anything else so need to be careful
something in _filter_isin that does conversions
rethink which selectors are allowed when, which I think is a bit wrong anyway because e.g. RangeSlider should be usable for ordinal data. Also understand the bool case from https://github.com/mckinsey/vizro/issues/445
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()
Which package?
vizro
Package version
0.1.26
Description
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 selectorvm.Dropdown
by default. However, filtering on it won't work.The root cause is:
OptionsType = Union[list[StrictBool], list[float], list[str], list[date], list[OptionsDictType]]
and casts options tofloat
_filter_isin
is then comparing series ofobject
s tofloat
, which doesn't return anythingThis is a problem with at least Dropdown, Checklist, RadioItems and probably affects more than just numerical types.
Possible fixes:
Union
in pydantic field definition but without breaking anything else so need to be careful_filter_isin
that does conversionsRangeSlider
should be usable for ordinal data. Also understand thebool
case from https://github.com/mckinsey/vizro/issues/445How to Reproduce
PyCafe snippet
Output
No response
Code of Conduct