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

Migrate formatting_html.py into xarray core #8930

Merged
merged 14 commits into from
Apr 18, 2024

Conversation

eni-awowale
Copy link
Collaborator

This PR migrates the formatting_html.py module into xarray/core/formatting_html.py as part of the on-going effort to merge xarray-datatree into xarray.

One thing of note is that importing and setting the OPTIONS to "default" in datatree/formatting_html.py (lines) were moved into xarray/core/options.py on #L23 and #L49. So, I did not add them back to xarray/core/formatting_html.py.

  • Completes migration step for datatree/formating_htmls.py Track merging datatree into xarray #8572
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

Copy link

welcome bot commented Apr 11, 2024

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@eni-awowale
Copy link
Collaborator Author

Bringing @TomNicholas comment here!

Thankyou for working on this @eni-awowale ! The main question I have before diving deeper is whether or not you have any time to look into the annoying bug which squeezes the width of the html output - see xarray-contrib/datatree#91

Yeah, I can take a look at this.

@eni-awowale
Copy link
Collaborator Author

@TomNicholas I think I found the fix! I responded in the thread xarray-contrib/datatree#91 and updated in my latest commit. I am a little concerned that the min-width and max-width are the same?

@@ -28,7 +28,7 @@ body.vscode-dark {

.xr-wrap {
display: block !important;
min-width: 300px;
min-width: 700px;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the min-width to be 700px seems to solve this bug, however, now it is the same as the max-width. I am not sure if this is okay but thought I would point it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Are there other similar values to compare to in that file? Should we just have min-width=700px and max-width even bigger, or is the bug from them being different values somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when i set max-width to 900px it doesn't make a difference for the grouped dataset (ompixcor) but it does increase the width for the non-grouped dataset (tree_hoss). I think it is something to do with the margin lines that represent the group hierarchies.

Here is an example:
Screenshot 2024-04-11 at 3 57 36 PM

Let me know what you think and I can update the max-width accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what I'm looking at with the css here... Pinging @benbovy and @jsignell as the original authors of the HTML repr 😁 Can either of you tell us how you would handle this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That width controls what the repr looks like when the area that it has available is small. It basically says the width of the repr cannot be less than 700px. This mostly comes up in jupyterlab when you have a split view. Here's the difference:

main:

image

this PR:

Screenshot from 2024-04-12 09-17-25

see how the repr goes off screen? There is a horizontal scroll, so you can still get to the far right of the repr, but it's just a little less beautiful.

It seems like this change is related to xarray-contrib/datatree#91. Is there a reproducible example that I can mess around with?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and I broke some tests. Will fix those now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: fdf53f

It looks resolved to me, but want to check sure if @eni-awowale is okay with things as she saw different behaviour.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check this out as soon as I can!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried it out and it's fixed! I will update this to not be a draft

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomNicholas - I think we're good to go.

xarray/core/formatting_html.py Outdated Show resolved Hide resolved
@@ -341,3 +343,130 @@ def dataset_repr(ds) -> str:
]

return _obj_repr(ds, header_components, sections)


def summarize_datatree_children(children: Mapping[str, Any]) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this Any really a DataTree? (Not 100% sure, but it seems like a good guess)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing up the type hints!

xarray/core/formatting_html.py Outdated Show resolved Hide resolved
@eni-awowale
Copy link
Collaborator Author

@owenlittlejohns I noticed I am getting some circular import errors from importing DataTree in formatting_html.py, so I can use it in place of Any.

@TomNicholas
Copy link
Member

circular import errors from importing DataTree

Shouldn't that be solvable with if TYPE_CHECKING and using "DataTree" as the type? Because it's only a type hint, you don't need it at runtime.

@eni-awowale
Copy link
Collaborator Author

circular import errors from importing DataTree

Shouldn't that be solvable with if TYPE_CHECKING and using "DataTree" as the type? Because it's only a type hint, you don't need it at runtime.

Ahh yes that solves it! Thanks!

@eni-awowale eni-awowale marked this pull request as ready for review April 17, 2024 22:33
@eni-awowale eni-awowale requested a review from TomNicholas April 17, 2024 22:34
Copy link
Member

@flamingbear flamingbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these changes, and I saw the CSS update worked. Nice. Approving even though that doesn't help you.

Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving even though that doesn't help you.

Explicitly approving it helps me!

Thank you everyone!

@TomNicholas TomNicholas merged commit 5f24079 into pydata:main Apr 18, 2024
31 checks passed
Copy link

welcome bot commented Apr 18, 2024

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

@flamingbear flamingbear deleted the DAS-2066-migrate-formatting-html branch May 21, 2024 16:29
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

Successfully merging this pull request may close these issues.

5 participants