Error encountered ruptures library

Traceback (most recent call last):

File “/context/venv/lib/python3.11/site-packages/crunch/runner/cloud_executor.py”, line 230, in start

prediction = self.process_unstructured()

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/context/venv/lib/python3.11/site-packages/crunch/runner/cloud_executor.py”, line 486, in process_unstructured

return utils.smart_call(

       ^^^^^^^^^^^^^^^^^

File “/context/venv/lib/python3.11/site-packages/crunch/utils.py”, line 270, in smart_call

return function(\*\*arguments)

       ^^^^^^^^^^^^^^^^^^^^^

File “/context/scoring/runner.py”, line 127, in infer

collected_values, \_ = wrapper.collect(len(datasets))

                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/context/venv/lib/python3.11/site-packages/crunch/container.py”, line 187, in collect

y = next(iterator, sentinel)

    ^^^^^^^^^^^^^^^^^^^^^^^^

File “/context/code/main.py”, line 1442, in infer

test_cpd_feats = compute_cpd_features(

                 ^^^^^^^^^^^^^^^^^^^^^

File “/context/code/main.py”, line 1319, in compute_cpd_features

res = detect_changepoints_and_confidence(

      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/context/code/main.py”, line 1265, in detect_changepoints_and_confidence

if not \_HAS_RUPTURES or n < 6:

       ^^^^^^^^^^^^^

NameError: name ‘_HAS_RUPTURES’ is not defined

Getting this error can you help me ?

You likely declared a constant in your notebook right?

This is a known issue as we cannot easily differenciate between debugging code and “safe” or constant code.

So our system will try to comment everything that is not functions, or imports or classes.
You can learn more here: Notebook Processor | CrunchDAO Docs V3

To fix it, you can either:

  • Wrap the declaration of your constant using the # @crunch/keep:on and # @crunch/keep:off commands:
    # @crunch/keep:on
    _HAS_RUPTURES = true
    # @crunch/keep:off
    
    if _HAS_RUPTURES:
        ...
    
  • Move your constants into a dedicated cell and put the # @crunch/keep:on at the very top:
    # @crunch/keep:on
    _HAS_RUPTURES = true
    
    if _HAS_RUPTURES:
        ...
    
  • Declare them in a class:
    class Constants:
        _HAS_RUPTURES = true
    
    if Constants._HAS_RUPTURES:
        ...