saezlab / pypath

Python module for prior knowledge integration. Builds databases of signaling pathways, enzyme-substrate interactions, complexes, annotations and intercellular communication roles.
http://omnipathdb.org/
GNU General Public License v3.0
134 stars 47 forks source link

pypath logging results in AttributeError during ramp db calls #296

Closed maca8e closed 2 weeks ago

maca8e commented 3 weeks ago

Describe the bug Attribute error hit when attempting to load ramp tables. Issue appears to be from the pypath logging functions.

To Reproduce Steps to reproduce the behavior:

from pypath.inputs import ramp
ramp.ramp_list_tables()
tables = ramp.ramp_raw(['entity_status_info', 'chem_props', 'metabolite_class', 'ontology'])
### ^^^ Error:
### AttributeError: 'function' object has no attribute 'msg'
con = ramp.ramp_raw(['entity_status_info', 'chem_props', 'metabolite_class', 'ontology'], sqlite=True)
### ^^^ Error:
### AttributeError: 'function' object has no attribute 'msg'

Tried using both poetry and conda/pip environments.

Expected behavior

Loading the tables (or making the sql connection) without the logging error.

Traceback If you have a traceback please quote it in your report.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 tables = ramp.ramp_raw(['entity_status_info', 'chem_props', 'metabolite_class', 'ontology'])
      2 tables
File ~/xyz/pypath/pypath/inputs/ramp.py:83, in ramp_raw(tables, sqlite, **kwargs)
     63 """
     64 Retrieve RaMP database contents from raw SQL dump.
     65 
   (...)
     78     as values, or an SQLite database connection.
     79 """
     81 fp = _ramp_sqldump()
---> 83 return sqldump.tables(
     84     sqldump = fp,
     85     tables = tables,
     86     return_df = True,
     87     return_sqlite = sqlite,
     88     con_param = kwargs,
     89     source_id = (fp.name, f'{os.path.getmtime(fp.name):.0f}'),
     90 )
File ~/xyz/pypath/pypath/formats/sqldump.py:79, in tables(sqldump, tables, return_df, return_sqlite, con_param, source_id, **kwargs)
     44 def tables(
     45         sqldump: str | IO,
     46         tables: str | Iterable[str] | None,
   (...)
     51         **kwargs
     52     ) -> tuple[dict, dict] | dict[str, pd.DataFrame] | sqlite3.Connection:
     53     """
     54     From a SQL dump, retrieve tables as data frames or as lists of tuples.
     55 
   (...)
     76         Contents of the table.
     77     """
---> 79     common.log_memory_usage()
     80     source_id = get_source_id(sqldump, source_id)
     81     sqldump = open_sqldump(sqldump, **kwargs)
File ~/Library/Caches/pypoetry/virtualenvs/pypath-omnipath-PHbY_0fz-py3.11/lib/python3.11/site-packages/pypath_common/_misc.py:1924, in log_memory_usage()
   1919 """
   1920 Logs the memory usage of the current process.
   1921 """
   1923 import pypath
-> 1924 pypath.session.log.msg(
   1925     f'Python memory use: {format_bytes(python_memory_usage())}',
   1926 )
AttributeError: 'function' object has no attribute 'msg'

Log file

[2024-11-05 13:40:45] Welcome!
[2024-11-05 13:40:45] Logger started, logging into `/xyz/pypath/pypath_log/pypath-jezdk.log`.
[2024-11-05 13:40:45] Session `jezdk` started.
[2024-11-05 13:40:45] Config has been read from the following files:
[2024-11-05 13:40:45]   - [/user_library_abc/Caches/pypoetry/virtualenvs/pypath-omnipath-PHbY_0fz-py3.11/lib/python3.11/site-packages/pypath_common/data/settings.yaml](https://file+.vscode-resource.vscode-cdn.net/Users/agjanyunlu/Library/Caches/pypoetry/virtualenvs/pypath-omnipath-PHbY_0fz-py3.11/lib/python3.11/site-packages/pypath_common/data/settings.yaml)
[2024-11-05 13:40:45] [pypath] 
    - session ID: `jezdk`
    - working directory: `/xyz/pypath`
    - logfile: `/xyz/pypath/pypath_log/pypath-jezdk.log`
    - config: 
        - [/user_library_abc/Caches/pypoetry/virtualenvs/pypath-omnipath-PHbY_0fz-py3.11/lib/python3.11/site-packages/pypath_common/data/settings.yaml](https://file+.vscode-resource.vscode-cdn.net/Users/agjanyunlu/Library/Caches/pypoetry/virtualenvs/pypath-omnipath-PHbY_0fz-py3.11/lib/python3.11/site-packages/pypath_common/data/settings.yaml)
    - pypath version: 0.16.16
    - imported from: `/xyz/pypath/pypath`
    - Python version: 3.11.7 (main, Dec 15 2023, 12:09:56) [Clang 14.0.6 ]
    - Platform: macOS-14.5-arm64-arm-64bit
[2024-11-05 13:40:45] [pypath] pypath
[2024-11-05 13:40:46] [curl] Creating Curl object to retrieve data from `[https://figshare.com/ndownloader/files/38534654`](https://figshare.com/ndownloader/files/38534654%60)
[2024-11-05 13:40:46] [curl] Cache file path: `/user_library_abc/Caches/pypath/2ac9fe4b32649e946c59f28f74943748-38534654`
[2024-11-05 13:40:46] [curl] Cache file found, no need for download.
[2024-11-05 13:40:46] [curl] Loading data from cache previously downloaded from `figshare.com`
[2024-11-05 13:40:46] [curl] Opening file `/user_library_abc/Caches/pypath/2ac9fe4b32649e946c59f28f74943748-38534654`
[2024-11-05 13:40:46] [curl] Extracting data from file type `gz`
[2024-11-05 13:40:46] [curl] Opening gzip file `/user_library_abc/Caches/pypath/2ac9fe4b32649e946c59f28f74943748-38534654`.
[2024-11-05 13:40:46] [curl] Result is an iterator over the lines of `/user_library_abc/Caches/pypath/2ac9fe4b32649e946c59f28f74943748-38534654`.
[2024-11-05 13:40:46] [curl] File at `[https://figshare.com/ndownloader/files/38534654`](https://figshare.com/ndownloader/files/38534654%60) successfully retrieved. Resulted file type `gz extracted data, file object`. Local file at
                      `/user_library_abc/Caches/pypath/2ac9fe4b32649e946c59f28f74943748-38534654`.

Desktop (please complete the following information):

Additional context

deeenes commented 3 weeks ago

Hello @maca8e , You were the one who fixed this bug in July :)

maca8e commented 2 weeks ago

Ahhh, it did feel a bit deja vu like 🤦 works with latest update, thanks.

Speaking of which, the github currently lists v0.16.5 as latest, but pypi has up to v0.16.17, and the log file has 0.1. Maybe to minimise confusion the repo release could be updated soon?