From ab593203b2df14bd79067df9acf62f84e7b8c2b3 Mon Sep 17 00:00:00 2001 From: Paddy Roddy Date: Wed, 13 Sep 2023 12:52:31 +0100 Subject: [PATCH] Make classes private --- heracles/catalog/__init__.py | 2 +- heracles/catalog/array.py | 10 +++------- heracles/catalog/base.py | 4 ++-- heracles/catalog/fits.py | 10 +++------- heracles/maps.py | 10 +++++----- tests/test_catalog.py | 22 +++++++++++----------- 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/heracles/catalog/__init__.py b/heracles/catalog/__init__.py index a7ccbe6..9d79304 100644 --- a/heracles/catalog/__init__.py +++ b/heracles/catalog/__init__.py @@ -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 diff --git a/heracles/catalog/array.py b/heracles/catalog/array.py index 497dcdc..3501466 100644 --- a/heracles/catalog/array.py +++ b/heracles/catalog/array.py @@ -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. diff --git a/heracles/catalog/base.py b/heracles/catalog/base.py index 314d10d..6f054a7 100644 --- a/heracles/catalog/base.py +++ b/heracles/catalog/base.py @@ -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 @@ -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 diff --git a/heracles/catalog/fits.py b/heracles/catalog/fits.py index 537171b..f87c203 100644 --- a/heracles/catalog/fits.py +++ b/heracles/catalog/fits.py @@ -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: @@ -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. diff --git a/heracles/maps.py b/heracles/maps.py index 44a961e..94b088b 100644 --- a/heracles/maps.py +++ b/heracles/maps.py @@ -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 @@ -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`` @@ -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 @@ -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. @@ -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, diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 223df26..77c7094 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -5,7 +5,7 @@ @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 @@ -13,7 +13,7 @@ def catalog(): 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) @@ -145,21 +145,21 @@ 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()) @@ -167,11 +167,11 @@ def test_catalog_base_properties(catalog): 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 == [] @@ -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()