Is your feature request related to a problem? Please describe.
often when developing short-hand names are used, they don't contain spaces and are selected for ease of writing code.
when displaying results to a user the backend names are often mapped to user facing titles.
it would be great if ipydatagrid facilitated this.
in autoui we care mostly about the jsonable value so we have a records property which does the mapping back to name rather than title.
it would be good if we could unpick some of this functionality and add it to ipydatagrid
Describe alternatives you've considered
when I looked at this again i thought that it might actually be better to use renderers rather than actually changing the underlying data
i.e.
import pandas as pd
from ipydatagrid import DataGrid, TextRenderer, Expr
def map_name(cell):
map_ = {'a': 'Title A', 'b': 'Title B'}
return map_[cell.value]
df = pd.DataFrame({"a":[1,2], "b": [3,4]})
hr = TextRenderer(text_value=Expr(map_name))
gr = DataGrid(df, header_renderer=hr)
gr
I could imagine adding a map_name_title trait which automatically applies this renderer on_change... ? this is good as you don't need to change the underlying dataframe.
the issues I see with this are:
we're taking control of the header_renderer making it unavailable to the user. it would be better if it could be done independently of that?
I don't know if this can be made to work with a multi-index title ?
Additional context
I was having a poke around thinking about where this could be best added to ipydatagrid...
pandas defines the schema like this:
https://specs.frictionlessdata.io/table-schema/
which explicitly supports a title (and description which would be great as a column heading tooltip!)
but unfortunately i don't think there is a way of add these metadata fields to a pandas dataframe object.
I think it would be good if the schema was also a trait - if not given it is defined by the dataframe, otherwise it can be used to add additional metadata about the dataframe... with some logic to ensure the 2 things are consistent
Is your feature request related to a problem? Please describe. often when developing short-hand names are used, they don't contain spaces and are selected for ease of writing code. when displaying results to a user the backend names are often mapped to user facing titles. it would be great if
ipydatagrid
facilitated this.Describe the solution you'd like in
ipyautoui
we implemented something that does this - ipyautoui requires a schema which gives the user the opportunity to define a title. we overrideDataGrid
withAutoGrid
and in the__init__
we check if titles are present and update the dataframe before setting https://github.com/maxfordham/ipyautoui/blob/782955ed379cd2b4f53b0ec0de74557813c2e80e/src/ipyautoui/custom/autogrid.py#L667-L696 something like this: https://github.com/maxfordham/ipyautoui/blob/782955ed379cd2b4f53b0ec0de74557813c2e80e/src/ipyautoui/custom/autogrid.py#L432-L438in autoui we care mostly about the jsonable value so we have a
records
property which does the mapping back to name rather than title.it would be good if we could unpick some of this functionality and add it to
ipydatagrid
Describe alternatives you've considered when I looked at this again i thought that it might actually be better to use renderers rather than actually changing the underlying data
i.e.
I could imagine adding a
map_name_title
trait which automatically applies this renderer on_change... ? this is good as you don't need to change the underlying dataframe. the issues I see with this are:header_renderer
making it unavailable to the user. it would be better if it could be done independently of that?Additional context I was having a poke around thinking about where this could be best added to
ipydatagrid
... pandas defines the schema like this: https://specs.frictionlessdata.io/table-schema/ which explicitly supports atitle
(anddescription
which would be great as a column heading tooltip!) but unfortunately i don't think there is a way of add these metadata fields to a pandas dataframe object.the main issue that i see is that the setting of the dataframe is the only required field. setting the dataframe happens first (before other traits are set) : https://github.com/bloomberg/ipydatagrid/blob/c7cf3a48756264db92218ac40a0d5417a078dc9a/ipydatagrid/datagrid.py#L372-L380 this then creates the schema: https://github.com/bloomberg/ipydatagrid/blob/c7cf3a48756264db92218ac40a0d5417a078dc9a/ipydatagrid/datagrid.py#L441-L467
I think it would be good if the schema was also a
trait
- if not given it is defined by the dataframe, otherwise it can be used to add additional metadata about the dataframe... with some logic to ensure the 2 things are consistent