orbit icon indicating copy to clipboard operation
orbit copied to clipboard

Exception: 'tqdm_asyncio' object has no attribute 'postfix'

Open johann-petrak opened this issue 6 months ago • 1 comments

I just got this very unexpected exception:

    super().fit(df, sampling_temperature=sampling_temperature, **kwargs)
  File "/home/johann/software/anaconda/envs/sipfront/lib/python3.11/site-packages/orbit/forecaster/forecaster.py", line 164, in fit
    _posterior_samples, training_metrics = estimator.fit(
                                           ^^^^^^^^^^^^^^
  File "/home/johann/software/anaconda/envs/sipfront/lib/python3.11/site-packages/orbit/estimators/stan_estimator.py", line 143, in fit
    stan_mcmc_fit = compiled_mod.sample(
                    ^^^^^^^^^^^^^^^^^^^^
  File "/home/johann/software/anaconda/envs/sipfront/lib/python3.11/site-packages/cmdstanpy/model.py", line 1098, in sample
    progress_hook("Done", -1)  # -1 == all chains finished
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/johann/software/anaconda/envs/sipfront/lib/python3.11/site-packages/cmdstanpy/model.py", line 2155, in progress_hook
    pbar.postfix[0]["value"] = 'Sampling completed'
    ^^^^^^^^^^^^
AttributeError: 'tqdm_asyncio' object has no attribute 'postfix'

This happens when using

os.environ['TQDM_DISABLE'] = '1'

before importing orbit modules in an attempt to disable those annotying progress bars. As far as I know setting this environment variable is a standard way to disable the output and seems to be the only way as orbit does not have any setting to do it in some other way. So when that environment variable is set, orbit should definitely NOT crash.

johann-petrak avatar Jun 25 '25 07:06 johann-petrak

I can reproduce this.

What’s happening:

  • When TQDM_DISABLE=1 is set, tqdm returns a “disabled” progress bar that doesn’t have a .postfix attribute.
  • cmdstanpy’s progress hook assumes .postfix exists and tries to do pbar.postfix[0]["value"].
  • That triggers an AttributeError when Orbit calls cmdstanpy.Model.sample.

Minimal repro:

import os
os.environ["TQDM_DISABLE"] = "1"

from orbit.models import DLT
import pandas as pd
import numpy as np

df = pd.DataFrame({
    "ds": pd.date_range("2020-01-01", periods=20, freq="D"),
    "y": np.random.randn(20).cumsum() + 100,
})

dlt = DLT(response_col="y", date_col="ds")
dlt.fit(df=df[:-3])  # crashes here

We can add a small compatibility guard so Orbit doesn’t break when progress bars are disabled, e.g., detect TQDM_DISABLE=1 and avoid progress updates (or check that .postfix exists before using it). This keeps normal behavior when progress bars are enabled.

mohsinm-dev avatar Sep 24 '25 17:09 mohsinm-dev