pharmpy / pharmpy

A library and toolkit for pharmacometrics
https://pharmpy.github.io
GNU General Public License v3.0
48 stars 14 forks source link

convert to rxode model #3273

Open rosemarychen99 opened 1 month ago

rosemarychen99 commented 1 month ago

Bug report

version: 1.2.0 and 1.1.0

happened when there is a RATE column. (from UPSS demo, apparently it worked before)

rxode_model <- convert_model(run2, "rxode") Error in py_call_impl(callable, call_args$unnamed, call_args$named) : KeyError: 'RATE' Run reticulate::py_last_error() for details. 9. stop() 8. get_loc at base.py#3812 7. getitem at frame.py#4102 6. same_time at sanity_checks.py#168 5. check_model at sanity_checks.py#49 4. convert_model at model.py#104 3. convert_model at common.py#176 2. pharmpy$modeling$convert_model(model, to_format) 1. convert_model(run2, "rxode")

reticulate::py_last_error()

── Python Exception Message ────────────────────────────────────── Traceback (most recent call last): File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3805, in get_loc return self._engine.get_loc(casted_key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "index.pyx", line 167, in pandas._libs.index.IndexEngine.get_loc File "index.pyx", line 196, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'RATE'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pharmpy/modeling/common.py", line 176, in convert_model new = module.convert_model(model) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pharmpy/model/external/rxode/model.py", line 104, in convert_model rxode_model = check_model(rxode_model, skip_error_model_check=skip_check) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pharmpy/model/external/nlmixr/sanity_checks.py", line 49, in check_model if same_time(model): ^^^^^^^^^^^^^^^^ File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pharmpy/model/external/nlmixr/sanity_checks.py", line 168, in same_time unique_rate = subset[ ^^^^^^^ File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pandas/core/frame.py", line 4102, in getitem indexer = self.columns.get_loc(key) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/xiach933/.virtualenvs/pharmr2/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 3812, in get_loc raise KeyError(key) from err KeyError: 'RATE'

── R Traceback ─────────────────────────────────────────────────── ▆

  1. └─pharmr::convert_model(run2, "rxode")
  2. └─pharmpy$modeling$convert_model(model, to_format)
  3. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named) See reticulate::py_last_error()$r_trace$full_call for more details.
rikardn commented 1 month ago

I checked and it looks like I was using an older version of pharmr for UPSS.