From 5c495fdccc59cce210a7fc1941f240b55dddf4a3 Mon Sep 17 00:00:00 2001 From: facero Date: Thu, 25 Jun 2026 13:56:30 +0100 Subject: [PATCH 1/4] replace np.string_ (deprecated in numpy 2) --- fermipy/catalog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fermipy/catalog.py b/fermipy/catalog.py index ea88333a..4fb07165 100644 --- a/fermipy/catalog.py +++ b/fermipy/catalog.py @@ -85,7 +85,7 @@ def row_to_dict(row): o = {} for colname in row.colnames: - if isinstance(row[colname], np.string_) and row[colname].dtype.kind in ['S', 'U']: + if isinstance(row[colname], (np.bytes_, np.str_)) and row[colname].dtype.kind in ['S', 'U']: o[colname] = str(row[colname]) else: o[colname] = row[colname] From f8ccae517c0dba25ba5ea0dfeb2f9a1347721243 Mon Sep 17 00:00:00 2001 From: facero Date: Thu, 25 Jun 2026 15:52:27 +0100 Subject: [PATCH 2/4] Fix astropy >6 handling of table.join() Fill missing (masked) values in key columns before joining In astropy >v6 table.join() strictly rejects missing values in key columns while it was cool with this in astropy v5. --- fermipy/catalog.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fermipy/catalog.py b/fermipy/catalog.py index 4fb07165..a953b8af 100644 --- a/fermipy/catalog.py +++ b/fermipy/catalog.py @@ -59,6 +59,19 @@ def join_tables(left, right, key_left, key_right, if key_left not in cols_right: cols_right += [key_left] + # Fill missing (masked) values in key columns before joining (astropy >6 + # raises TableMergeError if key columns have missing values). + for tbl in [left, right]: + if key_left in tbl.colnames: + col = tbl[key_left] + if hasattr(col, 'mask') and col.mask.any(): + if col.dtype.kind in ['S', 'U']: + tbl[key_left] = col.filled('') + elif col.dtype.kind in ['i']: + tbl[key_left] = col.filled(0) + else: + tbl[key_left] = col.filled(np.nan) + out = join(left, right[cols_right], keys=key_left, join_type='left') From 2faf4e42abdac638c236356508a2afbc1fe2aa18 Mon Sep 17 00:00:00 2001 From: facero Date: Fri, 26 Jun 2026 10:16:43 +0100 Subject: [PATCH 3/4] Update srcmap_utils.py numpy2 has stricter handling of scalar conversion, where 1-element arrays are no longer implicitly converted to Python scalars. In [7]: pix[0:1].shape Out[7]: (1,) int(pix[0:1]) # will throw an error int(pix[0:1][0] # works --- fermipy/srcmap_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fermipy/srcmap_utils.py b/fermipy/srcmap_utils.py index 376444bc..6fa5b44b 100644 --- a/fermipy/srcmap_utils.py +++ b/fermipy/srcmap_utils.py @@ -76,7 +76,7 @@ def get_offsets(self, pix): idx += [0] else: npix1 = int(self.shape[i]) - pix0 = int(pix[i - 1]) - npix1 // 2 + pix0 = int(pix[i - 1][0]) - npix1 // 2 idx += [pix0] return idx @@ -90,7 +90,7 @@ def shift_to_coords(self, pix, fill_value=np.nan): for i in range(len(self.shape) - 1): x = self.rebin * (pix[i] - pix_offset[i + 1] ) + (self.rebin - 1.0) / 2. - dpix[i] = x - self._pix_ref[i] + dpix[i] = x[0] - self._pix_ref[i] pos = [pix_offset[i] + self.shape[i] // 2 for i in range(self.data.ndim)] From 40cb27b4d94183182feae0f7b2e0fe6955281a76 Mon Sep 17 00:00:00 2001 From: facero Date: Fri, 26 Jun 2026 10:59:54 +0100 Subject: [PATCH 4/4] Fix numpy2 returning np.float32 instead of float PyLike does not accept np.float32 as input, only float objects. --- fermipy/gtanalysis.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fermipy/gtanalysis.py b/fermipy/gtanalysis.py index b0265bd3..c2c7b478 100644 --- a/fermipy/gtanalysis.py +++ b/fermipy/gtanalysis.py @@ -4791,7 +4791,7 @@ def _create_source(self, src): if src['SpatialType'] == 'SkyDirFunction': pylike_src = pyLike.PointSource(self.like.logLike.observation()) - pylike_src.setDir(src.skydir.ra.deg, src.skydir.dec.deg, False, + pylike_src.setDir(float(src.skydir.ra.deg), float(src.skydir.dec.deg), False, False) elif src['SpatialType'] == 'SpatialMap': filepath = str(utils.path_to_xmlpath(src['Spatial_Filename'])) @@ -4802,20 +4802,20 @@ def _create_source(self, src): elif src['SpatialType'] == 'RadialProfile': filepath = str(utils.path_to_xmlpath(src['Spatial_Filename'])) sm = pyLike.RadialProfile(filepath) - sm.setCenter(src['ra'], src['dec']) + sm.setCenter(float(src['ra']), float(src['dec'])) pylike_src = pyLike.DiffuseSource(sm, self.like.logLike.observation(), False) elif src['SpatialType'] == 'RadialGaussian': - sm = pyLike.RadialGaussian(src.skydir.ra.deg, src.skydir.dec.deg, - src.spatial_pars['Sigma']['value']) + sm = pyLike.RadialGaussian(float(src.skydir.ra.deg), float(src.skydir.dec.deg), + float(src.spatial_pars['Sigma']['value'])) pylike_src = pyLike.DiffuseSource(sm, self.like.logLike.observation(), False) elif src['SpatialType'] == 'RadialDisk': - sm = pyLike.RadialDisk(src.skydir.ra.deg, src.skydir.dec.deg, - src.spatial_pars['Radius']['value']) + sm = pyLike.RadialDisk(float(src.skydir.ra.deg), float(src.skydir.dec.deg), + float(src.spatial_pars['Radius']['value'])) pylike_src = pyLike.DiffuseSource(sm, self.like.logLike.observation(), False)