Skip to content

Commit

Permalink
Fix read/write of dense histogram (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
camposandro authored Oct 16, 2024
1 parent 9c24f97 commit c1acd21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/hipscat/pixel_math/sparse_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def to_file(self, file_name):

def to_dense_file(self, file_name):
"""Persist the DENSE array to disk as a numpy array."""
np.save(file_name, self.to_array())
with open(file_name, "wb+") as file_handle:
file_handle.write(self.to_array().data)

@classmethod
def make_empty(cls, healpix_order=10):
Expand Down
6 changes: 4 additions & 2 deletions tests/hipscat/pixel_math/test_sparse_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import numpy.testing as npt
import pytest
from numpy import frombuffer
from scipy.sparse import csr_array

import hipscat.pixel_math.healpix_shim as hp
Expand All @@ -27,9 +28,10 @@ def test_read_write_round_trip(tmp_path):
npt.assert_array_equal(read_histogram.to_array(), histogram.to_array())

# Write as a dense 1-d numpy array
file_name = tmp_path / "round_trip_dense.npy"
file_name = tmp_path / "round_trip_dense.npz"
histogram.to_dense_file(file_name)
read_histogram = np.load(str(file_name))
with open(file_name, "rb") as file_handle:
read_histogram = frombuffer(file_handle.read(), dtype=np.int64)
npt.assert_array_equal(read_histogram, histogram.to_array())


Expand Down

0 comments on commit c1acd21

Please sign in to comment.