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

check TBIT for slices/rows read #409

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
-------------

Expand Down
2 changes: 1 addition & 1 deletion fitsio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
usage.
"""

__version__ = '1.2.4'
__version__ = '1.2.5'

from . import fitslib

Expand Down
21 changes: 21 additions & 0 deletions fitsio/hdu/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions fitsio/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading