Skip to content

Commit

Permalink
Adding validation for parallaxes and fixing ParallaxView (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-rodriguez authored Jun 15, 2024
1 parent 1e7fea4 commit f2010f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
8 changes: 7 additions & 1 deletion simple/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ class Parallaxes(Base):
primary_key=True,
)

@validates("parallax")
def validate_value(self, key, value):
if value is None or value < 0:
raise ValueError(f"{key} not allowed to be 0 or lower")
return value


class ProperMotions(Base):
# Table to store proper motions, in milliarcseconds per year
Expand Down Expand Up @@ -445,7 +451,7 @@ class CompanionRelationships(Base):
Parallaxes.reference.label("reference"),
)
.select_from(Parallaxes)
.where(sa.and_(Parallaxes.adopted is True, Parallaxes.parallax > 0)),
.where(sa.and_(Parallaxes.adopted == 1, Parallaxes.parallax > 0)),
)

PhotometryView = view(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_integrity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Test to verify database integrity
# database object 'db' defined in conftest.py
import pytest
from sqlalchemy import func, and_
from astropy.table import unique
from astrodbkit2.astrodb import or_
from astrodbkit2.utils import _name_formatter
from astropy import units as u
from astropy.table import unique
from astroquery.simbad import Simbad
from astrodbkit2.utils import _name_formatter
from astrodbkit2.astrodb import or_
# from simple.schema import ParallaxView # , PhotometryView
from sqlalchemy import and_, func

from simple.schema import ParallaxView # , PhotometryView


def test_reference_uniqueness(db):
Expand Down Expand Up @@ -703,7 +704,6 @@ def test_special_characters(db):
assert all(check), f"{char} in {table_name}"


@pytest.mark.skip(reason="ParallaxView not working")
def test_database_views(db):
# Tests to verify views exist and work as intended

Expand Down
15 changes: 13 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from simple.schema import PhotometryFilters, Publications, Sources
from simple.schema import Parallaxes, PhotometryFilters, Publications, Sources


def schema_tester(table, values, error_state):
Expand Down Expand Up @@ -46,4 +46,15 @@ def test_sources(values, error_state):
])
def test_publications(values, error_state):
"""Validating Publications"""
schema_tester(Publications, values, error_state)
schema_tester(Publications, values, error_state)


@pytest.mark.parametrize("values, error_state",
[
({"parallax": 0.1}, None),
({"parallax": -999}, ValueError),
({"parallax": None}, ValueError),
])
def test_parallaxes(values, error_state):
"""Validating Parallaxes"""
schema_tester(Parallaxes, values, error_state)

0 comments on commit f2010f8

Please sign in to comment.