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

importing pyenzyme fails under Python 3.13 (v2-migration branch) #72

Closed
jmrohwer opened this issue Mar 3, 2025 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@jmrohwer
Copy link
Member

jmrohwer commented Mar 3, 2025

When trying to import pyenzyme from a fresh install of the v2-migration branch, the import fails due to some error with functools. Under Python 3.12 everything works without error. The traceback follows:

[1]: import pyenzyme

/home/jr/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/units/units.py:52: FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in enum.member() if you want to preserve the old behavior
  k = partial(set_scale, scale=3.0)
/home/jr/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/units/units.py:53: FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in enum.member() if you want to preserve the old behavior
  m = partial(set_scale, scale=-3.0)
/home/jr/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/units/units.py:54: FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in enum.member() if you want to preserve the old behavior
  u = partial(set_scale, scale=-6.0)
/home/jr/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/units/units.py:55: FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in enum.member() if you want to preserve the old behavior
  n = partial(set_scale, scale=-9.0)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 1
----> 1 import pyenzyme

File ~/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/__init__.py:9
      6 from rich import print
      8 from .model import *  # noqa: F403
----> 9 from .sbml import to_sbml, read_sbml  # noqa: F401
     10 from .suite import EnzymeMLSuite  # noqa: F401
     11 from .tabular import to_pandas, read_csv, read_excel, from_dataframe  # noqa: F401

File ~/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/sbml/__init__.py:3
      1 from .omex import create_sbml_omex, read_sbml_omex
      2 from .parser import read_sbml
----> 3 from .serializer import to_sbml
      5 __all__ = [
      6     "to_sbml",
      7     "read_sbml",
      8     "create_sbml_omex",
      9     "read_sbml_omex",
     10 ]

File ~/.virtualenvs/fair-nmr/lib/python3.13/site-packages/pyenzyme/sbml/serializer.py:21
     19 from pyenzyme.tabular import to_pandas
     20 from pyenzyme.tools import to_dict_wo_json_ld
---> 21 from pyenzyme.units.units import UnitDefinition
     23 MAPPINGS = tools.read_static_file("pyenzyme.sbml", "mappings.toml")
     24 NSMAP = {"enzymeml": "https://www.enzymeml.org/v2"}

File ~/.virtualenvs/fair-nmr[/](http://localhost:8888/lab/tree/Data/Python/NMRPy/EnzymeML_datamodel/EnzymeMLxNMRpy.ipynb)lib/python3.13/site-packages/pyenzyme[/](http://localhost:8888/lab/tree/Data/Python/NMRPy/EnzymeML_datamodel/EnzymeMLxNMRpy.ipynb)units/__init__.py:1
----> 1 from .predefined import *  # noqa: F403

File ~[/](http://localhost:8888/lab/tree/Data/Python/NMRPy/EnzymeML_datamodel/EnzymeMLxNMRpy.ipynb).virtualenvs/fair-nmr/lib/python3.13[/](http://localhost:8888/lab/tree/Data/Python/NMRPy/EnzymeML_datamodel/EnzymeMLxNMRpy.ipynb)site-packages/pyenzyme/units/predefined.py:70
     68 # Molarity
     69 M = Unit.mol() / Unit.litre()
---> 70 mM = m * Unit.mol() / Unit.litre()
     71 uM = u * Unit.mol() / Unit.litre()
     72 nM = n * Unit.mol() / Unit.litre()

TypeError: unsupported operand type(s) for *: 'functools.partial' and 'BaseUnit'
@jmrohwer jmrohwer added the bug Something isn't working label Mar 3, 2025
@JR-1991
Copy link
Member

JR-1991 commented Mar 3, 2025

@jmrohwer thanks for raising awareness of this! The issue seems to be tied to a breaking change in functool.partial which does not allow closures outside non-context (@partial) environments. I have opened a PR to fix this:

@JR-1991
Copy link
Member

JR-1991 commented Mar 3, 2025

We are also switching to a less hacky implementation based on string variants, as implemented here. It's much more embedded and safer to use since astropy is supporting the unit extraction.

Example

data = MeasurementData(data_unit="mmol")
data.data_unit # Will be the fully compatible SBML unit definition

@JR-1991 JR-1991 closed this as completed Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants