Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
smcguire-cmu committed Oct 11, 2023
1 parent 31f0131 commit cb797a3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/hipscat/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ def small_sky_order1_pixels():
HealpixPixel(1, 45),
HealpixPixel(1, 46),
HealpixPixel(1, 47),
]
]
8 changes: 5 additions & 3 deletions tests/hipscat/io/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@pytest.fixture
def assert_text_file_matches():
def assert_text_file_matches(expected_lines, file_name, storage_options: dict={}):
def assert_text_file_matches(expected_lines, file_name, storage_options: dict = {}):
"""Convenience method to read a text file and compare the contents, line for line.
When file contents get even a little bit big, it can be difficult to see
Expand All @@ -31,7 +31,9 @@ def assert_text_file_matches(expected_lines, file_name, storage_options: dict={}
file_name (str): fully-specified path of the file to read
storage_options (dict): dictionary of filesystem storage options
"""
assert does_file_or_directory_exist(file_name, storage_options=storage_options), f"file not found [{file_name}]"
assert does_file_or_directory_exist(
file_name, storage_options=storage_options
), f"file not found [{file_name}]"
contents = load_text_file(file_name, storage_options=storage_options)

assert len(expected_lines) == len(
Expand All @@ -56,4 +58,4 @@ def basic_catalog_parquet_metadata():
pa.field("dec_error", pa.int64()),
pa.field("__index_level_0__", pa.int64()),
]
)
)
23 changes: 17 additions & 6 deletions tests/hipscat/io/file_io/test_file_pointers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_directory_has_contents(small_sky_order1_dir, tmp_path):
def test_get_directory_contents(small_sky_order1_dir, tmp_path):
small_sky_contents = get_directory_contents(small_sky_order1_dir)

for i,content in enumerate(small_sky_contents):
for i, content in enumerate(small_sky_contents):
if not content.startswith("/"):
small_sky_contents[i] = f"/{content}"

Expand All @@ -99,20 +99,25 @@ def test_get_directory_contents(small_sky_order1_dir, tmp_path):

assert len(get_directory_contents(tmp_path)) == 0


def test_get_fs():
filesystem, _ = get_fs("file://")
assert filesystem.protocol == "file"
#this will fail if the environment installs lakefs to import

# this will fail if the environment installs lakefs to import
with pytest.raises(ImportError):
get_fs("lakefs://")

with pytest.raises(ValueError):
get_fs("invalid://")


def test_get_file_pointer_for_fs():
test_abfs_protocol_path = get_file_pointer_from_path("abfs:///container/path/to/parquet/file")
assert get_file_pointer_for_fs("abfs", file_pointer=test_abfs_protocol_path) == "/container/path/to/parquet/file"
assert (
get_file_pointer_for_fs("abfs", file_pointer=test_abfs_protocol_path)
== "/container/path/to/parquet/file"
)
test_s3_protocol_path = get_file_pointer_from_path("s3:///bucket/path/to/catalog.json")
assert get_file_pointer_for_fs("s3", file_pointer=test_s3_protocol_path) == "/bucket/path/to/catalog.json"
test_local_path = get_file_pointer_from_path("/path/to/file")
Expand All @@ -123,6 +128,12 @@ def test_get_file_pointer_for_fs():

def test_strip_leading_slash_for_pyarrow():
test_leading_slash_filename = get_file_pointer_from_path("/bucket/path/test.txt")
assert strip_leading_slash_for_pyarrow(test_leading_slash_filename, protocol="abfs") == "bucket/path/test.txt"
assert (
strip_leading_slash_for_pyarrow(test_leading_slash_filename, protocol="abfs")
== "bucket/path/test.txt"
)
test_non_leading_slash_filenaem = get_file_pointer_from_path("bucket/path/test.txt")
assert strip_leading_slash_for_pyarrow(test_non_leading_slash_filenaem, protocol="abfs") == "bucket/path/test.txt"
assert (
strip_leading_slash_for_pyarrow(test_non_leading_slash_filenaem, protocol="abfs")
== "bucket/path/test.txt"
)
2 changes: 1 addition & 1 deletion tests/hipscat/io/test_write_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def check_parquet_schema(file_name, expected_schema, expected_num_row_groups=1):

assert schema.equals(expected_schema, check_metadata=False)

