datajoint / datajoint-python

Relational data pipelines for the science lab
https://datajoint.com/docs
GNU Lesser General Public License v2.1
169 stars 84 forks source link

Jupyterlab shows tables in black on black #1167

Open horsto opened 2 months ago

horsto commented 2 months ago

In Jupyterlab table previews are suddenly unreadable in dark and dark-high-contrast themes. I am not sure what happened here, but I seem not to be able to revert it to showing the font in white. This might be a jupyter lab issue and not a datajoint issue.

OS: Mac OS Jupyter lab: Version 4.2.4 Datajoint python: Version 0.14.1

Screenshot 2024-08-14 at 11 38 45
CBroz1 commented 2 months ago

The html table style is defined here, hardcoded for light themes. Not ideal, but running an editable install would allow you to adjust these values

dimitri-yatsenko commented 2 months ago

@CBroz1 what would you suggest for a better solution?

CBroz1 commented 2 months ago

I can see a few possible paths...

  1. Determine theme and adjust html accordingly. Discussion
    • Pros: maintains status quo for light-mode users
    • Cons: maintenance burden of front-end variance
  2. Defer rendering to pandas html, which already adjusts for theme.
    • Pros: offloads maintenance to another package, no additional dependencies
    • Cons:
    • mismatch across versions
    • may require deprecation timeline for html in case someone uses this for other tools
    • minor edits to show primary keys and table header
  3. Add a config option that determines the html displayed
    • Pros: maintains status quo, no interface changes, minimal work
    • Cons: Additional config line item
Example Pandas adjustment for primary keys ```python import pandas as pd from IPython.display import display data = { 'id': [1, 2, 3], 'name': ['Alice', 'Bob', 'Charlie'], 'age': [24, 27, 22], 'email': ['alice@example.com', 'bob@example.com', 'charlie@example.com'] } df = pd.DataFrame(data) primary_key_cols = ['id', 'name'] def style_primary_keys(df, primary_key_cols): styled_cols = {col: f"*{col}" if col in primary_key_cols else col for col in df.columns} df = df.rename(columns=styled_cols) return df styled_df = style_primary_keys(df, primary_key_cols) display(styled_df.style) ```

I don't think 1 is worth the additional maintenance burden. 2 may be the most long-term solution, but 3 is an easier short-term solution. I lean toward 2.