diff --git a/CHANGES.rst b/CHANGES.rst index d5ad65983..5c692d169 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,13 @@ New Features Bug Fixes ^^^^^^^^^ +- ``photutils.segmentation`` + + - Fixed a bug where the table output from the ``SourceCatalog`` + ``to_table`` method could have column names with a ``np.str_`` + representation instead of ``str`` representation when using NumPy + 2.0+. [#1956] + API Changes ^^^^^^^^^^^ diff --git a/photutils/segmentation/catalog.py b/photutils/segmentation/catalog.py index df2e74679..439522c70 100644 --- a/photutils/segmentation/catalog.py +++ b/photutils/segmentation/catalog.py @@ -967,8 +967,10 @@ def to_table(self, columns=None): """ if columns is None: table_columns = self.default_columns + elif isinstance(columns, str): + table_columns = [columns] else: - table_columns = np.atleast_1d(columns) + table_columns = columns tbl = QTable() tbl.meta.update(self.meta) # keep tbl.meta type diff --git a/photutils/segmentation/tests/test_catalog.py b/photutils/segmentation/tests/test_catalog.py index 39b6a3cbf..eb6113e25 100644 --- a/photutils/segmentation/tests/test_catalog.py +++ b/photutils/segmentation/tests/test_catalog.py @@ -275,6 +275,16 @@ def test_table(self): assert len(tbl) == 7 assert tbl.colnames == columns + tbl = self.cat.to_table(self.cat.default_columns) + for col in tbl.columns: + assert isinstance(col, str) + assert not isinstance(col, np.str_) + + tbl = self.cat.to_table('label') + for col in tbl.columns: + assert isinstance(col, str) + assert not isinstance(col, np.str_) + def test_invalid_inputs(self): segm = SegmentationImage(np.zeros(self.data.shape, dtype=int)) match = 'segment_img must have at least one non-zero label'