pynapple-org / pynapple

PYthon Neural Analysis Package :pineapple:
https://pynapple-org.github.io/pynapple/
MIT License
239 stars 58 forks source link

@jit TypingError #278

Open jolson1129 opened 1 month ago

jolson1129 commented 1 month ago

I'm having issues using restrict with a tsdFrame - it works on the sample code, but not my real object, due to a jit typing error. I'm having a difficult time figuring out what's going on. Any help would be appreciated.

Ex:

tsdframe = nap.TsdFrame(
    t=np.arange(100), d=np.random.rand(100, 3), time_units="s", columns=["a", "b", "c"]
)
ep = nap.IntervalSet(start=3000, end=4000, time_units='s')
newtsdframe = tsdframe.restrict(ep)
newtsdframe.time_support

start end shape: (0, 2), time unit: sec.

movement_df = pd.read_pickle(
    os.path.join(settings['beh_path'],
                 NWB_FILE + settings[tracking_to_use]))
mv_no_nan_df = movement_df.dropna()
movement_tsdf = nap.TsdFrame(mv_no_nan_df)
ep = nap.IntervalSet(start=3000, end=4000, time_units='s')
newtsdframe = movement_tsdf.restrict(ep)
newtsdframe.time_support

TypingError

The obj looks like this: movement_tsdf

Time (s)               x        y         hd        vel     heading  ...
---------------  -------  -------  ---------  ---------  ----------  -----
2466.663166667   40.9124  124.26   -2.87964    9.53626    2.56746    ...
2466.692766667   40.6901  124.496  -2.8696    10.9515     2.32637    ...
2466.728433333   40.5355  124.758  -2.85585    8.5128     2.10494    ...
2466.758033333   40.44    125.02   -2.84096    9.42049    1.92033    ...
2466.793233333   40.3851  125.263  -2.82691    7.09351    1.79278    ...
...
15179.432        85.6107  224.851   0.645715   0.66341   -0.0945317  ...
15179.461466667  85.6287  224.845   0.648599   0.640743  -0.30386    ...
15179.497066667  85.6405  224.838   0.652732   0.380431  -0.511823   ...
15179.5267       85.6471  224.833   0.656747   0.289697  -0.706567   ...
15179.561266667  85.6498  224.83    0.65921    0.120441  -0.850848   ...

dtype: object, shape: (215173, 14)

jolson1129 commented 1 month ago

Edit: It's just a full on JIT issue. I can't even slice. I'll try another computer tomorrow. Was running pynapple 0.6.1 btw, upgraded to 0.6.4, to no effect.

File ~/miniconda3/envs/JLabToNWB/lib/python3.8/site-packages/pynapple/core/time_series.py:105, in BaseTsd.init(self, t, d, time_units, time_support) 103 starts = time_support.start 104 ends = time_support.end --> 105 t, d = jitrestrict(self.index.values, self.values, starts, ends) 106 self.index = TsIndex(t) 107 self.values = d

File ~/miniconda3/envs/JLabToNWB/lib/python3.8/site-packages/numba/core/dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws) 464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused " 465 f"by the following argument(s):\n{args_str}\n") 466 e.patch_message(msg) --> 468 error_rewrite(e, 'typing') 469 except errors.UnsupportedError as e: 470 # Something unsupported is present in the user code, add help info 471 error_rewrite(e, 'unsupported_error')

File ~/miniconda3/envs/JLabToNWB/lib/python3.8/site-packages/numba/core/dispatcher.py:409, in _DispatcherBase._compile_for_args..error_rewrite(e, issue_type) 407 raise e 408 else: --> 409 raise e.with_traceback(None)

TypingError: Failed in nopython mode pipeline (step: nopython frontend) non-precise type array(pyobject, 1d, C) During: typing of argument at /home/jmo/miniconda3/envs/JLabToNWB/lib/python3.8/site-packages/pynapple/core/_jitted_functions.py (5)

File "../../../../../../../home/jmo/miniconda3/envs/JLabToNWB/lib/python3.8/site-packages/pynapple/core/_jitted_functions.py", line 5:

@jit(nopython=True)

jolson1129 commented 1 month ago

I've narrowed it down using slices of the df that I use to create the TsdFrame to learn that it is 1 column in particular causing the failure. It is a boolean column, but there are other boolean columns that do not fail. Do you have any suggestions on what is occurring here?

gviejo commented 1 month ago

It looks like it's a problem with a dtype that numba doesn't like. Is movement_tsdf a mixed dtype dataframe?

jolson1129 commented 1 month ago

Yes. Here are the details. Do you have any insight to what causes the JIT issues when creating variables? I cannot see a difference between the offending column and it's neighbor, but perhaps I'm not looking at the correct property?

I've narrowed it down using slices of the df that I use to create the TsdFrame to learn that it is 1 column in particular causing the failure. It is a boolean column, but there are other boolean columns that do not fail. Do you have any suggestions on what is occurring here?

gviejo commented 1 month ago

Can you share a small version of your data frame?