WillianFuks / tfcausalimpact

Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.
Apache License 2.0
593 stars 70 forks source link

AttributeError: 'NoneType' object has no attribute 'loc' #71

Closed tmpacc90 closed 1 year ago

tmpacc90 commented 1 year ago

Not sure if anyone else has encountered the same issue. Running the example returns the following error

import pandas as pd
from causalimpact import CausalImpact

data = pd.read_csv('https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/tests/fixtures/arma_data.csv')[['y', 'X']]
data.iloc[70:, 0] += 5

pre_period = [0, 69]
post_period = [70, 99]

ci = CausalImpact(data, pre_period, post_period)
print(ci.summary())
print(ci.summary(output='report'))
ci.plot()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-78-aeae0ba2a7e5>](https://localhost:8080/#) in <module>
     10 
     11 ci = CausalImpact(data, pre_period, post_period)
---> 12 print(ci.summary())
     13 print(ci.summary(output='report'))
     14 ci.plot()

[/usr/local/lib/python3.9/dist-packages/causalimpact/analysis.py](https://localhost:8080/#) in summary(self, output, width, path)
    727         confidence = "{}%".format(int((1 - alpha) * 100))
    728         post_period = self.params["post_period"]
--> 729         post_inf = self.inferences.loc[post_period[0] : post_period[1], :]
    730         post_point_resp = post_inf.loc[:, "response"]
    731         post_point_pred = post_inf.loc[:, "point_pred"]

AttributeError: 'NoneType' object has no attribute 'loc'

Python version: 3.9.16 Pandas version: 1.4.4

WillianFuks commented 1 year ago

Hi @tmpacc90 ,

Apparently you are using some other project of causal impact, this one doesn't have a module named "analysis.py" which is indicated in your traceback.

To use this project, please make sure the code is available in your interpreter lib by running pip install -U tfcausalimpact

Let me know if this helps you,

tmpacc90 commented 1 year ago

Thanks. It helps! 😃

benji931122 commented 8 months ago

Hi! I'm getting the exact same error here, despite doing the pip install -U tfcausalimpact. Do you know what else I can do?

It was working just fine 3 days ago.

WillianFuks commented 8 months ago

Hi @benji931122 ,

Could you please open a new issue for us to further investigate it? Please let us know the version of tfci you currently have and an example of the code you are running, as well as OS and Python version.