Skip to content

Commit

Permalink
use findspec properly mock
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Oct 30, 2024
1 parent 681fa4f commit bae3bd7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions hvplot/tests/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,13 @@ def test_geoviews_is_available():


def test_geoviews_is_available_no_raise():
with patch('hvplot.util.geoviews_is_available', side_effect=ImportError):
with patch('hvplot.util.find_spec', return_value=None):
result = geoviews_is_available(raise_error=False)
assert result is False


def test_geoviews_is_available_with_raise():
with patch('hvplot.util.geoviews_is_available', side_effect=ImportError):
with patch('hvplot.util.find_spec', return_value=None):
with pytest.raises(
ImportError, match='GeoViews must be installed to enable the geographic options.'
):
Expand Down
4 changes: 2 additions & 2 deletions hvplot/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ def _plot(self):
if kwargs.get('geo'):
if 'crs' not in kwargs:
xmax = np.max(np.abs(self.xlim()))
self.geographic.crs = 'PlateCarree' if xmax <= 360 else 'GOOGLE_MERCATOR'
kwargs['crs'] = self.geographic.crs
# self.geographic.crs = 'PlateCarree' if xmax <= 360 else 'GOOGLE_MERCATOR'
kwargs['crs'] = 'PlateCarree' if xmax <= 360 else 'GOOGLE_MERCATOR'
for key in ['crs', 'projection']:
if key not in kwargs:
continue
Expand Down
12 changes: 3 additions & 9 deletions hvplot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Provides utilities to convert data and projections
"""

from importlib.util import find_spec
import sys

from collections.abc import Hashable
Expand Down Expand Up @@ -756,15 +757,8 @@ def geoviews_is_available(raise_error: bool = False):
"""
Check if GeoViews is available and raise an ImportError if not.
"""
try:
import geoviews # noqa

gv_available = True
except ImportError:
gv_available = False

if not raise_error:
return gv_available
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.')
return gv_available

0 comments on commit bae3bd7

Please sign in to comment.