Skip to content

Commit

Permalink
AttributeError for Spool.viz
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadtourei committed Aug 21, 2024
1 parent 7157521 commit 1589621
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dascore/core/spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
get_dim_names_from_columns,
split_df_query,
)
from dascore.viz import VizSpoolNameSpace

T = TypeVar("T")

Expand Down Expand Up @@ -327,6 +328,11 @@ def map(
# Add method for stacking (adding the data arrays) patches in spool.
stack = stack_patches

@property
def viz(self) -> VizSpoolNameSpace:
"""The visualization namespace."""
return VizSpoolNameSpace(self)


class DataFrameSpool(BaseSpool):
"""An abstract class for spools whose contents are managed by a dataframe."""
Expand Down
26 changes: 26 additions & 0 deletions dascore/utils/spool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Utilities for working with the Patch class."""

from __future__ import annotations

import functools

from dascore.constants import SpoolType


def spool_function():
"""
Decorator to mark a function as a spool method.
"""

def _wrapper(func):
@functools.wraps(func)
def _func(spool, *args, **kwargs):
out: SpoolType = func(spool, *args, **kwargs)
return out

_func.func = func # attach original function
_func.__wrapped__ = func

return _func

return _wrapper
8 changes: 8 additions & 0 deletions dascore/viz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ class VizPatchNameSpace(MethodNameSpace):
spectrogram = spectrogram
wiggle = wiggle
map_fiber = map_fiber

class VizSpoolNameSpace(MethodNameSpace):
"""A class for storing visualization namespace."""

waterfall = waterfall
spectrogram = spectrogram
wiggle = wiggle
map_fiber = map_fiber
20 changes: 20 additions & 0 deletions dascore/viz/waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ def waterfall(
if show:
plt.show()
return ax


# @spool_function()
# def waterfall(
# spool: SpoolType,
# ax: plt.Axes | None = None,
# cmap="bwr",
# scale: float | Sequence[float] | None = None,
# scale_type: Literal["relative", "absolute"] = "relative",
# log=False,
# show=False,
# ) -> plt.Axes:
# """Raise an AttributeError for Spool.viz.waterfall()."""
# msg = (
# "'Spool' object has no attribute 'viz'. "
# "Apply 'viz.waterfall()' on a Patch object."
# "(you can select a subset of the spool and merge it "
# "into a single patch using the Chunk function.)"
# )
# raise AttributeError(msg)
8 changes: 7 additions & 1 deletion tests/test_core/test_spool.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ def test_empty_spool_str(self):
assert "Spool" in spool_str

def test_base_concat_raises(self, random_spool):
"""Ensure baseSpool.concatenate raises NotImplementedError."""
"""Ensure BaseSpool.concatenate raises NotImplementedError."""
msg = "has no concatenate implementation"
with pytest.raises(NotImplementedError, match=msg):
BaseSpool.concatenate(random_spool, time=2)

def test_viz_raises_waterfall(self, random_spool):
"""Ensure BaseSpool.viz.waterfall raises AttributeError."""
msg = "has no attribute 'viz'. Apply 'viz.waterfall()' on a Patch"
with pytest.raises(AttributeError, match=msg):
BaseSpool.viz.waterfall(random_spool)


class TestSpoolEquals:
"""Tests for spool equality."""
Expand Down

0 comments on commit 1589621

Please sign in to comment.