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

Fix logic for no geoviews explorer #1451

Merged
merged 10 commits into from
Dec 13, 2024
Merged

Fix logic for no geoviews explorer #1451

merged 10 commits into from
Dec 13, 2024

Conversation

ahuang11
Copy link
Collaborator

Even though geo=False, explorer would raise raise ImportError('GeoViews must be installed to enable the geographic options.')

import pandas as pd
import hvplot.pandas
df = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]})

df.hvplot.explorer(geo=False)

Not sure how to add a test for this because the dev dependencies installs geoviews.

@ahuang11 ahuang11 requested a review from maximlt October 29, 2024 20:37
@hoxbro
Copy link
Member

hoxbro commented Oct 29, 2024

@ahuang11
Copy link
Collaborator Author

ooh that's fancy and good to know! Turns out there actually was a marker for geo tests so I didn't need it.

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.03%. Comparing base (9078378) to head (70e59b3).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
hvplot/util.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1451      +/-   ##
==========================================
+ Coverage   88.94%   89.03%   +0.09%     
==========================================
  Files          52       52              
  Lines        7781     7819      +38     
==========================================
+ Hits         6921     6962      +41     
+ Misses        860      857       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoxbro
Copy link
Member

hoxbro commented Oct 30, 2024

Are you sure?

@maximlt
Copy link
Member

maximlt commented Oct 30, 2024

ooh that's fancy and good to know! Turns

It's also a little crazy right 🙃

A suggestion could be to refactor gv_available into a utility function that is mocked for this test to return False.

@ahuang11
Copy link
Collaborator Author

Hm I guess there is a marker, but the tests still run everything
https://github.com/holoviz/hvplot/blob/main/.github/workflows/test.yaml#L171
https://github.com/holoviz/hvplot/blob/main/hvplot/tests/testui.py#L394

I guess I'll go with Maxime's suggestion

hvplot/util.py Outdated Show resolved Hide resolved
@ahuang11 ahuang11 force-pushed the fix_ui_without_geoviews branch from 7d8b05e to bae3bd7 Compare October 30, 2024 20:01
hvplot/util.py Outdated
gv_available = find_spec('geoviews') is not None

if not gv_available and raise_error:
raise ImportError('GeoViews must be installed to enable the geographic options.')
Copy link
Member

Choose a reason for hiding this comment

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

I got confused a minute here, does find_spec('geoviews') actually import GeoViews?

Copy link
Member

Choose a reason for hiding this comment

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

No, but it checks if it is installed.

image

Copy link
Member

Choose a reason for hiding this comment

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

Yes ok that's what I thought. I was confused as then an ImportError is raised. Since importing GeoViews comes with side effects (registering lots of stuff), I'd like to make sure we're not removing an important step there. @hoxbro did you suggest find_spec for performance reasons?

Copy link
Member

Choose a reason for hiding this comment

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

Just as an alternative and also easier to patch in the test suite.

I think it is okay to use find_spec when we check if it is available. We should import geoviews in the code, where there previously was a try/except, to get those juicy side effects.

Copy link
Member

Choose a reason for hiding this comment

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

I also think the error message is wrong here. As it no longer only affects the UI code.

hvplot/util.py Outdated Show resolved Hide resolved
@maximlt
Copy link
Member

maximlt commented Dec 12, 2024

@ahuang11 what do you think about the refactor done in 31df383? I'm fine with reverting if you prefer the former way. I've preferred creating a function that does the actual import since the side effects of importing geoviews as required I think.

@ahuang11
Copy link
Collaborator Author

I'm fine with the refactor.

@maximlt maximlt merged commit dc8b578 into main Dec 13, 2024
9 checks passed
@maximlt maximlt deleted the fix_ui_without_geoviews branch December 13, 2024 09:42
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.

3 participants