-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add truncate_headers
parameter to Dataframe
to improve header text control
#11941
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
base: main
Are you sure you want to change the base?
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/58e7726f1882516b6f18cccfa06889cc3455d48d/gradio-5.48.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@58e7726f1882516b6f18cccfa06889cc3455d48d#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/58e7726f1882516b6f18cccfa06889cc3455d48d/gradio-client-1.19.1.tgz |
🦄 change detectedThis Pull Request includes changes to the following packages.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @hannahblair ! What if this parameter can also take a list of column names to give developers even more control as opposed to all headers are truncated or none are?
show_search: Literal["none", "search", "filter"] = "none", | ||
pinned_columns: int | None = None, | ||
static_columns: list[int] | None = None, | ||
truncate_headers: bool = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add to docstring
Thanks @hannahblair! This helps for sure, see previous (top) vs. current (bottom): ![]() ![]() But it doesn't completely solve the issue, because cell values are still being truncated, see the first column. This leads to ambiguity since all of the values appear to be the same, and there's no way to see the full value in each cell. I guess my question is why is this truncating happening at all? If we don't specify column widths, I thought the behavior is that the columns should take up as much width as they need to fit the content, especially given that the dataframe already has horizontal scrolling, so there's no need for columns to truncate the inner values to fit some arbitrary width. Code to repro: import gradio as gr
import pandas as pd
data = {
"Name": ["test-run-v1", "test-run-v2", "test-run-v3"],
"Username": ["abidlabs_user1", "abidlabs_user2", "abidlabs_user3"],
"Created": ["about 30 minutes ago", "about 30 minutes ago", "about 30 minutes ago"],
"epoch": [20, 20, 20],
"learning_rate": [0.001, 0.001, 0.001],
"batch_size": [32, 32, 32],
"max_position_embeddings": [32768, 32768, 32768],
"hidden_size": [896, 896, 896],
"intermediate_size": [4864, 4864, 4864],
"optimizer": ["adam with warmup schedule", "adam with warmup schedule", "adam with warmup schedule"],
"dataset": ["custom-text-dataset-v1", "custom-text-dataset-v1", "custom-text-dataset-v1"],
"status": ["running (ETA ~2h)", "completed successfully", "failed at step 1200"],
}
df = pd.DataFrame(data)
def show_table():
return df
with gr.Blocks() as demo:
gr.Markdown("## Experiment Runs Overview")
gr.Dataframe(
value=show_table(),
interactive=False,
label="Training Configurations and Status",
truncate_headers=False
)
demo.launch() |
truncate_headers
param to improve header text control truncate_headers
parameter to Dataframe
to improve header text control
Description
Adds a
truncate_headers
param to allow for better control over how the headers behave. Set to default to True for backwards compatibility.Closes: #11929
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Testing and Formatting Your Code
PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests:
bash scripts/run_backend_tests.sh
Please run these bash scripts to automatically format your code:
bash scripts/format_backend.sh
, and (if you made any changes to non-Python files)bash scripts/format_frontend.sh