From 46b7a5731d0bcbbed161412d49b918236354431e Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Mon, 5 Aug 2024 11:28:54 -0400 Subject: [PATCH 1/2] check TBIT for slices/rows read --- fitsio/hdu/table.py | 21 +++++++++++++++++++++ fitsio/tests/test_table.py | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/fitsio/hdu/table.py b/fitsio/hdu/table.py index 3b462b1b..dc6eea87 100644 --- a/fitsio/hdu/table.py +++ b/fitsio/hdu/table.py @@ -896,6 +896,8 @@ def read_rows(self, rows, vstorage=None, dtype, offsets, isvar = self.get_rec_dtype(vstorage=vstorage) w, = np.where(isvar == True) # noqa + has_tbit = self._check_tbit() + if w.size > 0: if vstorage is None: _vstorage = self._vstorage @@ -905,6 +907,14 @@ def read_rows(self, rows, vstorage=None, return self._read_rec_with_var( colnums, rows, sortind, dtype, offsets, isvar, _vstorage, ) + elif has_tbit: + # drop down to read_columns since we can't stuff into a + # contiguous array + colnums = self._extract_colnums() + array = self.read_columns( + colnums, rows=rows, vstorage=vstorage, upper=upper, + lower=lower, trim_strings=trim_strings, + ) else: array = np.zeros(rows.size, dtype=dtype) self._FITS.read_rows_as_rec(self._ext+1, array, rows, sortind) @@ -1094,6 +1104,8 @@ def read_slice(self, firstrow, lastrow, step=1, dtype, offsets, isvar = self.get_rec_dtype(vstorage=vstorage) w, = np.where(isvar == True) # noqa + has_tbit = self._check_tbit() + if w.size > 0: if vstorage is None: _vstorage = self._vstorage @@ -1104,6 +1116,15 @@ def read_slice(self, firstrow, lastrow, step=1, colnums = self._extract_colnums() array = self._read_rec_with_var( colnums, rows, sortind, dtype, offsets, isvar, _vstorage) + elif has_tbit: + # drop down to read_columns since we can't stuff into a + # contiguous array + colnums = self._extract_colnums() + rows = np.arange(firstrow, lastrow, step, dtype='i8') + array = self.read_columns( + colnums, rows=rows, vstorage=vstorage, upper=upper, + lower=lower, trim_strings=trim_strings, + ) else: if step != 1: rows = np.arange(firstrow, lastrow, step, dtype='i8') diff --git a/fitsio/tests/test_table.py b/fitsio/tests/test_table.py index 9902324f..516fb2b3 100644 --- a/fitsio/tests/test_table.py +++ b/fitsio/tests/test_table.py @@ -1257,6 +1257,13 @@ def test_table_bitcol_read_write(): d = fits[1].read() compare_rec(bdata, d, "table read/write") + rows = [0, 2] + d = fits[1].read(rows=rows) + compare_rec(bdata[rows], d, "table read/write rows") + + d = fits[1][:2] + compare_rec(bdata[:2], d, "table read/write slice") + # now test read_column with FITS(fname) as fits: From c4956723353958b5f83156386cbad52c29e99f56 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Mon, 5 Aug 2024 11:32:23 -0400 Subject: [PATCH 2/2] update CHANGES.md, bump version --- CHANGES.md | 7 +++++++ fitsio/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 047d3dc2..73c68e72 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +version 1.2.5 (not yet released) +------------- + +Bug Fixes + + - Fig bug slicing tables that have TBIT columns + version 1.2.4 ------------- diff --git a/fitsio/__init__.py b/fitsio/__init__.py index cca79d06..54ae40b7 100644 --- a/fitsio/__init__.py +++ b/fitsio/__init__.py @@ -5,7 +5,7 @@ usage. """ -__version__ = '1.2.4' +__version__ = '1.2.5' from . import fitslib diff --git a/setup.py b/setup.py index 707be3c2..56d1944b 100644 --- a/setup.py +++ b/setup.py @@ -318,7 +318,7 @@ def check_system_cfitsio_objects(self, obj_name): setup( name="fitsio", - version="1.2.4", + version="1.2.5", description=description, long_description=long_description, long_description_content_type='text/markdown; charset=UTF-8; variant=GFM',