Skip to content

Commit

Permalink
Merge pull request #371 from esheldon/rowsnull
Browse files Browse the repository at this point in the history
BUG checking rows were sent
  • Loading branch information
esheldon authored Jun 27, 2023
2 parents 54cc73d + 566086e commit db69aad
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
version 1.1.10 (unreleased)
---------------------------

Changes

Bug Fixes

- Fix errors on 32 bit builds where default numpy integer
types were 32 rather than 64 bit assumed by the C code.
- Fix checks for rows being sent to C codes

version 1.1.9
-------------

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.1.9'
__version__ = '1.1.10'

from . import fitslib

Expand Down
17 changes: 8 additions & 9 deletions fitsio/fitsio_pywrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3205,8 +3205,6 @@ static int read_binary_column(
LONGLONG repeat=0;
LONGLONG width=0;

int rows_sent=0;

// use char for pointer arith. It's actually ok to use void as char but
// this is just in case.
char *data=NULL, *ptr=NULL;
Expand All @@ -3220,10 +3218,8 @@ static int read_binary_column(
repeat = colptr->trepeat;
width = colptr->tdatatype == TSTRING ? 1 : colptr->twidth;

rows_sent = nrows == hdu->numrows ? 0 : 1;

for (irow=0; irow<nrows; irow++) {
if (rows_sent) {
if (rows != NULL) {
si = sortind[irow];
row = rows[si];
} else {
Expand Down Expand Up @@ -3539,7 +3535,6 @@ static int read_binary_rec_columns(
npy_int64 colnum=0;
char* ptr=NULL;

int rows_sent=0;
npy_intp irow=0;
npy_int64 row=0, si=0;

Expand All @@ -3550,10 +3545,8 @@ static int read_binary_rec_columns(
// using struct defs here, could cause problems
hdu = fits->Fptr;

rows_sent = (nrows == hdu->numrows) ? 0 : 1;

for (irow=0; irow < nrows; irow++) {
if (rows_sent) {
if (rows != NULL) {
si = sortind[irow];
row = rows[si];
} else {
Expand Down Expand Up @@ -3644,7 +3637,13 @@ PyFITSObject_read_columns_as_rec(struct PyFITSObject* self, PyObject* args) {
nrows = hdu->numrows;
} else {
rows = get_int64_from_array(rowsObj, &nrows);
if (rows == NULL) {
return NULL;
}
sortind = get_int64_from_array(sortindObj, &nsortind);
if (sortind == NULL) {
return NULL;
}
}
if (read_binary_rec_columns(
self->fits, ncols, colnums,
Expand Down
6 changes: 3 additions & 3 deletions fitsio/hdu/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ def read_slice(self, firstrow, lastrow, step=1,
else:
_vstorage = vstorage
rows = np.arange(firstrow, lastrow, step, dtype='i8')
sortind = np.arange(rows.size)
sortind = np.arange(rows.size, dtype='i8')
colnums = self._extract_colnums()
array = self._read_rec_with_var(
colnums, rows, sortind, dtype, offsets, isvar, _vstorage)
Expand Down Expand Up @@ -1425,8 +1425,8 @@ def _extract_rows(self, rows, sort=False):
rows = np.unique(rows)
return rows, None

# returns unique, sorted
sortind = rows.argsort()
# returns unique, sorted. Force i8 for 32-bit systems
sortind = np.array(rows.argsort(), dtype='i8', copy=False)

maxrow = self._info['nrows']-1
if rows.size > 0:
Expand Down
2 changes: 1 addition & 1 deletion fitsio/tests/makedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


@lru_cache
@lru_cache(maxsize=1)
def make_data():

nvec = 2
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def check_system_cfitsio_objects(self, obj_name):

setup(
name="fitsio",
version="1.1.9",
version="1.1.10",
description=description,
long_description=long_description,
long_description_content_type='text/markdown; charset=UTF-8; variant=GFM',
Expand Down

0 comments on commit db69aad

Please sign in to comment.