Skip to content

Commit

Permalink
Add test for lsdb.to_hipscat (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucchi-cmu authored Apr 1, 2024
1 parent 4f81c84 commit 2f07189
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def small_sky_order1_dir_local(local_data_dir):
return os.path.join(local_data_dir, SMALL_SKY_ORDER1_DIR_NAME)


@pytest.fixture
def small_sky_parts_dir_local(local_data_dir):
return os.path.join(local_data_dir, "small_sky_parts")


@pytest.fixture
def tmp_dir_cloud(example_cloud_path):
return os.path.join(example_cloud_path, "tmp")
Expand Down
5 changes: 0 additions & 5 deletions tests/hipscat_import/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ def dask_client():
@pytest.fixture
def small_sky_parts_dir_cloud(example_cloud_path):
return os.path.join(example_cloud_path, "hipscat_import", "data", "small_sky_parts")


@pytest.fixture
def small_sky_parts_dir_local(local_data_dir):
return os.path.join(local_data_dir, "small_sky_parts")
33 changes: 33 additions & 0 deletions tests/lsdb/io/test_to_hipscat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

import lsdb
import pandas as pd

from hipscat_cloudtests import TempCloudDirectory


def test_save_catalog_and_margin(local_data_dir, example_cloud_storage_options, tmp_dir_cloud):
pathway = os.path.join(local_data_dir, "xmatch", "xmatch_catalog_raw.csv")
input_df = pd.read_csv(pathway)
catalog = lsdb.from_dataframe(
input_df, margin_threshold=5000, catalog_name="small_sky_from_dataframe", catalog_type="object"
)

with TempCloudDirectory(
tmp_dir_cloud, "lsdb_save_catalog_and_margin", example_cloud_storage_options
) as temp_path:
base_catalog_path = f"{temp_path}/new_catalog_name"
catalog.to_hipscat(base_catalog_path, storage_options=example_cloud_storage_options)
expected_catalog = lsdb.read_hipscat(base_catalog_path, storage_options=example_cloud_storage_options)
assert expected_catalog.hc_structure.catalog_name == catalog.hc_structure.catalog_name
assert expected_catalog.hc_structure.catalog_info == catalog.hc_structure.catalog_info
assert expected_catalog.get_healpix_pixels() == catalog.get_healpix_pixels()
pd.testing.assert_frame_equal(expected_catalog.compute(), catalog._ddf.compute())

base_catalog_path = f"{temp_path}/new_margin_name"
catalog.margin.to_hipscat(base_catalog_path, storage_options=example_cloud_storage_options)
expected_catalog = lsdb.read_hipscat(base_catalog_path, storage_options=example_cloud_storage_options)
assert expected_catalog.hc_structure.catalog_name == catalog.margin.hc_structure.catalog_name
assert expected_catalog.hc_structure.catalog_info == catalog.margin.hc_structure.catalog_info
assert expected_catalog.get_healpix_pixels() == catalog.margin.get_healpix_pixels()
pd.testing.assert_frame_equal(expected_catalog.compute(), catalog.margin._ddf.compute())

0 comments on commit 2f07189

Please sign in to comment.