parquet_file = file_io.read_parquet_file(file_name)
parquet_file = file_io.read_parquet_file(file_name)
assert parquet_file.metadata.num_row_groups == expected_num_row_groups

for row_index in range(0, parquet_file.metadata.num_row_groups):
Expand Down
12 changes: 3 additions & 9 deletions tests/hipscat/pixel_math/test_hipscat_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def test_hipscat_id_to_healpix():
def test_healpix_to_hipscat_id_single():
orders = [3, 3, 4, 1]
pixels = [0, 12, 1231, 11]
pixels_at_high_order = [
p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)
]
pixels_at_high_order = [p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)]
lon, lat = hp.pix2ang(
[2**HIPSCAT_ID_HEALPIX_ORDER] * len(orders), pixels_at_high_order, nest=True, lonlat=True
)
Expand All @@ -133,9 +131,7 @@ def test_healpix_to_hipscat_id_single():
def test_healpix_to_hipscat_id_array():
orders = [3, 3, 4, 1]
pixels = [0, 12, 1231, 11]
pixels_at_high_order = [
p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)
]
pixels_at_high_order = [p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)]
lon, lat = hp.pix2ang(
[2**HIPSCAT_ID_HEALPIX_ORDER] * len(orders), pixels_at_high_order, nest=True, lonlat=True
)
Expand All @@ -148,9 +144,7 @@ def test_healpix_to_hipscat_id_offset():
orders = [3, 3, 4, 1]
pixels = [0, 0, 1231, 11]
offsets = [0, 1, 0, 0]
pixels_at_high_order = [
p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)
]
pixels_at_high_order = [p * (4 ** (HIPSCAT_ID_HEALPIX_ORDER - o)) for o, p in zip(orders, pixels)]
lon, lat = hp.pix2ang(
[2**HIPSCAT_ID_HEALPIX_ORDER] * len(orders), pixels_at_high_order, nest=True, lonlat=True
)
Expand Down
52 changes: 29 additions & 23 deletions tests/hipscat/pixel_math/test_margin_bounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_check_margin_bounds():
"""Make sure check_margin_bounds works properly"""

ras = np.array([42.4704538, 56.25, 56.25, 50.61225197])
decs = np.array([1.4593925, 9.6, 10., 14.4767556])
decs = np.array([1.4593925, 9.6, 10.0, 14.4767556])

checks = pm.check_margin_bounds(ras, decs, 3, 4, 360.0)

Expand All @@ -23,27 +23,31 @@ def test_check_margin_bounds():
def test_check_margin_bounds_low_order():
"""Make sure check_margin_bounds works when using a low order healpixel"""

ras = np.array([
142.4704538,
45.09,
45.2,
37.31343956517391,
42.649354753311535,
32.62796809350278,
39.89468227954832,
27.718121934039974
])

decs = np.array([
1.4593925,
0.0,
0.0,
6.566326903165274,
2.005185097251452,
10.597884275167646,
4.465967883812584,
14.959672304191956
])
ras = np.array(
[
142.4704538,
45.09,
45.2,
37.31343956517391,
42.649354753311535,
32.62796809350278,
39.89468227954832,
27.718121934039974,
]
)

decs = np.array(
[
1.4593925,
0.0,
0.0,
6.566326903165274,
2.005185097251452,
10.597884275167646,
4.465967883812584,
14.959672304191956,
]
)

checks = pm.check_margin_bounds(ras, decs, 0, 4, 360.0)

Expand Down Expand Up @@ -81,15 +85,17 @@ def test_check_polar_margin_bounds_south():

npt.assert_array_equal(vals, expected)


def test_check_margin_bounds_uneven():
"""Ensure check_margin_bounds fails when ra and dec arrays are unbalanced."""

ras = np.array([42.4704538, 56.25, 56.25, 50.61225197])
decs = np.array([1.4593925, 9.6, 10.])
decs = np.array([1.4593925, 9.6, 10.0])

with pytest.raises(ValueError, match="length of r_asc"):
pm.check_margin_bounds(ras, decs, 3, 4, 360.0)


def test_check_margin_bounds_empty():
"""Ensure check_margin_bounds works when passed empty coordinate arrays."""

Expand Down

0 comments on commit cb797a3

Please sign in to comment.