Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update numpy dependency #352

Closed
Nilsonfsilva opened this issue Jan 17, 2023 · 7 comments · Fixed by #370
Closed

update numpy dependency #352

Nilsonfsilva opened this issue Jan 17, 2023 · 7 comments · Fixed by #370
Milestone

Comments

@Nilsonfsilva
Copy link

Nilsonfsilva commented Jan 17, 2023

Hello!
As you know, your project is on Debian.

Recently, one of your code's dependencies was updated, in this case "numpy".

As debian is constantly updating its packages, mir-herval also needed to make some changes to some parts of its code in order to keep it building normally.

This issue is described in this article:
https://levelup.gitconnected.com/fix-attributeerror-module-numpy-has-no-attribute-float-d7d68c5a4971

Below is part of the code that needed updates:

Index: mir-eval/mir_eval/segment.py
===================================================================
--- mir-eval.orig/mir_eval/segment.py
+++ mir-eval/mir_eval/segment.py
@@ -540,7 +540,7 @@ def _contingency_matrix(reference_indice
     return scipy.sparse.coo_matrix((np.ones(ref_class_idx.shape[0]),
                                     (ref_class_idx, est_class_idx)),
                                    shape=(n_ref_classes, n_est_classes),
-                                   dtype=np.int).toarray()
+                                   dtype=int).toarray()
 
 
 def _adjusted_rand_index(reference_indices, estimated_indices):
@@ -720,7 +720,7 @@ def _entropy(labels):
     if len(labels) == 0:
         return 1.0
     label_idx = np.unique(labels, return_inverse=True)[1]
-    pi = np.bincount(label_idx).astype(np.float)
+    pi = np.bincount(label_idx).astype(float)
     pi = pi[pi > 0]
     pi_sum = np.sum(pi)
     # log(a / b) should be calculated as log(a) - log(b) for

