Skip to content

Commit

Permalink
Make attirbutes private
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy committed Sep 13, 2023
1 parent e04ade3 commit acd3430
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions heracles/catalog/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ def select(self, selection: TypeVar("Unknown")) -> Iterator[TypeVar("Unknown")]:
class CatalogBase(metaclass=ABCMeta):
"""Abstract base class for base catalogues (not views)."""

default_page_size: int = 100_000
_default_page_size: int = 100_000
"""Default value for page size"""

def __init__(self) -> None:
"""Create a new catalogue instance."""
self._page_size = self.default_page_size
self._page_size = self._default_page_size
self._filters = []
self._visibility = None

Expand Down
19 changes: 10 additions & 9 deletions heracles/catalog/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def __init__(
If ``warn`` is true, invalid values will emit a warning.
Args:
columns: _description_
weight: _description_
warn: _description_
"""
self.columns = columns
self.weight = weight
self.warn = warn
self._columns = columns
self._weight = weight
self._warn = warn

def __repr__(self) -> str:
"""_summary_.
Expand All @@ -53,8 +54,8 @@ def __repr__(self) -> str:
_description_
"""
name = self.__class__.__name__
args = list(map(repr, self.columns))
args += [f"weight={self.weight!r}", f"warn={self.warn!r}"]
args = list(map(repr, self._columns))
args += [f"weight={self._weight!r}", f"warn={self._warn!r}"]
args = ", ".join(args)
return f"{name}({args})"

Expand All @@ -65,13 +66,13 @@ def __call__(self, page: TypeVar("Unknown")) -> None:
page: _description_
"""
invalid_mask = np.zeros(page.size, dtype=bool)
for col in self.columns:
for col in self._columns:
invalid_mask |= np.isnan(page[col])
if self.weight is not None:
invalid_mask &= page[self.weight] != 0
if self._weight is not None:
invalid_mask &= page[self._weight] != 0
invalid = np.where(invalid_mask)[0]
if len(invalid) > 0:
if self.warn:
if self._warn:
warnings.warn("WARNING: catalog contains invalid values")
page.delete(invalid)

Expand Down
38 changes: 19 additions & 19 deletions heracles/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def __init__(self, out: io.IOBase = sys.stdout) -> None:
Args:
out: _description_
"""
self.out = out
self.time = 0
self.progress = 0
self.total = 0
self.title = None
self._out = out
self._time = 0
self._progress = 0
self._total = 0
self._title = None

def start(
self,
Expand All @@ -51,10 +51,10 @@ def start(
total: _description_
title: _description_
"""
self.time = time.monotonic()
self.progress = 0
self.total = total
self.title = title
self._time = time.monotonic()
self._progress = 0
self._total = total
self._title = title
self.update(0)

def update(self, step: int = 1) -> None:
Expand All @@ -63,22 +63,22 @@ def update(self, step: int = 1) -> None:
Args:
step: _description_
"""
self.progress = min(self.progress + step, self.total)
m = f"{self.title!s}: " if self.title is not None else ""
p = self.progress / self.total
self._progress = min(self._progress + step, self._total)
m = f"{self._title!s}: " if self._title is not None else ""
p = self._progress / self._total
b = "#" * int(20 * p)
f = f"{self.progress:_}/{self.total:_}"
t = timedelta(seconds=(time.monotonic() - self.time))
f = f"{self._progress:_}/{self._total:_}"
t = timedelta(seconds=(time.monotonic() - self._time))
s = f"\r{m}{100*p:3.0f}% |{b:20s}| {f} | {t}"
try:
w, _ = os.get_terminal_size(self.out.fileno())
w, _ = os.get_terminal_size(self._out.fileno())
except (OSError, AttributeError):
pass
else:
if w > 0:
s = s[:w]
self.out.write(s)
self.out.flush()
self._out.write(s)
self._out.flush()

def stop(self, complete: bool = True) -> None:
"""Stop progress and end line.
Expand All @@ -87,5 +87,5 @@ def stop(self, complete: bool = True) -> None:
complete: _description_
"""
if complete:
self.update(self.total - self.progress)
self.out.write("\n")
self.update(self._total - self._progress)
self._out.write("\n")
6 changes: 3 additions & 3 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
Expand Down

0 comments on commit acd3430

Please sign in to comment.