diff --git a/pyteomics/mgf.py b/pyteomics/mgf.py index 8746e7dd..811e43eb 100644 --- a/pyteomics/mgf.py +++ b/pyteomics/mgf.py @@ -609,7 +609,11 @@ def _pepmass_repr(k, pepmass): def _charge_repr(k, charge): - return '{}={}'.format(k.upper(), aux.Charge(charge) if isinstance(charge, int) else aux.ChargeList(charge)) + try: + val = aux.Charge(charge) + except (TypeError, aux.PyteomicsError): + val = aux.ChargeList(charge) + return '{}={}'.format(k.upper(), val) def _default_repr(key, val): diff --git a/pyteomics/version.py b/pyteomics/version.py index a3a43e45..2b310b6c 100644 --- a/pyteomics/version.py +++ b/pyteomics/version.py @@ -19,7 +19,7 @@ """ -__version__ = '4.6.2' +__version__ = '4.6.3a1' from collections import namedtuple import re diff --git a/tests/test_mgf.py b/tests/test_mgf.py index 7f4dd397..5d690fca 100644 --- a/tests/test_mgf.py +++ b/tests/test_mgf.py @@ -252,11 +252,13 @@ def test_charge_repr_single(self): self.assertEqual(mgf._charge_repr('charge', [2]), 'CHARGE=2+') self.assertEqual(mgf._charge_repr('charge', aux.Charge(2)), 'CHARGE=2+') self.assertEqual(mgf._charge_repr('charge', aux.ChargeList([2])), 'CHARGE=2+') + self.assertEqual(mgf._charge_repr('charge', np.int64(2)), 'CHARGE=2+') def test_charge_repr_multiple(self): self.assertEqual(mgf._charge_repr('charge', [2, 3]), 'CHARGE=2+ and 3+') self.assertEqual(mgf._charge_repr('charge', aux.ChargeList([2, 3])), 'CHARGE=2+ and 3+') self.assertEqual(mgf._charge_repr('charge', '2+, 3+'), 'CHARGE=2+ and 3+') + self.assertEqual(mgf._charge_repr('charge', np.array([2, 3])), 'CHARGE=2+ and 3+') if __name__ == "__main__":