Skip to content

Commit

Permalink
need to still be backwards compatible with old astropy. sigh
Browse files Browse the repository at this point in the history
  • Loading branch information
mpound committed Nov 6, 2024
1 parent c9b37f1 commit 9fffadd
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/dysh/fits/sdfitsload.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ def _add_primary_hdu(self):
self._index[k] = v
elif self._index[k][0] != v:
warnings.warn(
f"Column {k} is defined in the primary header and in the binary table index, but their values do not match. Will not update this column in the index.",
f"Column {k} is defined in the primary header and in the binary table index, but their values do"
" not match. Will not update this column in the index.",
UserWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -661,7 +662,7 @@ def _bintable_from_rows(self, rows=None, bintable=None):
rows.sort()
outbintable = self._bintable[bintable].copy()
outbintable.data = outbintable.data[rows]
outbintable.update_header()
outbintable.update()
return outbintable

def write(
Expand Down Expand Up @@ -863,7 +864,8 @@ def _add_binary_table_column(self, name, value, bintable=None):
if bintable is not None:
if lenv != self.nrows(bintable):
raise ValueError(
f"Length of values array ({len(value)}) for column {name} and total number of rows ({self.nrows(bintable)}) aren't equal."
f"Length of values array ({len(value)}) for column {name} and total number of rows"
f" ({self.nrows(bintable)}) aren't equal."
)
if is_col:
self._bintable[bintable].columns.add_col(value)
Expand All @@ -872,11 +874,12 @@ def _add_binary_table_column(self, name, value, bintable=None):
t = BinTableHDU(t1)
self._bintable[bintable].columns.add_col(t.columns[name])
# self._update_column_added(bintable, self._bintable[bintable].columns)
# self._bintable[bintable].update_header()
# self._bintable[bintable].update()
else:
if lenv != self.total_rows:
raise ValueError(
f"Length of values array ({len(value)}) for column {name} and total number of rows ({self.total_rows}) aren't equal."
f"Length of values array ({len(value)}) for column {name} and total number of rows"
f" ({self.total_rows}) aren't equal."
)
# Split values up by length of the individual binary tables
start = 0
Expand All @@ -891,7 +894,7 @@ def _add_binary_table_column(self, name, value, bintable=None):
t = BinTableHDU(Table(names=[name], data=[value[start : start + n]]))
self._bintable[i].columns.add_col(t.columns[name])
# self._update_column_added(i, self._bintable[i].columns)
# self._bintable[bintable].update_header()
# self._bintable[bintable].update()
start = start + n

def _update_column_added(self, bintable, coldefs):
Expand Down Expand Up @@ -943,7 +946,7 @@ def _update_binary_table_column(self, column_dict):
# otherwise we need to add rather than replace/update
else:
self._add_binary_table_column(k, value, 0)
self._bintable[0].update_header()
self._bintable[0].update()
else:
start = 0
for k, v in column_dict.items():
Expand All @@ -956,7 +959,8 @@ def _update_binary_table_column(self, column_dict):
is_str = isinstance(value, str)
if not is_str and isinstance(value, (Sequence, np.ndarray)) and len(value) != self.total_rows:
raise ValueError(
f"Length of values array ({len(v)}) for column {k} and total number of rows ({self.total_rows}) aren't equal."
f"Length of values array ({len(v)}) for column {k} and total number of rows ({self.total_rows})"
" aren't equal."
)

# Split values up by length of the individual binary tables
Expand Down Expand Up @@ -986,7 +990,7 @@ def _update_binary_table_column(self, column_dict):
v1 = np.array(value[start : start + n])
start = start + n
self._add_binary_table_column(k, v1, j)
self._bintable[j].update_header()
self._bintable[j].update()

def __getitem__(self, items):
# items can be a single string or a list of strings.
Expand All @@ -1004,7 +1008,8 @@ def __getitem__(self, items):
[b.data[multikey].shape == self._bintable[0].data[multikey].shape for b in self._bintable]
):
raise ValueError(
"{multikey} columns for multiple binary tables in this SDFITSLoad have different shapes. They can only be accessed via _bintable.data['DATA'] attribute."
"{multikey} columns for multiple binary tables in this SDFITSLoad have different shapes. They"
" can only be accessed via _bintable.data['DATA'] attribute."
)
if len(self._bintable) == 1:
return self._bintable[0].data[multikey]
Expand Down

0 comments on commit 9fffadd

Please sign in to comment.