Skip to content

Commit

Permalink
Update with Constant numpy version
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed May 18, 2024
1 parent e9b35a4 commit dda3f84
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
_PANDAS_ROWS_LARGE = 1_000_000
_PANDAS_SAMPLE_SIZE = 1_000_000

numpy_version = Version(Version(np.__version__).base_version)
NUMPY_GE_200 = numpy_version >= Version("2")

pandas_version = Version(pd.__version__)
try:
if pandas_version >= Version('1.3.0'):
Expand Down
4 changes: 2 additions & 2 deletions holoviews/tests/core/test_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""
import numpy as np
import pandas as pd
from packaging.version import Version

from holoviews.core import Dimension, Dimensioned
from holoviews.core.util import NUMPY_GE_200
from holoviews.element.comparison import ComparisonTestCase

from ..utils import LoggingComparisonTestCase
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_tuple_clone(self):
class DimensionDefaultTest(ComparisonTestCase):

def test_validate_default_against_values(self):
if Version(np.__version__) >= Version('2.0.0a0'):
if NUMPY_GE_200:
msg = r"Dimension\('A'\) default 1\.1 not found in declared values: \[np\.int64\(0\), np\.int64\(1\)\]"
else:
msg = r"Dimension\('A'\) default 1\.1 not found in declared values: \[0, 1\]"
Expand Down
5 changes: 2 additions & 3 deletions holoviews/tests/element/test_comparisondimension.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
Test cases for Dimension and Dimensioned object comparison.
"""
import numpy as np
from packaging.version import Version

from holoviews.core import Dimension, Dimensioned
from holoviews.core.util import NUMPY_GE_200
from holoviews.element.comparison import ComparisonTestCase


Expand Down Expand Up @@ -77,7 +76,7 @@ def test_dimension_comparison_values_unequal(self):
try:
self.assertEqual(self.dimension4, self.dimension8)
except AssertionError as e:
if Version(np.__version__) >= Version('2.0.0a0'):
if NUMPY_GE_200:
msg = "Dimension parameter 'values' mismatched: [] != [np.str_('a'), np.str_('b')]"
else:
msg = "Dimension parameter 'values' mismatched: [] != ['a', 'b']"
Expand Down
13 changes: 8 additions & 5 deletions holoviews/tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import holoviews as hv
from holoviews.core.spaces import DynamicMap
from holoviews.core.util import Version
from holoviews.core.util import NUMPY_GE_200, Version
from holoviews.element import Curve, Histogram, Points, Polygons, Scatter
from holoviews.element.comparison import ComparisonTestCase
from holoviews.streams import * # noqa (Test all available streams)
Expand Down Expand Up @@ -1421,6 +1421,7 @@ def test_selection_expr_stream_hist_invert_xaxis_yaxis(self):


def test_selection_expr_stream_polygon_index_cols(self):
# TODO: Should test both spatialpandas and shapely
# Create SelectionExpr on element
try: import shapely # noqa
except ImportError:
Expand All @@ -1444,10 +1445,12 @@ def test_selection_expr_stream_polygon_index_cols(self):
self.assertIsNone(expr_stream.bbox)
self.assertIsNone(expr_stream.selection_expr)

format = lambda x: list(map(np.str_, x)) if NUMPY_GE_200 else x

expr_stream.input_streams[2].event(index=[0, 1])
self.assertEqual(
repr(expr_stream.selection_expr),
repr(dim('cat').isin(['a', 'b']))
repr(dim('cat').isin(format(['a', 'b'])))
)
self.assertEqual(expr_stream.bbox, None)
self.assertEqual(len(events), 1)
Expand All @@ -1456,23 +1459,23 @@ def test_selection_expr_stream_polygon_index_cols(self):
expr_stream.input_streams[0].event(bounds=(0, 0, 4, 1))
self.assertEqual(
repr(expr_stream.selection_expr),
repr(dim('cat').isin(['a', 'b']))
repr(dim('cat').isin(format(['a', 'b'])))
)
self.assertEqual(len(events), 1)

# Ensure geometry event does trigger another update
expr_stream.input_streams[1].event(geometry=np.array([(0, 0), (4, 0), (4, 2), (0, 2)]))
self.assertEqual(
repr(expr_stream.selection_expr),
repr(dim('cat').isin(['a', 'b', 'c']))
repr(dim('cat').isin(format(['a', 'b', 'c'])))
)
self.assertEqual(len(events), 2)

# Ensure index event does trigger another update
expr_stream.input_streams[2].event(index=[1, 2])
self.assertEqual(
repr(expr_stream.selection_expr),
repr(dim('cat').isin(['b', 'c']))
repr(dim('cat').isin(format(['b', 'c'])))
)
self.assertEqual(expr_stream.bbox, None)
self.assertEqual(len(events), 3)
Expand Down
1 change: 0 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ python = "3.11.*"
[feature.py312.dependencies]
python = "3.12.*"


[feature.example.dependencies]
cftime = "*"
dask-core = "*"
Expand Down

0 comments on commit dda3f84

Please sign in to comment.