Index: mir-eval/mir_eval/chord.py
===================================================================
--- mir-eval.orig/mir_eval/chord.py
+++ mir-eval/mir_eval/chord.py
@@ -510,7 +510,7 @@ def encode(chord_label, reduce_extended_
         semitone_bitmap += scale_degree_to_bitmap(scale_degree,
                                                   reduce_extended_chords)
 
-    semitone_bitmap = (semitone_bitmap > 0).astype(np.int)
+    semitone_bitmap = (semitone_bitmap > 0).astype(int)
     if not semitone_bitmap[bass_number] and strict_bass_intervals:
         raise InvalidChordException(
             "Given bass scale degree is absent from this chord: "
@@ -544,8 +544,8 @@ def encode_many(chord_labels, reduce_ext
 
     """
     num_items = len(chord_labels)
-    roots, basses = np.zeros([2, num_items], dtype=np.int)
-    semitones = np.zeros([num_items, 12], dtype=np.int)
+    roots, basses = np.zeros([2, num_items], dtype=int)
+    semitones = np.zeros([num_items, 12], dtype=int)
     local_cache = dict()
     for i, label in enumerate(chord_labels):
         result = local_cache.get(label, None)
@@ -749,7 +749,7 @@ def thirds(reference_labels, estimated_l
 
     eq_roots = ref_roots == est_roots
     eq_thirds = ref_semitones[:, 3] == est_semitones[:, 3]
-    comparison_scores = (eq_roots * eq_thirds).astype(np.float)
+    comparison_scores = (eq_roots * eq_thirds).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -797,7 +797,7 @@ def thirds_inv(reference_labels, estimat
     eq_root = ref_roots == est_roots
     eq_bass = ref_bass == est_bass
     eq_third = ref_semitones[:, 3] == est_semitones[:, 3]
-    comparison_scores = (eq_root * eq_third * eq_bass).astype(np.float)
+    comparison_scores = (eq_root * eq_third * eq_bass).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -845,7 +845,7 @@ def triads(reference_labels, estimated_l
     eq_roots = ref_roots == est_roots
     eq_semitones = np.all(
         np.equal(ref_semitones[:, :8], est_semitones[:, :8]), axis=1)
-    comparison_scores = (eq_roots * eq_semitones).astype(np.float)
+    comparison_scores = (eq_roots * eq_semitones).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -894,7 +894,7 @@ def triads_inv(reference_labels, estimat
     eq_basses = ref_bass == est_bass
     eq_semitones = np.all(
         np.equal(ref_semitones[:, :8], est_semitones[:, :8]), axis=1)
-    comparison_scores = (eq_roots * eq_semitones * eq_basses).astype(np.float)
+    comparison_scores = (eq_roots * eq_semitones * eq_basses).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -941,7 +941,7 @@ def tetrads(reference_labels, estimated_
 
     eq_roots = ref_roots == est_roots
     eq_semitones = np.all(np.equal(ref_semitones, est_semitones), axis=1)
-    comparison_scores = (eq_roots * eq_semitones).astype(np.float)
+    comparison_scores = (eq_roots * eq_semitones).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -989,7 +989,7 @@ def tetrads_inv(reference_labels, estima
     eq_roots = ref_roots == est_roots
     eq_basses = ref_bass == est_bass
     eq_semitones = np.all(np.equal(ref_semitones, est_semitones), axis=1)
-    comparison_scores = (eq_roots * eq_semitones * eq_basses).astype(np.float)
+    comparison_scores = (eq_roots * eq_semitones * eq_basses).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -1035,7 +1035,7 @@ def root(reference_labels, estimated_lab
     validate(reference_labels, estimated_labels)
     ref_roots, ref_semitones = encode_many(reference_labels, False)[:2]
     est_roots = encode_many(estimated_labels, False)[0]
-    comparison_scores = (ref_roots == est_roots).astype(np.float)
+    comparison_scores = (ref_roots == est_roots).astype(float)
 
     # Ignore 'X' chords
     comparison_scores[np.any(ref_semitones < 0, axis=1)] = -1.0
@@ -1087,7 +1087,7 @@ def mirex(reference_labels, estimated_la
     eq_chroma = (ref_chroma * est_chroma).sum(axis=-1)
 
     # Chroma matching for set bits
-    comparison_scores = (eq_chroma >= min_intersection).astype(np.float)
+    comparison_scores = (eq_chroma >= min_intersection).astype(float)
 
     # No-chord matching; match -1 roots, SKIP_CHORDS dropped next
     no_root = np.logical_and(ref_data[0] == -1, est_data[0] == -1)
@@ -1150,7 +1150,7 @@ def majmin(reference_labels, estimated_l
     eq_root = ref_roots == est_roots
     eq_quality = np.all(np.equal(ref_semitones[:, :8],
                                  est_semitones[:, :8]), axis=1)
-    comparison_scores = (eq_root * eq_quality).astype(np.float)
+    comparison_scores = (eq_root * eq_quality).astype(float)
 
     # Test for Major / Minor / No-chord
     is_maj = np.all(np.equal(ref_semitones[:, :8], maj_semitones), axis=1)
@@ -1217,7 +1217,7 @@ def majmin_inv(reference_labels, estimat
     eq_root_bass = (ref_roots == est_roots) * (ref_bass == est_bass)
     eq_semitones = np.all(np.equal(ref_semitones[:, :8],
                                    est_semitones[:, :8]), axis=1)
-    comparison_scores = (eq_root_bass * eq_semitones).astype(np.float)
+    comparison_scores = (eq_root_bass * eq_semitones).astype(float)
 
     # Test for Major / Minor / No-chord
     is_maj = np.all(np.equal(ref_semitones[:, :8], maj_semitones), axis=1)
@@ -1280,7 +1280,7 @@ def sevenths(reference_labels, estimated
 
     eq_root = ref_roots == est_roots
     eq_semitones = np.all(np.equal(ref_semitones, est_semitones), axis=1)
-    comparison_scores = (eq_root * eq_semitones).astype(np.float)
+    comparison_scores = (eq_root * eq_semitones).astype(float)
 
     # Test for reference chord inclusion
     is_valid = np.array([np.all(np.equal(ref_semitones, semitones), axis=1)
@@ -1335,7 +1335,7 @@ def sevenths_inv(reference_labels, estim
 
     eq_roots_basses = (ref_roots == est_roots) * (ref_basses == est_basses)
     eq_semitones = np.all(np.equal(ref_semitones, est_semitones), axis=1)
-    comparison_scores = (eq_roots_basses * eq_semitones).astype(np.float)
+    comparison_scores = (eq_roots_basses * eq_semitones).astype(float)
 
     # Test for Major / Minor / No-chord
     is_valid = np.array([np.all(np.equal(ref_semitones, semitones), axis=1)

Index: mir-eval/tests/test_beat.py
===================================================================
--- mir-eval.orig/tests/test_beat.py
+++ mir-eval/tests/test_beat.py
@@ -19,9 +19,9 @@ SCORES_GLOB = 'data/beat/output*.json'
 
 def test_trim_beats():
     # Construct dummy beat times [0., 1., ...]
-    dummy_beats = np.arange(10, dtype=np.float)
+    dummy_beats = np.arange(10, dtype=float)
     # We expect trim_beats to remove all beats < 5s
-    expected_beats = np.arange(5, 10, dtype=np.float)
+    expected_beats = np.arange(5, 10, dtype=float)
     assert np.allclose(mir_eval.beat.trim_beats(dummy_beats), expected_beats)
 
 
@@ -51,7 +51,7 @@ def __unit_test_beat_function(metric):
     nose.tools.assert_raises(ValueError, metric, beats, beats)
 
     # Valid beats which are the same produce a score of 1 for all metrics
-    beats = np.arange(10, dtype=np.float)
+    beats = np.arange(10, dtype=float)
     assert np.allclose(metric(beats, beats), 1)
 
 
Index: mir-eval/tests/test_onset.py
===================================================================
--- mir-eval.orig/tests/test_onset.py
+++ mir-eval/tests/test_onset.py
@@ -43,7 +43,7 @@ def __unit_test_onset_function(metric):
     nose.tools.assert_raises(ValueError, metric, onsets, onsets)
 
     # Valid onsets which are the same produce a score of 1 for all metrics
-    onsets = np.arange(10, dtype=np.float)
+    onsets = np.arange(10, dtype=float)
     assert np.allclose(metric(onsets, onsets), 1)
 
 
Index: mir-eval/mir_eval/beat.py
===================================================================
--- mir-eval.orig/mir_eval/beat.py
+++ mir-eval/mir_eval/beat.py
@@ -386,14 +386,14 @@ def p_score(reference_beats,
     estimated_beats = np.array(estimated_beats - offset)
     reference_beats = np.array(reference_beats - offset)
     # Get the largest time index
-    end_point = np.int(np.ceil(np.max([np.max(estimated_beats),
+    end_point = int(np.ceil(np.max([np.max(estimated_beats),
                                        np.max(reference_beats)])))
     # Make impulse trains with impulses at beat locations
     reference_train = np.zeros(end_point*sampling_rate + 1)
-    beat_indices = np.ceil(reference_beats*sampling_rate).astype(np.int)
+    beat_indices = np.ceil(reference_beats*sampling_rate).astype(int)
     reference_train[beat_indices] = 1.0
     estimated_train = np.zeros(end_point*sampling_rate + 1)
-    beat_indices = np.ceil(estimated_beats*sampling_rate).astype(np.int)
+    beat_indices = np.ceil(estimated_beats*sampling_rate).astype(int)
     estimated_train[beat_indices] = 1.0
     # Window size to take the correlation over
     # defined as .2*median(inter-annotation-intervals)
@bmcfee
Copy link
Collaborator

bmcfee commented Jan 17, 2023

👍 to this - should be an easy update if anyone wants to prep a PR?

@craffel
Copy link
Collaborator

craffel commented Jan 17, 2023

+1, PRs welcome!

@carlthome
Copy link
Contributor

Think this is resolved now (but might be wrong).

@carlthome
Copy link
Contributor

Related #366

@bmcfee bmcfee added this to the 0.8 milestone Mar 13, 2024
@bmcfee bmcfee mentioned this issue Mar 21, 2024
4 tasks
@Nilsonfsilva
Copy link
Author

Nilsonfsilva commented Mar 25, 2024 via email

@bmcfee
Copy link
Collaborator

bmcfee commented Mar 25, 2024

@Nilsonfsilva There's a milestone set up for the next release, and I'm working on it.

@Nilsonfsilva
Copy link
Author

Nilsonfsilva commented Mar 25, 2024 via email

guillaumekh added a commit to guillaumekh/jams that referenced this issue Jul 4, 2024
note:
- [email protected] dropped support for Python <= 3.8
- [email protected]+ broke mir_eval. A fix was merged in mir_eval@main but has not been released yet
	- see: mir-evaluation/mir_eval#352
- [email protected] brakes mir_eval
	- see: mir-evaluation/mir_eval#383
- i updated pytest hoping it would help solve failing tests but that's a HUGE v3—>v8 jump. I only made the bare minimum of fixes to accomodate this upgrade, and I would expect more work is needed
- i wanted to add python 11/12 support but delayed this until we can already get tests runnning properly on 3.9/3.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants