Skip to content

Commit

Permalink
feat: add ROW_LIMIT as a settable property
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Apr 8, 2024
1 parent fe86754 commit d8a50f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
19 changes: 17 additions & 2 deletions astroquery/simbad/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class SimbadClass(BaseVOQuery):
(https://simbad.cds.unistra.fr/guide/sim-url.htx)
"""
SIMBAD_URL = 'https://' + conf.server + '/simbad/sim-script'
ROW_LIMIT = conf.row_limit

@dataclass(frozen=True)
class Column:
Expand All @@ -104,7 +103,7 @@ class Join:
column_right: Any
join_type: str = field(default="JOIN")

def __init__(self):
def __init__(self, ROW_LIMIT=None):
super().__init__()
# to create the TAPService
self._server = conf.server
Expand All @@ -114,6 +113,22 @@ def __init__(self):
self._columns_in_output = None # a list of Simbad.Column
self.joins = [] # a list of Simbad.Join
self.criteria = [] # a list of strings
self.ROW_LIMIT = ROW_LIMIT

@property
def ROW_LIMIT(self):
return self._ROW_LIMIT

@ROW_LIMIT.setter
def ROW_LIMIT(self, ROW_LIMIT):
if ROW_LIMIT is None:
self._ROW_LIMIT = conf.row_limit
elif isinstance(ROW_LIMIT, int) and ROW_LIMIT >= -1:
self._ROW_LIMIT = ROW_LIMIT
else:
raise ValueError("ROW_LIMIT can be either -1 to set the limit to SIMBAD's "
"maximum capability, 0 to retrieve an empty table, "
"or a positive integer.")

@property
def server(self):
Expand Down
17 changes: 17 additions & 0 deletions astroquery/simbad/tests/test_simbad.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ def test_simbad_mirror():
simbad_instance.server = "test"


def test_simbad_row_limit():
simbad_instance = simbad.SimbadClass()
# default value is -1
assert simbad_instance.ROW_LIMIT == -1
# we can assign afterward
simbad_instance.ROW_LIMIT = 5
assert simbad_instance.ROW_LIMIT == 5
# or from the beginning
simbad_instance = simbad.SimbadClass(ROW_LIMIT=10)
assert simbad_instance.ROW_LIMIT == 10
# non-valid values trigger an error
with pytest.raises(ValueError, match="ROW_LIMIT can be either -1 to set the limit "
"to SIMBAD's maximum capability, 0 to retrieve an empty table, "
"or a positive integer."):
simbad_instance = simbad.SimbadClass(ROW_LIMIT='test')


def test_simbad_create_tap_service():
simbad_instance = simbad.Simbad()
# newly created should have no tap service
Expand Down

0 comments on commit d8a50f3

Please sign in to comment.