Skip to content

Commit

Permalink
MAINT: changes for test failures from python 3.9 update (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizgehret authored May 2, 2024
1 parent 7ce4378 commit 02e77df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion q2_feature_classifier/_skl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def num_leaf_nodes(self) -> int:
{'__type__': 'feature_extraction.text.HashingVectorizer',
'analyzer': 'char_wb',
'n_features': 8192,
'ngram_range': [7, 7],
'ngram_range': (7, 7),
'alternate_sign': False}],
['classify',
{'__type__': 'custom.LowMemoryMultinomialNB',
Expand Down
4 changes: 4 additions & 0 deletions q2_feature_classifier/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def default(self, obj):

def pipeline_from_spec(spec):
def as_steps(obj):
if 'ngram_range' in obj:
obj['ngram_range'] = tuple(obj['ngram_range'])
if '__type__' in obj:
klass = _load_class(obj['__type__'])
return klass(**{k: v for k, v in obj.items() if k != '__type__'})
Expand Down Expand Up @@ -332,6 +334,8 @@ def generic_fitter(reference_reads: DNAIterator,
kwargs[param] = json.loads(kwargs[param])
except (json.JSONDecodeError, TypeError):
pass
if param == 'feat_ext__ngram_range':
kwargs[param] = tuple(kwargs[param])
pipeline = pipeline_from_spec(spec)
pipeline.set_params(**kwargs)
if class_weight is not None:
Expand Down
4 changes: 2 additions & 2 deletions q2_feature_classifier/tests/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_populate_class_weight(self):
{'__type__': 'feature_extraction.text.HashingVectorizer',
'analyzer': 'char_wb',
'n_features': 8192,
'ngram_range': [8, 8],
'ngram_range': (8, 8),
'alternate_sign': False}],
['classify',
{'__type__': 'naive_bayes.GaussianNB'}]]
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_class_weight(self):
{'__type__': 'feature_extraction.text.HashingVectorizer',
'analyzer': 'char_wb',
'n_features': 8192,
'ngram_range': [8, 8],
'ngram_range': (8, 8),
'alternate_sign': False}],
['classify',
{'__type__': 'linear_model.LogisticRegression'}]]
Expand Down
4 changes: 2 additions & 2 deletions q2_feature_classifier/tests/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_low_memory_multinomial_nb(self):
{'__type__': 'feature_extraction.text.HashingVectorizer',
'analyzer': 'char',
'n_features': 8192,
'ngram_range': [8, 8],
'ngram_range': (8, 8),
'alternate_sign': False}],
['classify',
{'__type__': 'custom.LowMemoryMultinomialNB',
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_chunked_hashing_vectorizer(self):

params = {'analyzer': 'char',
'n_features': 8192,
'ngram_range': [8, 8],
'ngram_range': (8, 8),
'alternate_sign': False}
hv = HashingVectorizer(**params)
unchunked = hv.fit_transform(X)
Expand Down

0 comments on commit 02e77df

Please sign in to comment.