Skip to content

Commit

Permalink
Allow limit=None (sort of) but not offset=None.
Browse files Browse the repository at this point in the history
We mixed up which of these should be allowed to be None in the old
interface, but we don't need to repeat the mistake in the new one,
though some of the fix will have to wait until new interfaces stop
delegating to the old ones.
  • Loading branch information
TallJimbo committed Dec 10, 2023
1 parent 5df890c commit 01df32d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def _query_data_ids(
expanded: bool = False,
order_by: Iterable[str] | str | None = None,
limit: int | None = None,
offset: int | None = None,
offset: int = 0,
explain: bool = True,
**kwargs: Any,
) -> list[DataCoordinate]:
Expand Down Expand Up @@ -1569,7 +1569,7 @@ def _query_dimension_records(
bind: Mapping[str, Any] | None = None,
order_by: Iterable[str] | str | None = None,
limit: int | None = None,
offset: int | None = None,
offset: int = 0,
explain: bool = True,
**kwargs: Any,
) -> list[DimensionRecord]:
Expand Down
18 changes: 8 additions & 10 deletions python/lsst/daf/butler/_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,16 @@ def order_by(self, *args: str) -> DataCoordinateQueryResults:
raise NotImplementedError()

@abstractmethod
def limit(self, limit: int, offset: int | None = 0) -> DataCoordinateQueryResults:
def limit(self, limit: int | None = None, offset: int = 0) -> DataCoordinateQueryResults:
"""Make the iterator return limited number of records.
Parameters
----------
limit : `int`
limit : `int` or `None`, optional
Upper limit on the number of returned records.
offset : `int` or `None`, optional
offset : `int`, optional
The number of records to skip before returning at most ``limit``
records. `None` is interpreted the same as zero for backwards
compatibility.
records.
Returns
-------
Expand Down Expand Up @@ -695,17 +694,16 @@ def order_by(self, *args: str) -> DimensionRecordQueryResults:
raise NotImplementedError()

@abstractmethod
def limit(self, limit: int, offset: int | None = 0) -> DimensionRecordQueryResults:
def limit(self, limit: int | None = None, offset: int = 0) -> DimensionRecordQueryResults:
"""Make the iterator return limited number of records.
Parameters
----------
limit : `int`
limit : `int` or `None`, optional
Upper limit on the number of returned records.
offset : `int` or `None`
offset : `int`, optional
The number of records to skip before returning at most ``limit``
records. `None` is interpreted the same as zero for backwards
compatibility.
records.
Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/direct_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ def _query_data_ids(
expanded: bool = False,
order_by: Iterable[str] | str | None = None,
limit: int | None = None,
offset: int | None = None,
offset: int = 0,
explain: bool = True,
**kwargs: Any,
) -> list[DataCoordinate]:
Expand Down Expand Up @@ -2289,7 +2289,7 @@ def _query_dimension_records(
bind: Mapping[str, Any] | None = None,
order_by: Iterable[str] | str | None = None,
limit: int | None = None,
offset: int | None = None,
offset: int = 0,
explain: bool = True,
**kwargs: Any,
) -> list[DimensionRecord]:
Expand Down
8 changes: 6 additions & 2 deletions python/lsst/daf/butler/direct_query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def order_by(self, *args: str) -> DataCoordinateQueryResults:
# Docstring inherited.
return DirectDataCoordinateQueryResults(self._registry_query_result.order_by(*args))

def limit(self, limit: int, offset: int | None = 0) -> DataCoordinateQueryResults:
def limit(self, limit: int | None = None, offset: int = 0) -> DataCoordinateQueryResults:
# Docstring inherited.
if limit is None:
raise NotImplementedError("Offset without limit is temporarily unsupported.")
return DirectDataCoordinateQueryResults(self._registry_query_result.limit(limit, offset))


Expand Down Expand Up @@ -289,8 +291,10 @@ def order_by(self, *args: str) -> DimensionRecordQueryResults:
# Docstring inherited.
return DirectDimensionRecordQueryResults(self._registry_query_result.order_by(*args))

def limit(self, limit: int, offset: int | None = 0) -> DimensionRecordQueryResults:
def limit(self, limit: int | None = None, offset: int = 0) -> DimensionRecordQueryResults:
# Docstring inherited.
if limit is None:
raise NotImplementedError("Offset without limit is temporarily unsupported.")
return DirectDimensionRecordQueryResults(self._registry_query_result.limit(limit, offset))

def explain_no_results(self, execute: bool = True) -> Iterable[str]:
Expand Down

0 comments on commit 01df32d

Please sign in to comment.