Search code examples
pythonpiptypeerror

Python Causal Impact is producing a type error


I am working on calculating causal impact and it is throwing an error

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [19], in <cell line: 1>()
----> 1 ci = CausalImpact(new_data, pre_period, post_period)

TypeError: 'module' object is not callable

Here is my code for causal impact, it has two columns (y, X0) and date index:

from statsmodels.tsa.arima_process import ArmaProcess
import causalimpact as CausalImpact
pre_period = ['2021-01-01 00:00:00+00:00', '2022-07-08 00:00:00+0000']
post_period = ['2022-07-09 00:00:00+0000', '2022-07-21 00:00:00+00:00']
ci = CausalImpact(data, pre_period, post_period)

Solution

  • import causalimpact as CausalImpact
    

    You're importing a module (and giving it a different name, but that's beside the point), and then you're trying to use that module as if it were a class.

    I don't know anything about this module, but I bet that there is really a class of that name defined inside the module, and that's what you wanted:

    from causalimpact import CausalImpact