Skip to content

Commit b38ea92

Browse files
authored
Merge pull request #180 from ageller/bugfix/numpy-2.0-support
add import guard to import relocated AxisError as of numpy-2.0
2 parents 512f899 + fdf8448 commit b38ea92

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ If you use Firefly, please cite our [ApJS paper](https://ui.adsabs.harvard.edu/a
1616

1717
Comprehensive documentation is available [here](https://firefly.rcs.northwestern.edu/docs).
1818

19-
*Note: currently Firefly requires numpy version<2.0. This may not be the default version of numpy installed via `pip install firefly`.*
20-
2119
## Contributors
2220
### Primary Developers
2321
* Aaron Geller

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
setuptools.setup(
77
name="firefly",
8-
version="3.3.1",
8+
version="3.3.2",
99
author = 'Alex Gurvich, Aaron Geller',
10-
author_email = 'agurvich@u.northwestern.edu, a-geller@northwestern.edu',
10+
author_email = 'alex.b.gurvich@gmail.com, a-geller@northwestern.edu',
1111
description="A browser-based particle visualization platform",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",

src/firefly/data_reader/reader.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import numpy as np
88
import time
99

10+
## numpy 1.X
11+
try: AxisError = np.AxisError
12+
## numpy 2.X
13+
except: from numpy.exceptions import AxisError
14+
1015
from .settings import Settings,default_settings
1116
from .tween import TweenParams
1217
from .particlegroup import ParticleGroup
@@ -720,11 +725,11 @@ def __init__(
720725
:type write_to_disk: bool, optional
721726
:param loud: flag to print status information to the console, defaults to False
722727
:type loud: bool, optional
723-
:raises np.AxisError: if the coordinate data cannot be interpreted
728+
:raises AxisError: if the coordinate data cannot be interpreted
724729
:raises ValueError: if the number of particle groups does not match the number of
725730
coordinate arrays
726-
:raises np.AxisError: if the field data cannot be interpreted
727-
:raises np.AxisError: if the field names cannot be interpreted
731+
:raises AxisError: if the field data cannot be interpreted
732+
:raises AxisError: if the field names cannot be interpreted
728733
"""
729734

730735
super().__init__(**kwargs)
@@ -740,14 +745,14 @@ def __init__(
740745
## passed a jagged array of different coordinates
741746
pass
742747
else:
743-
raise np.AxisError("Uninterpretable coordinate array, either pass a single (N,3) array"+
748+
raise AxisError("Uninterpretable coordinate array, either pass a single (N,3) array"+
744749
" or a jagged list of 'shape' (M,N_m,3)")
745750

746751
ngroups = len(coordinates)
747752
npartss = np.array([len(coords) for coords in coordinates])
748753

749754
## check fields and wrap a single field for a single particle group
750-
fielderror = np.AxisError("Uninterpretable field array, either pass a single N array"
755+
fielderror = AxisError("Uninterpretable field array, either pass a single N array"
751756
" or a jagged list of 'shape' (M,N_fm,N_pm)")
752757
if fields is not None:
753758
## special case and want to allow convenient/inconsistent syntax,
@@ -784,7 +789,7 @@ def __init__(
784789
nfieldss = [len(this_fields) for this_fields in fields]
785790

786791
## check field names and generate them if necessary
787-
fieldnameerror = np.AxisError("Uninterpretable field array, either pass a single N array"+
792+
fieldnameerror = AxisError("Uninterpretable field array, either pass a single N array"+
788793
" or a jagged list of 'shape' (M,N_fm,N_pm)")
789794

790795
if field_names is not None:
@@ -1006,7 +1011,7 @@ def __getHDF5Coordinates(
10061011
:param coordinates: existing coordinate array that should be appended to, defaults to None
10071012
:type coordinates: np.ndarray, optional
10081013
:raises TypeError: if :code:`coordinates` is not of type :code:`np.ndarray`
1009-
:raises np.AxisError: if :code:`coordinates` does not have shape (N,3)
1014+
:raises AxisError: if :code:`coordinates` does not have shape (N,3)
10101015
:return: coordinates, the opened coordinate array from :code:`fname`
10111016
:rtype: np.ndarray
10121017
"""
@@ -1018,7 +1023,7 @@ def __getHDF5Coordinates(
10181023
elif type(coordinates)!= np.ndarray:
10191024
raise TypeError("Existing coordinate array must be of type np.ndarry")
10201025
if np.shape(coordinates)[-1] != 3:
1021-
raise np.AxisError("Last axis of existing coordinate array must be of size 3")
1026+
raise AxisError("Last axis of existing coordinate array must be of size 3")
10221027

10231028
## open the hdf5 group
10241029
if particle_group is not None:

src/firefly/data_reader/tween.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import numpy as np
44

5+
## numpy 1.X
6+
try: AxisError = np.AxisError
7+
## numpy 2.X
8+
except: from numpy.exceptions import AxisError
9+
510
import os
611

712
from .json_utils import write_to_json
@@ -73,16 +78,16 @@ def addKeyframe(
7378
* [d1,d2,...] multiple durations (corresponding to number of keyframes or
7479
raises an error)
7580
:type duration: float/list of float
76-
:raises np.AxisError: if len of coords is not divisible by 3
77-
:raises np.AxisError: if len of durations does not match len of coords
81+
:raises AxisError: if len of coords is not divisible by 3
82+
:raises AxisError: if len of durations does not match len of coords
7883
"""
7984

8085
try:
8186
## cast to numpy array and reorder coords at the same time for
8287
## convenient input
8388
coords = np.array(coords).reshape(-1,3)
8489
except:
85-
raise np.AxisError("coords should either be a 2d Nx3 numpy array or"+
90+
raise AxisError("coords should either be a 2d Nx3 numpy array or"+
8691
"a 3N list/array.")
8792

8893
## convert duration to a 1d numpy array, however it was passed
@@ -92,7 +97,7 @@ def addKeyframe(
9297
## ensure there is a duration per keyframe transition
9398
## TODO: shouldn't durations be 1 less than coordss?
9499
if duration.shape[0]!=coords.shape[0]:
95-
raise np.AxisError(
100+
raise AxisError(
96101
"Mismatching coords and duration shape (%d,%d)"%(
97102
coords.shape[0],
98103
duration.shape[0]))

0 commit comments

Comments
 (0)