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

Add support for numpy 2 #1114

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def mean_occupation(self, **kwargs):
"you must pass both ``prim_haloprop`` and ``sfr_designation`` keyword arguments"
)
raise HalotoolsError(msg)
if type(sfr_designation[0]) in (str, unicode, np.string_, np.unicode_):
if type(sfr_designation[0]) in (str, unicode, np.bytes_, np.str_):
if sfr_designation[0] not in ["active", "quiescent"]:
msg = (
"The only acceptable values of "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def pairwise_distance_3d_engine(double_mesh, x1in, y1in, z1in, x2in, y2in, z2in,
cdef cnp.float64_t[:] y2 = np.ascontiguousarray(y2in[double_mesh.mesh2.idx_sorted], dtype=np.float64)
cdef cnp.float64_t[:] z2 = np.ascontiguousarray(z2in[double_mesh.mesh2.idx_sorted], dtype=np.float64)

cdef vector[cnp.int_t] i_ind
cdef vector[cnp.int_t] j_ind
cdef vector[cnp.int64_t] i_ind
cdef vector[cnp.int64_t] j_ind
cdef vector[cnp.float64_t] distances

cdef cnp.int64_t icell1, icell2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def pairwise_distance_xy_z_engine(double_mesh, x1in, y1in, z1in, x2in, y2in, z2i
cdef cnp.float64_t[:] y2 = np.ascontiguousarray(y2in[double_mesh.mesh2.idx_sorted], dtype=np.float64)
cdef cnp.float64_t[:] z2 = np.ascontiguousarray(z2in[double_mesh.mesh2.idx_sorted], dtype=np.float64)

cdef vector[cnp.int_t] i_ind
cdef vector[cnp.int_t] j_ind
cdef vector[cnp.int64_t] i_ind
cdef vector[cnp.int64_t] j_ind
cdef vector[cnp.float64_t] rp_distances
cdef vector[cnp.float64_t] pi_distances

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def pairwise_distance_no_pbc(np.ndarray[np.float64_t, ndim=1] x_icell1,
"""

#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] distances
cdef double d
cdef np.int_t i, j, n
cdef np.int64_t i, j, n
cdef int Ni = len(x_icell1)
cdef int Nj = len(x_icell2)

Expand Down Expand Up @@ -195,8 +195,8 @@ def pairwise_distance_pbc(np.ndarray[np.float64_t, ndim=1] x_icell1,
"""

#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] distances
cdef double d
cdef int i, j, n
Expand Down Expand Up @@ -307,8 +307,8 @@ def pairwise_xy_z_distance_no_pbc(


#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] para_distances
cdef vector[np.float64_t] perp_distances
cdef double d_perp, d_para
Expand Down Expand Up @@ -429,8 +429,8 @@ def pairwise_xy_z_distance_pbc(
"""

#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] para_distances
cdef vector[np.float64_t] perp_distances
cdef double d_perp, d_para
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def conditional_pairwise_distance_no_pbc(np.ndarray[np.float64_t, ndim=1] x_icel
np.float64_t max_r,
np.ndarray[np.float64_t, ndim=2] w_icell1,
np.ndarray[np.float64_t, ndim=2] w_icell2,
np.int_t cond_func_id):
np.int64_t cond_func_id):

"""
Calculate the conditional limited pairwise distance matrix, :math:`d_{ij}`.
Expand Down Expand Up @@ -101,11 +101,11 @@ def conditional_pairwise_distance_no_pbc(np.ndarray[np.float64_t, ndim=1] x_icel
"""

#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] distances
cdef double d
cdef np.int_t i, j, n
cdef np.int64_t i, j, n
cdef int Ni = len(x_icell1)
cdef int Nj = len(x_icell2)

Expand Down Expand Up @@ -149,7 +149,7 @@ def conditional_pairwise_xy_z_distance_no_pbc(np.ndarray[np.float64_t, ndim=1] x
np.float64_t max_rp, np.float64_t max_pi,
np.ndarray[np.float64_t, ndim=2] w_icell1,
np.ndarray[np.float64_t, ndim=2] w_icell2,
np.int_t cond_func_id):
np.int64_t cond_func_id):
"""
Calculate the conditional limited pairwise distance matrices, :math:`d_{{\perp}ij}` and :math:`d_{{\parallel}ij}`.

Expand Down Expand Up @@ -228,8 +228,8 @@ def conditional_pairwise_xy_z_distance_no_pbc(np.ndarray[np.float64_t, ndim=1] x


#c definitions
cdef vector[np.int_t] i_ind
cdef vector[np.int_t] j_ind
cdef vector[np.int64_t] i_ind
cdef vector[np.int64_t] j_ind
cdef vector[np.float64_t] para_distances
cdef vector[np.float64_t] perp_distances
cdef double d_perp, d_para
Expand Down
8 changes: 4 additions & 4 deletions halotools/sim_manager/cached_halo_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ def _retrieve_matching_ptcl_cache_log_entry(self):
else:
msg += "redshift = ``" + str(self.redshift) + "``\n"

msg += ("\nThere is no matching catalog in cache "
"within dz_tol = "+str(self._dz_tol)+" of these inputs.\n"
)

if len(matching_entries) == 0:
msg += (
"\nThere is no matching catalog in cache "
"within dz_tol = " + str(self._dz_tol) + " of these inputs.\n"
)
suggestion_preamble = ("\nThe following entries in the cache log "
"most closely match your inputs:\n\n")
alt_list1 = list(gen1) # discard the redshift requirement
Expand Down
16 changes: 8 additions & 8 deletions halotools/sim_manager/rockstar_hlist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,22 @@ def _write_metadata(self):

# Now add the metadata
f = h5py.File(self.output_fname, 'a')
f.attrs.create('simname', np.string_(self.simname))
f.attrs.create('halo_finder', np.string_(self.halo_finder))
redshift_string = np.string_(get_redshift_string(self.redshift))
f.attrs.create('simname', np.bytes_(self.simname))
f.attrs.create('halo_finder', np.bytes_(self.halo_finder))
redshift_string = np.bytes_(get_redshift_string(self.redshift))
f.attrs.create('redshift', redshift_string)
f.attrs.create('version_name', np.string_(self.version_name))
f.attrs.create('fname', np.string_(self.output_fname))
f.attrs.create('version_name', np.bytes_(self.version_name))
f.attrs.create('fname', np.bytes_(self.output_fname))

f.attrs.create('Lbox', self.Lbox)
f.attrs.create('particle_mass', self.particle_mass)
f.attrs.create('orig_ascii_fname', np.string_(self.input_fname))
f.attrs.create('orig_ascii_fname', np.bytes_(self.input_fname))

time_right_now = np.string_(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
time_right_now = np.bytes_(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
f.attrs.create('time_of_catalog_production', time_right_now)

if self.processing_notes is not None:
f.attrs.create('processing_notes', np.string_(self.processing_notes))
f.attrs.create('processing_notes', np.bytes_(self.processing_notes))

# Store all the choices for row cuts as metadata
for haloprop_key, cut_value in self.row_cut_min_dict.items():
Expand Down
16 changes: 8 additions & 8 deletions halotools/sim_manager/user_supplied_halo_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,24 +415,24 @@ def add_halocat_to_cache(self,

redshift_string = get_redshift_string(self.redshift)

f.attrs.create('simname', np.string_(simname))
f.attrs.create('halo_finder', np.string_(halo_finder))
f.attrs.create('version_name', np.string_(version_name))
f.attrs.create('redshift', np.string_(redshift_string))
f.attrs.create('fname', np.string_(fname))
f.attrs.create('simname', np.bytes_(simname))
f.attrs.create('halo_finder', np.bytes_(halo_finder))
f.attrs.create('version_name', np.bytes_(version_name))
f.attrs.create('redshift', np.bytes_(redshift_string))
f.attrs.create('fname', np.bytes_(fname))

f.attrs.create('Lbox', self.Lbox)
f.attrs.create('particle_mass', self.particle_mass)

time_right_now = datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S')

f.attrs.create('time_catalog_was_originally_cached', np.string_(time_right_now))
f.attrs.create('time_catalog_was_originally_cached', np.bytes_(time_right_now))

f.attrs.create('processing_notes', np.string_(processing_notes))
f.attrs.create('processing_notes', np.bytes_(processing_notes))

for key, value in additional_metadata.items():
f.attrs.create(key, np.string_(value))
f.attrs.create(key, np.bytes_(value))

f.close()
############################################################
Expand Down
12 changes: 6 additions & 6 deletions halotools/sim_manager/user_supplied_ptcl_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,19 @@ def add_ptclcat_to_cache(self, fname, simname, version_name,

redshift_string = get_redshift_string(self.redshift)

f.attrs.create('simname', np.string_(simname))
f.attrs.create('version_name', np.string_(version_name))
f.attrs.create('redshift', np.string_(redshift_string))
f.attrs.create('fname', np.string_(fname))
f.attrs.create('simname', np.bytes_(simname))
f.attrs.create('version_name', np.bytes_(version_name))
f.attrs.create('redshift', np.bytes_(redshift_string))
f.attrs.create('fname', np.bytes_(fname))

f.attrs.create('Lbox', self.Lbox)
f.attrs.create('particle_mass', self.particle_mass)

time_right_now = datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S')
f.attrs.create('time_catalog_was_originally_cached', np.string_(time_right_now))
f.attrs.create('time_catalog_was_originally_cached', np.bytes_(time_right_now))

f.attrs.create('processing_notes', np.string_(processing_notes))
f.attrs.create('processing_notes', np.bytes_(processing_notes))

f.close()

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ markers = ["slow", "installation_test"]
requires = ["setuptools>=42.0.0",
"setuptools_scm",
"wheel",
"oldest-supported-numpy",
Copy link
Contributor

Choose a reason for hiding this comment

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

@bsipocz this PR led by @AlanPearl establishes compatibility between halotools and numpy 2.0. However, I'm not sure about this particular line of code because I never really understood what using oldest-supported-numpy did. But this PR fails unless this line is changed to numpy>=2.0.

On a possibly related note, I'm also not sure whether any additional changes need to be made in order to properly use extension-helpers in the right way.

"cython==3.0.2",
"numpy>=2.0",
"cython>=3.0.2",
"extension-helpers==1.*"]
build-backend = 'setuptools.build_meta'

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
astropy
numpy<2
numpy
scipy
requests
beautifulsoup4
Expand Down
Loading