Skip to content

Commit 669a433

Browse files
committed
Avoid accessing self.data just to get data shape
1 parent a3543f1 commit 669a433

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎astropy/io/fits/hdu/compressed/compressed.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ def _has_data(self):
514514
def _data_loaded(self):
515515
return self._bintable is None or self._bintable.data is not DELAYED
516516

517+
@property
518+
def _data_shape(self):
519+
if self._decompression_active:
520+
return tuple(reversed(self._axes))
521+
else:
522+
return self.data.shape
523+
517524
@property
518525
def data(self):
519526
"""

‎astropy/io/fits/hdu/image.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,18 @@ def data(self, data):
319319
# setting self.__dict__['data']
320320
return data
321321

322+
@property
323+
def _data_shape(self):
324+
return self.data.shape
325+
322326
def update_header(self):
323327
"""
324328
Update the header keywords to agree with the data.
325329
"""
326330
if not (
327331
self._modified
328332
or self._header._modified
329-
or (self._has_data and self.shape != self.data.shape)
333+
or (self._has_data and self.shape != self._data_shape)
330334
):
331335
# Not likely that anything needs updating
332336
return
@@ -345,8 +349,8 @@ def update_header(self):
345349
# If the data's shape has changed (this may have happened without our
346350
# noticing either via a direct update to the data.shape attribute) we
347351
# need to update the internal self._axes
348-
if self._has_data and self.shape != self.data.shape:
349-
self._axes = list(self.data.shape)
352+
if self._has_data and self.shape != self._data_shape:
353+
self._axes = list(self._data_shape)
350354
self._axes.reverse()
351355

352356
# Update the NAXIS keyword and ensure it's in the correct location in

0 commit comments

Comments
 (0)