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

Dictionary Values are Not Displayed correctly #381

Open
JohnOmernik opened this issue Dec 3, 2022 · 1 comment
Open

Dictionary Values are Not Displayed correctly #381

JohnOmernik opened this issue Dec 3, 2022 · 1 comment

Comments

@JohnOmernik
Copy link

Describe the bug
When a Dictionary object is in a column of a Data frame, or even in a list item of a dataframe, it is displayed as [object Object] instead of a more intuitive "use str repr of dictionary".

To Reproduce
Steps to reproduce the behavior:

  1. mydf = pd.DataFrame([{'dict_field':{'hi':'ya'}}, {'dict_field':{'hi':'yo'}}])
  2. Render this in ipydataframe
  3. Observe [object Object] rather than {'hi': 'ya'}
  4. ????
  5. Profit (Sorry, couldn't help myself)

Expected behavior
Like lists, (which are rendered correctly unless they contain dictionaries), ipydatagrid should use a str repr of the dictionary object.
I am not sure how that will affect performance, but if performance is a major concern, perhaps make a flag that defaults to False that can override and force that str repr to be displayed

Environment (please complete the following information):

  • Jupyter Lab running on Windows in Chrome
@tfmark
Copy link
Contributor

tfmark commented Apr 4, 2024

A workaround could be to json-ify your data

import ipydatagrid
import pandas as pd
import json

df = pd.DataFrame([{'dict_field':{'hi':'ya'}}, {'dict_field':{'hi':'yo'}}])
df["dict_field"] = df["dict_field"].apply(json.dumps)

ipydatagrid.DataGrid(
    dataframe=df,
    column_widths=dict(dict_field=100),
)

image

.. which is how I think we'll deal with the dicts in our table if we decide that our users want to see them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants