From 676d0cd9832d9f26ea8eb6bdf19786e35f794004 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 12:00:33 -0400 Subject: [PATCH 01/17] Add seaborn to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 25df434..71c333d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ sphinx numpydoc flake8 pytest +seaborn From 1fd5b8cd499783a702f98585e3def7d1bab36285 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 15:31:23 -0400 Subject: [PATCH 02/17] Changed second import in toymir/__init__.py to from . import freq --- toymir/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toymir/__init__.py b/toymir/__init__.py index ad625cc..968be93 100644 --- a/toymir/__init__.py +++ b/toymir/__init__.py @@ -2,4 +2,4 @@ # When you import from .MODULE, that means look within the current package # instead of going out to the installed packages from .version import __version__ # noqa -from .freq import * # noqa +from . import freq # noqa From 53eeb6b4506455ebdc55142005c1a5b662d99cc5 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 15:52:18 -0400 Subject: [PATCH 03/17] Uncommented two functions that start with test_hz_to_midi --- toymir/tests/test_toymir.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/toymir/tests/test_toymir.py b/toymir/tests/test_toymir.py index f1f72be..6e94bd3 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 c6856d0f09d54db749bee539e57c7b463463a8bd Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 16:01:35 -0400 Subject: [PATCH 04/17] Uncommented code --- toymir/freq.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toymir/freq.py b/toymir/freq.py index 311890f..e5941c3 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -38,12 +38,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 2701bff9f8354841f43675d32d596674ac44e02e Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 16:16:11 -0400 Subject: [PATCH 05/17] Indented line that throws an exception --- toymir/freq.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toymir/freq.py b/toymir/freq.py index e5941c3..32993ed 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -41,7 +41,8 @@ def hz_to_midi(frequencies): 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.') + + 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 @@ -74,6 +75,7 @@ def hz_to_period(frequencies): 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.') return 1 / np.asanyarray(frequencies) From 3f7d7a4c3e0563d09a35f85c7c12168514916367 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 16:18:52 -0400 Subject: [PATCH 06/17] Unindented a line that was uncommented --- toymir/tests/test_toymir.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/toymir/tests/test_toymir.py b/toymir/tests/test_toymir.py index 6e94bd3..ca61f9b 100644 --- a/toymir/tests/test_toymir.py +++ b/toymir/tests/test_toymir.py @@ -18,13 +18,13 @@ 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] +def test_hz_to_midi_array(): + expected = [57, 69, 81] assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected) From f856e74b8a6ad119cea901ae9842a239b082c5eb Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 17:00:08 -0400 Subject: [PATCH 07/17] Changed second import back to from .freq import * --- toymir/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toymir/__init__.py b/toymir/__init__.py index 968be93..4922376 100644 --- a/toymir/__init__.py +++ b/toymir/__init__.py @@ -2,4 +2,4 @@ # When you import from .MODULE, that means look within the current package # instead of going out to the installed packages from .version import __version__ # noqa -from . import freq # noqa +from .freq import * # noqa From 2cb85fedc5e919c2abb0de9b0d41b60c8e6b80e5 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 17:02:39 -0400 Subject: [PATCH 08/17] Uncommented --- toymir/freq.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/toymir/freq.py b/toymir/freq.py index 32993ed..bd9ca27 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -41,7 +41,6 @@ def hz_to_midi(frequencies): 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.') return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69 @@ -75,7 +74,6 @@ def hz_to_period(frequencies): 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.') return 1 / np.asanyarray(frequencies) From 9becfb9f05055f37b89119cd9cc977d7523b6529 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 17:04:46 -0400 Subject: [PATCH 09/17] Uncommented --- toymir/tests/test_toymir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toymir/tests/test_toymir.py b/toymir/tests/test_toymir.py index ca61f9b..321835a 100644 --- a/toymir/tests/test_toymir.py +++ b/toymir/tests/test_toymir.py @@ -28,7 +28,7 @@ def test_hz_to_midi_array(): 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! +# Hello! You could add the missing test for test_hz_to_midi here! def test_hz_to_period_float(): From 4f5331252789f6b21287543007921b1bc16513f4 Mon Sep 17 00:00:00 2001 From: Lizette Date: Tue, 28 May 2019 17:19:30 -0400 Subject: [PATCH 10/17] Uncommented the flake8 line above the call to pytest --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a164f4..3358f49 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 0dd34e1b931c37b0f7f1d8b61de5af7e4423b0b1 Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 09:17:52 -0400 Subject: [PATCH 11/17] Deleted the unused import, seaborn --- toymir/freq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toymir/freq.py b/toymir/freq.py index bd9ca27..5ff7b1a 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,5 +1,5 @@ import numpy as np -import seaborn # trap to make tests fail! +#import seaborn trap to make tests fail! def midi_to_hz(notes): From e11ebfd119442f7a6826339b64a2ee1cc5352ea2 Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 09:28:54 -0400 Subject: [PATCH 12/17] Trying to see if Travis works --- toymir/freq.py | 1 + 1 file changed, 1 insertion(+) diff --git a/toymir/freq.py b/toymir/freq.py index 5ff7b1a..8e717bf 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,5 +1,6 @@ import numpy as np #import seaborn trap to make tests fail! +#this line indicates a change that needs to take place to make another push def midi_to_hz(notes): From cec02fbb9c799fb75201195f86cf853c363b4c05 Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 09:55:25 -0400 Subject: [PATCH 13/17] Uncommented two lines of code --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3358f49..41350dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ 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 +- pytest --pyargs toymir --cov-report term-missing --cov=toymir +- pytest # Hey, this block (and the above arguments to pytest ) # are important if you care about test coverage. From e978e48afad1c577fcb23dfe0da88634b84f2419 Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 09:58:37 -0400 Subject: [PATCH 14/17] Commented unused import, seaborn --- toymir/freq.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/toymir/freq.py b/toymir/freq.py index 8e717bf..2c89199 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,7 +1,5 @@ import numpy as np -#import seaborn trap to make tests fail! -#this line indicates a change that needs to take place to make another push - +#import seaborn #trap to make tests fail! def midi_to_hz(notes): """Hello Part 6! You should add documentation to this function. From a5dfaa91961efe9d07c7b609f0ebfcb99d354344 Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 10:02:32 -0400 Subject: [PATCH 15/17] Commented out a line in travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 41350dc..0d56779 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 ) From fb570dfc2b8fbf24a0d994ac97a20b448e081cae Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 10:21:08 -0400 Subject: [PATCH 16/17] Corrected the errors --- toymir/freq.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toymir/freq.py b/toymir/freq.py index 2c89199..67995ae 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -1,5 +1,6 @@ import numpy as np -#import seaborn #trap to make tests fail! +# import seaborn trap to make tests fail! + def midi_to_hz(notes): """Hello Part 6! You should add documentation to this function. From 7c8a1ab60b2cc666de6ffb50f44d1fd0a344951a Mon Sep 17 00:00:00 2001 From: Lizette Date: Wed, 29 May 2019 11:17:27 -0400 Subject: [PATCH 17/17] Addded documentation to midi_to_hz function --- toymir/freq.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/toymir/freq.py b/toymir/freq.py index 67995ae..338076f 100644 --- a/toymir/freq.py +++ b/toymir/freq.py @@ -3,7 +3,23 @@ def midi_to_hz(notes): - """Hello Part 6! You should add documentation to this function. + """Get frequencies (Hz) of MIDI + + Parameters + ---------- + notes : number or np.ndarray [shape=(n,), dtype=float] + note numbers to convert + + Returns + ------- + + frequences : float or np.ndarray [shape=(n,), dtype=float] + frequences to convert + + Examples + -------- + >>> midi_to_hz(120) + 8372.01 """ return 440.0 * (2.0 ** ((np.asanyarray(notes) - 69.0) / 12.0))