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

ci: relax numpy<=2.0.0 constraint #3504

Merged
merged 3 commits into from
Jul 25, 2024
Merged

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Jul 25, 2024

Follow-up: #3438

Most of the numpy usage is within the test examples, which is not run through ruff.

Applying all of NPY only required one fix, so AFAIK altair is compatible with NumPy 2.0.


Moving out of draft after checking for issues in r"tests/examples_.+_syntax/*.py"

Edit: See #3504 (comment)

@dangotbanned
Copy link
Member Author

dangotbanned commented Jul 25, 2024

Didn't find any NPY201, only NPY002 which could be fixed but aren't required.

The same changes would need to be made for "examples_arguments_syntax" equivalent files.

diff --git a/tests/examples_methods_syntax/layered_histogram.py b/tests/examples_methods_syntax/layered_histogram.py
index 62c7dccf..ed418b05 100644
--- a/tests/examples_methods_syntax/layered_histogram.py
+++ b/tests/examples_methods_syntax/layered_histogram.py
@@ -7,13 +7,13 @@ This example shows how to use opacity to make a layered histogram in Altair.
 import pandas as pd
 import altair as alt
 import numpy as np
-np.random.seed(42)
+np.random.seed(42)  # noqa: NPY002
 
 # Generating Data
 source = pd.DataFrame({
-    'Trial A': np.random.normal(0, 0.8, 1000),
-    'Trial B': np.random.normal(-2, 1, 1000),
-    'Trial C': np.random.normal(3, 2, 1000)
+    'Trial A': np.random.normal(0, 0.8, 1000),  # noqa: NPY002
+    'Trial B': np.random.normal(-2, 1, 1000),  # noqa: NPY002
+    'Trial C': np.random.normal(3, 2, 1000)  # noqa: NPY002
 })
 
 alt.Chart(source).transform_fold(
diff --git a/tests/examples_methods_syntax/multiline_tooltip.py b/tests/examples_methods_syntax/multiline_tooltip.py
index 12ac92bf..1801d370 100644
--- a/tests/examples_methods_syntax/multiline_tooltip.py
+++ b/tests/examples_methods_syntax/multiline_tooltip.py
@@ -14,10 +14,10 @@ import altair as alt
 import pandas as pd
 import numpy as np
 
-np.random.seed(42)
+np.random.seed(42)  # noqa: NPY002
 columns = ["A", "B", "C"]
 source = pd.DataFrame(
-    np.cumsum(np.random.randn(100, 3), 0).round(2),
+    np.cumsum(np.random.randn(100, 3), 0).round(2),  # noqa: NPY002
     columns=columns, index=pd.RangeIndex(100, name="x")
 )
 source = source.reset_index().melt("x", var_name="category", value_name="y")
diff --git a/tests/examples_methods_syntax/multiline_tooltip_standard.py b/tests/examples_methods_syntax/multiline_tooltip_standard.py
index 990aa201..f908ee0a 100644
--- a/tests/examples_methods_syntax/multiline_tooltip_standard.py
+++ b/tests/examples_methods_syntax/multiline_tooltip_standard.py
@@ -10,10 +10,10 @@ import altair as alt
 import pandas as pd
 import numpy as np
 
-np.random.seed(42)
+np.random.seed(42)  # noqa: NPY002
 columns = ["A", "B", "C"]
 source = pd.DataFrame(
-    np.cumsum(np.random.randn(100, 3), 0).round(2),
+    np.cumsum(np.random.randn(100, 3), 0).round(2),  # noqa: NPY002
     columns=columns, index=pd.RangeIndex(100, name="x"),
 )
 source = source.reset_index().melt("x", var_name="category", value_name="y")
diff --git a/tests/examples_methods_syntax/scatter_with_layered_histogram.py b/tests/examples_methods_syntax/scatter_with_layered_histogram.py
index 2cec7590..0c25fd02 100644
--- a/tests/examples_methods_syntax/scatter_with_layered_histogram.py
+++ b/tests/examples_methods_syntax/scatter_with_layered_histogram.py
@@ -16,13 +16,13 @@ import numpy as np
 source = pd.DataFrame({
     'gender': ['M']*1000 + ['F']*1000,
     'height':np.concatenate((
-        np.random.normal(69, 7, 1000), np.random.normal(64, 6, 1000)
+        np.random.normal(69, 7, 1000), np.random.normal(64, 6, 1000)  # noqa: NPY002
     )),
     'weight': np.concatenate((
-        np.random.normal(195.8, 144, 1000), np.random.normal(167, 100, 1000)
+        np.random.normal(195.8, 144, 1000), np.random.normal(167, 100, 1000)  # noqa: NPY002
     )),
     'age': np.concatenate((
-        np.random.normal(45, 8, 1000), np.random.normal(51, 6, 1000)
+        np.random.normal(45, 8, 1000), np.random.normal(51, 6, 1000)  # noqa: NPY002
         ))
     })
 
diff --git a/tests/examples_methods_syntax/select_detail.py b/tests/examples_methods_syntax/select_detail.py
index 58bdb9df..0fe447fe 100644
--- a/tests/examples_methods_syntax/select_detail.py
+++ b/tests/examples_methods_syntax/select_detail.py
@@ -15,7 +15,7 @@ import altair as alt
 import pandas as pd
 import numpy as np
 
-np.random.seed(0)
+np.random.seed(0)  # noqa: NPY002
 
 n_objects = 20
 n_times = 50
@@ -23,12 +23,12 @@ n_times = 50
 # Create one (x, y) pair of metadata per object
 locations = pd.DataFrame({
     'id': range(n_objects),
-    'x': np.random.randn(n_objects),
-    'y': np.random.randn(n_objects)
+    'x': np.random.randn(n_objects),  # noqa: NPY002
+    'y': np.random.randn(n_objects)  # noqa: NPY002
 })
 
 # Create a 50-element time-series for each object
-timeseries = pd.DataFrame(np.random.randn(n_times, n_objects).cumsum(0),
+timeseries = pd.DataFrame(np.random.randn(n_times, n_objects).cumsum(0),  # noqa: NPY002
                           columns=locations['id'],
                           index=pd.RangeIndex(0, n_times, name='time'))
 
diff --git a/tests/examples_methods_syntax/simple_scatter_with_errorbars.py b/tests/examples_methods_syntax/simple_scatter_with_errorbars.py
index 434e6adc..bcf8c28b 100644
--- a/tests/examples_methods_syntax/simple_scatter_with_errorbars.py
+++ b/tests/examples_methods_syntax/simple_scatter_with_errorbars.py
@@ -9,9 +9,9 @@ import pandas as pd
 import numpy as np
 
 # generate some data points with uncertainties
-np.random.seed(0)
+np.random.seed(0)  # noqa: NPY002
 x = [1, 2, 3, 4, 5]
-y = np.random.normal(10, 0.5, size=len(x))
+y = np.random.normal(10, 0.5, size=len(x))  # noqa: NPY002
 yerr = 0.2
 
 # set up data frame
diff --git a/tests/examples_methods_syntax/stem_and_leaf.py b/tests/examples_methods_syntax/stem_and_leaf.py
index 9436d8eb..72c940a9 100644
--- a/tests/examples_methods_syntax/stem_and_leaf.py
+++ b/tests/examples_methods_syntax/stem_and_leaf.py
@@ -7,10 +7,10 @@ This example shows how to make a stem and leaf plot.
 import altair as alt
 import pandas as pd
 import numpy as np
-np.random.seed(42)
+np.random.seed(42)  # noqa: NPY002
 
 # Generating random data
-source = pd.DataFrame({'samples': np.random.normal(50, 15, 100).astype(int).astype(str)})
+source = pd.DataFrame({'samples': np.random.normal(50, 15, 100).astype(int).astype(str)})  # noqa: NPY002
 
 # Splitting stem and leaf
 source['stem'] = source['samples'].str[:-1]

@dangotbanned dangotbanned marked this pull request as ready for review July 25, 2024 17:40
@mattijn
Copy link
Contributor

mattijn commented Jul 25, 2024

Thanks! It looks good as-is. Thanks for pushing!

@mattijn mattijn merged commit 679a7ce into vega:main Jul 25, 2024
15 checks passed
@dangotbanned dangotbanned deleted the numpy-2-support branch August 17, 2024 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants