From 95df3bde6301bc746bc87898c9c50d18cae21524 Mon Sep 17 00:00:00 2001 From: Sean McGuire <123987820+smcguire-cmu@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:28:16 -0500 Subject: [PATCH] add more helpful error with non overlapping catalogs (#537) --- src/lsdb/dask/merge_catalog_functions.py | 12 +++++++++--- tests/lsdb/catalog/test_crossmatch.py | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lsdb/dask/merge_catalog_functions.py b/src/lsdb/dask/merge_catalog_functions.py index 8ae79242..fb109f6c 100644 --- a/src/lsdb/dask/merge_catalog_functions.py +++ b/src/lsdb/dask/merge_catalog_functions.py @@ -138,15 +138,19 @@ def func( aligned partitions of the catalogs """ - # aligns the catalog's partitions to the given pixels for each catalog - aligned_partitions = [align_catalog_to_partitions(cat, pixels) for (cat, pixels) in catalog_mappings] - # gets the pixels and hc_structures to pass to the function pixels = [pixels for (_, pixels) in catalog_mappings] + for p in pixels: + if len(p) == 0: + raise RuntimeError("Catalogs do not overlap") + catalog_infos = [ cat.hc_structure.catalog_info if cat is not None else None for (cat, _) in catalog_mappings ] + # aligns the catalog's partitions to the given pixels for each catalog + aligned_partitions = [align_catalog_to_partitions(cat, pixels) for (cat, pixels) in catalog_mappings] + # defines an inner function that can be vectorized to apply the given function to each of the partitions # with the additional arguments including as the hc_structures and any specified additional arguments def apply_func(*partitions_and_pixels): @@ -208,6 +212,8 @@ def get_healpix_pixels_from_alignment( a tuple of (primary_pixels, join_pixels) with lists of HealpixPixel objects """ pixel_mapping = alignment.pixel_mapping + if len(pixel_mapping) == 0: + return ([], []) make_pixel = np.vectorize(HealpixPixel) left_pixels = make_pixel( pixel_mapping[PixelAlignment.PRIMARY_ORDER_COLUMN_NAME], diff --git a/tests/lsdb/catalog/test_crossmatch.py b/tests/lsdb/catalog/test_crossmatch.py index 63d0d069..1710525b 100644 --- a/tests/lsdb/catalog/test_crossmatch.py +++ b/tests/lsdb/catalog/test_crossmatch.py @@ -418,3 +418,10 @@ def test_algorithm_has_no_extra_columns_specified(small_sky_xmatch_catalog): def test_raise_for_unknown_kwargs(small_sky_catalog): with pytest.raises(TypeError, match="unexpected keyword argument"): small_sky_catalog.crossmatch(small_sky_catalog, unknown_kwarg="value") + + +def test_raise_for_non_overlapping_catalogs(small_sky_order1_catalog, small_sky_xmatch_catalog): + small_sky_order1_catalog = small_sky_order1_catalog.pixel_search([HealpixPixel(1, 44)]) + small_sky_xmatch_catalog = small_sky_xmatch_catalog.pixel_search([HealpixPixel(1, 45)]) + with pytest.raises(RuntimeError, match="overlap"): + small_sky_order1_catalog.crossmatch(small_sky_xmatch_catalog)