From c62a9e410ec6ab4e8f36fd9220fa7b337eb74d96 Mon Sep 17 00:00:00 2001 From: jkeast Date: Wed, 6 Feb 2019 11:37:42 -0500 Subject: [PATCH 1/5] Add seaborn to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 25df434..95362fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ sphinx numpydoc flake8 pytest +seaborn \ No newline at end of file From 59033828f7ea41d45af160f3e1216a20f340d19d Mon Sep 17 00:00:00 2001 From: jkeast Date: Thu, 7 Feb 2019 16:52:19 -0500 Subject: [PATCH 2/5] Add flake8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a164f4..8185273 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - travis_retry pip install -e . script: -# - flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/` + - flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/` # - pytest --pyargs toymir --cov-report term-missing --cov=toymir - pytest From c3acdcd109e3bcb294757cea1870e8ae2fa718c7 Mon Sep 17 00:00:00 2001 From: jkeast Date: Fri, 8 Feb 2019 09:22:30 -0500 Subject: [PATCH 3/5] removed seaborn from freq.py --- toymir/freq.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toymir/freq.py b/toymir/freq.py index 311890f..aa4b4d5 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,5 +1,4 @@ import numpy as np -import seaborn # trap to make tests fail! def midi_to_hz(notes): @@ -38,12 +37,12 @@ def hz_to_midi(frequencies): # Oh hey, it's Part 5! You could uncomment this implementation, # and then the tests will pass! - # less_than_zero = (np.asanyarray(frequencies) <= 0).any() + less_than_zero = (np.asanyarray(frequencies) <= 0).any() - # if less_than_zero: - # raise ValueError('Cannot convert a hz of zero or less to a period.') + if less_than_zero: + raise ValueError('Cannot convert a hz of zero or less to a period.') - # return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69 + return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69 def hz_to_period(frequencies): From 8100b67ce83816549002d00e072c8db14fe8f757 Mon Sep 17 00:00:00 2001 From: jkeast Date: Fri, 8 Feb 2019 09:52:14 -0500 Subject: [PATCH 4/5] completed part 5 no.3 --- .travis.yml | 2 +- toymir/tests/test_toymir.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8185273..3b2dbe9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ install: script: - flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/` -# - pytest --pyargs toymir --cov-report term-missing --cov=toymir + - pytest --pyargs toymir --cov-report term-missing --cov=toymir - pytest # Hey, this block (and the above arguments to pytest ) diff --git a/toymir/tests/test_toymir.py b/toymir/tests/test_toymir.py index f1f72be..ca61f9b 100644 --- a/toymir/tests/test_toymir.py +++ b/toymir/tests/test_toymir.py @@ -18,14 +18,14 @@ def test_midi_to_hz_array(): # These are the two tests you should uncomment! -# def test_hz_to_midi_float(): -# expected = 69 -# assert toymir.hz_to_midi(440.0) == expected +def test_hz_to_midi_float(): + expected = 69 + assert toymir.hz_to_midi(440.0) == expected -# def test_hz_to_midi_array(): -# expected = [57, 69, 81] -# assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected) +def test_hz_to_midi_array(): + expected = [57, 69, 81] + assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected) # Hello! You could add the missing test for test_hz_to_midi here! From 25a6396008a21ec39bf19d967d42ce58cffd3a14 Mon Sep 17 00:00:00 2001 From: jkeast Date: Fri, 8 Feb 2019 15:55:01 -0500 Subject: [PATCH 5/5] Add docstring to midi_to_hz in freq.py --- toymir/freq.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/toymir/freq.py b/toymir/freq.py index aa4b4d5..5d5efaa 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -2,7 +2,29 @@ def midi_to_hz(notes): - """Hello Part 6! You should add documentation to this function. + """Get frequencies for given MIDI note numbers. + + Parameters + ---------- + notes : number or np.ndarray [shape=(n,), dtype=float] + MIDI notes to convert + + Returns + ------- + frequencies : float or np.ndarray [shape=(n,), dtype=float] + resultant frequencies + + Examples + -------- + >>> midi_to_hz(34.506) + 60 + + >>> midi_to_hz([ 45., 57., 69.]) + array([110, 220, 440]) + + See Also + -------- + hz_to_midi """ return 440.0 * (2.0 ** ((np.asanyarray(notes) - 69.0) / 12.0))