Skip to content

Commit

Permalink
Make classes private
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy committed Sep 13, 2023
1 parent acd3430 commit ab59320
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion heracles/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"""Module for catalogue processing."""

from .array import ArrayCatalog # noqa: F401
from .base import Catalog, CatalogBase, CatalogPage, CatalogView # noqa: F401
from .base import Catalog, CatalogPage, CatalogView, _CatalogBase # noqa: F401
from .filters import FootprintFilter, InvalidValueFilter # noqa: F401
from .fits import FitsCatalog # noqa: F401
10 changes: 3 additions & 7 deletions heracles/catalog/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
from collections.abc import Iterator
from typing import Optional, TypeVar

from .base import CatalogBase, CatalogPage
from .base import CatalogPage, _CatalogBase


class ArrayCatalog(CatalogBase):
"""Catalogue reader for arrays.
Args:
CatalogBase: _description_
"""
class ArrayCatalog(_CatalogBase):
"""Catalogue reader for arrays."""

def __init__(self, arr: TypeVar("Unknown")) -> None:
"""Create a new array catalogue reader.
Expand Down
4 changes: 2 additions & 2 deletions heracles/catalog/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def select(self, selection: TypeVar("Unknown")) -> Iterator[TypeVar("Unknown")]:
yield from self._catalog.select(joined)


class CatalogBase(metaclass=ABCMeta):
class _CatalogBase(metaclass=ABCMeta):
"""Abstract base class for base catalogues (not views)."""

_default_page_size: int = 100_000
Expand All @@ -405,7 +405,7 @@ def __init__(self) -> None:
self._filters = []
self._visibility = None

def __copy__(self) -> "CatalogBase":
def __copy__(self) -> "_CatalogBase":
"""Return a shallow copy of the catalogue.
Returns
Expand Down
10 changes: 3 additions & 7 deletions heracles/catalog/fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import fitsio

from .base import CatalogBase, CatalogPage
from .base import CatalogPage, _CatalogBase


def _is_table_hdu(hdu: fitsio.hdu.TableHDU) -> bool:
Expand Down Expand Up @@ -52,12 +52,8 @@ def rowfilter(array: TypeVar("Unknown"), expr: str) -> Any:
return eval(expr, None, {name: array[name] for name in array.dtype.names})


class FitsCatalog(CatalogBase):
"""Flexible reader for catalogues from FITS files.
Args:
CatalogBase: _description_
"""
class FitsCatalog(_CatalogBase):
"""Flexible reader for catalogues from FITS files."""

def __init__(self, filename, *, columns=None, ext=None) -> None:
"""Create a new FITS catalogue reader.
Expand Down
10 changes: 5 additions & 5 deletions heracles/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def update_metadata(
_MapGenerator = t.Generator[_MapFunction, None, _MapData]


class Map(metaclass=ABCMeta):
class _Map(metaclass=ABCMeta):
"""Abstract base class for map making from catalogues.
Concrete classes must implement the `__call__()` method which takes a
Expand Down Expand Up @@ -221,7 +221,7 @@ def __call__(self, catalog: "Catalog") -> t.Union[_MapData, _MapGenerator]:
...


class HealpixMap(Map):
class HealpixMap(_Map):
"""Abstract base class for HEALPix map making.
HEALPix maps have a resolution parameter, available as the ``nside``
Expand Down Expand Up @@ -259,7 +259,7 @@ def nside(self, nside: int) -> None:
self._nside = nside


class RandomizableMap(Map):
class RandomizableMap(_Map):
"""Abstract base class for randomisable maps.
Randomisable maps have a ``randomize`` property that determines
Expand Down Expand Up @@ -297,7 +297,7 @@ def randomize(self, randomize: bool) -> None:
self._randomize = randomize


class NormalizableMap(Map):
class NormalizableMap(_Map):
"""Abstract base class for normalisable maps.
A normalised map is a map that is divided by its mean weight.
Expand Down Expand Up @@ -975,7 +975,7 @@ def _close_and_return(generator: t.Generator) -> t.Any:


def map_catalogs(
maps: t.Mapping[t.Any, Map],
maps: t.Mapping[t.Any, _Map],
catalogs: t.Mapping[t.Any, "Catalog"],
*,
parallel: bool = False,
Expand Down
22 changes: 11 additions & 11 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

@pytest.fixture
def catalog():
from heracles.catalog import CatalogBase, CatalogPage
from heracles.catalog import CatalogPage, _CatalogBase

# fix a set of rows to be returned for testing
size = 100
x = np.random.rand(size)
y = np.random.rand(size)
z = np.random.rand(size)

class TestCatalog(CatalogBase):
class TestCatalog(_CatalogBase):
SIZE = size
DATA = dict(x=x, y=y, z=z)

Expand Down Expand Up @@ -145,33 +145,33 @@ def test_catalog_page_immutable():


def test_catalog_base(catalog):
from heracles.catalog import Catalog, CatalogBase
from heracles.catalog import Catalog, _CatalogBase

# ABC cannot be instantiated directly
with pytest.raises(TypeError):
CatalogBase()
_CatalogBase()

# fixture has tested concrete implementation
assert isinstance(catalog, CatalogBase)
assert isinstance(catalog, _CatalogBase)

# check that CatalogBase implements the Catalog protocol
assert isinstance(catalog, Catalog)


def test_catalog_base_properties(catalog):
from heracles.catalog import CatalogBase
from heracles.catalog import _CatalogBase

assert catalog.size == catalog.SIZE
assert catalog.names == list(catalog.DATA.keys())

assert catalog.base is None
assert catalog.selection is None

assert catalog.page_size == CatalogBase._default_page_size
assert catalog.page_size == _CatalogBase._default_page_size
catalog.page_size = 1
assert catalog.page_size == 1
catalog.page_size = CatalogBase._default_page_size
assert catalog.page_size == CatalogBase._default_page_size
catalog.page_size = _CatalogBase._default_page_size
assert catalog.page_size == _CatalogBase._default_page_size

filt = object()
assert catalog.filters == []
Expand Down Expand Up @@ -202,9 +202,9 @@ def test_catalog_base_pagination(catalog):


def test_catalog_base_copy():
from heracles.catalog import CatalogBase
from heracles.catalog import _CatalogBase

class TestCatalog(CatalogBase):
class TestCatalog(_CatalogBase):
def __init__(self):
super().__init__()
self._visibility = object()
Expand Down

0 comments on commit ab59320

Please sign in to comment.