Skip to content

Commit

Permalink
Merge pull request astropy#16581 from neutrinoceros/io.fits/bug/16578…
Browse files Browse the repository at this point in the history
…/skip_windows_hack_on_numpy2

BUG: skip un-portable hack on windows + numpy2
  • Loading branch information
mhvk committed Jun 18, 2024
2 parents 5d1b667 + 239c9d4 commit c86243e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion astropy/io/fits/hdu/hdulist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from astropy.io.fits.verify import VerifyError, VerifyWarning, _ErrList, _Verify
from astropy.utils import indent
from astropy.utils.compat.numpycompat import NUMPY_LT_2_0

# NOTE: Python can be built without bz2.
from astropy.utils.compat.optional_deps import HAS_BZ2
Expand Down Expand Up @@ -1506,7 +1507,7 @@ def _flush_resize(self):
del hdu.data
hdu._file = ffo

if sys.platform.startswith("win"):
if sys.platform.startswith("win") and NUMPY_LT_2_0:
# On Windows, all the original data mmaps were closed above.
# However, it's possible that the user still has references to
# the old data which would no longer work (possibly even cause
Expand All @@ -1517,6 +1518,8 @@ def _flush_resize(self):
# lead to odd behavior in practice. Better to just not keep
# references to data from files that had to be resized upon
# flushing (on Windows--again, this is no problem on Linux).
# Note that this hack is only possible on numpy 1.x:
# in 2.x, we cannot write directly to the data attribute
for idx, mmap, arr in mmaps:
if mmap is not None:
# https://github.com/numpy/numpy/issues/8628
Expand Down
5 changes: 5 additions & 0 deletions docs/changes/io.fits/16581.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed a crash that occurred for files opened via
``fits.open(..., mode='update')``, on Windows, and with numpy 2.0 installed.
It is possible, though unlikely, that this patch reveals memory issues
for downstream code run under these exact conditions. Please report any
regression found.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ keywords = [
]
dependencies = [
"numpy>=1.23",
# https://github.com/astropy/astropy/issues/16578
"numpy < 2.0 ; platform_system=='Windows'",
"pyerfa>=2.0.1.1",
"astropy-iers-data>=0.2024.5.27.0.30.8",
"PyYAML>=3.13",
Expand Down

0 comments on commit c86243e

Please sign in to comment.