From 84ace4b9fd9a75425d16d7148380f8b9106823e2 Mon Sep 17 00:00:00 2001 From: Brian McFee Date: Thu, 12 Oct 2017 11:10:57 -0400 Subject: [PATCH 1/2] added repr_html and str to pump --- pumpp/core.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pumpp/core.py b/pumpp/core.py index 0db13b0..227cb81 100644 --- a/pumpp/core.py +++ b/pumpp/core.py @@ -11,6 +11,7 @@ import librosa import jams +import six from .base import Slicer from .exceptions import ParameterError @@ -225,3 +226,28 @@ def __getitem__(self, key): def __call__(self, *args, **kwargs): return self.transform(*args, **kwargs) + + def __str__(self): + rstr = ''.format(len(self.ops), + len(self.fields)) + for key in self.opmap: + rstr += "\n - '{}': {}".format(key, type(self.opmap[key])) + for field in self.opmap[key].fields: + rstr += "\n - '{}': {}".format(field, self.opmap[key].fields[field]) + return rstr + + def _repr_html_(self): + + rstr = '
' + for key in self.opmap: + rstr += '\n
{:s}
'.format(key) + rstr += '\n
{}'.format(self.opmap[key]) + + rstr += '
    ' + for fkey, field in six.iteritems(self.opmap[key].fields): + rstr += '\n
  • {:s} [shape={}, dtype={}]
  • '.format(fkey, + field.shape, + field.dtype.__name__) + rstr += '
' + rstr += '
' + return rstr From 02c5e44612e181334828d164d5e4c468551a4e90 Mon Sep 17 00:00:00 2001 From: Brian McFee Date: Thu, 12 Oct 2017 11:12:20 -0400 Subject: [PATCH 2/2] added tests for repr html --- tests/test_core.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_core.py b/tests/test_core.py index b728699..ae5b1fc 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -212,3 +212,45 @@ def test_pump_layers(sr, hop_length): assert L1[k].dtype == L2[k].dtype for d1, d2 in zip(L1[k].shape, L2[k].shape): assert str(d1) == str(d2) + + +def test_pump_str(sr, hop_length): + + ops = [pumpp.feature.STFT(name='stft', sr=sr, + hop_length=hop_length, + n_fft=2*hop_length), + + pumpp.task.BeatTransformer(name='beat', sr=sr, + hop_length=hop_length), + + pumpp.task.ChordTransformer(name='chord', sr=sr, + hop_length=hop_length), + + pumpp.task.StaticLabelTransformer(name='tags', + namespace='tag_open', + labels=['rock', 'jazz'])] + + pump = pumpp.Pump(*ops) + + assert isinstance(str(pump), str) + + +def test_pump_repr_html(sr, hop_length): + + ops = [pumpp.feature.STFT(name='stft', sr=sr, + hop_length=hop_length, + n_fft=2*hop_length), + + pumpp.task.BeatTransformer(name='beat', sr=sr, + hop_length=hop_length), + + pumpp.task.ChordTransformer(name='chord', sr=sr, + hop_length=hop_length), + + pumpp.task.StaticLabelTransformer(name='tags', + namespace='tag_open', + labels=['rock', 'jazz'])] + + pump = pumpp.Pump(*ops) + + assert isinstance(pump._repr_html_(), str)