WillianFuks / tfcausalimpact

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

Example with data in np.ndarray doesn't work #44

Closed tarstars closed 2 years ago

tarstars commented 2 years ago

This snippet from CasualImpact docstring produces the error:

Python data = np.random.rand(100, 2) pre_period = [0, 69] post_period = [70, 99] ci = CausalImpact(data, pre_period, post_period) print(ci.summary()) print(ci.summary('report')) ci.plot()

Error: /main.py:333 332 self.inferences = inferrer.compile_posterior_inferences( --> 333 self.data.index, AttributeError: 'numpy.ndarray' object has no attribute 'index'

WillianFuks commented 2 years ago

Hi @tarstars ,

Thanks for opening this issue! You're right, just tested it here and got the same error.

Not sure yet what happened, I suspect that after tensorflow probability updated their API to only accept pandas dataframes with time based indexes has left this repository with open bugs yet when processing numpy arrays, which unfortunately were not detected on the unit tests.

I'll work on a fix by Monday and update the code already.

Thanks once again,

Will

WillianFuks commented 2 years ago

Hi @tarstars ,

Just published a new release candidate, could you please try it out and confirm if it's working for you now?

To install the new code:

pip install tfcausalimpact==0.0.10rc0

Hopefully now it'll work as expected.

Best,

Will

tarstars commented 2 years ago

Hi @tarstars ,

Just published a new release candidate, could you please try it out and confirm if it's working for you now?

To install the new code:

pip install tfcausalimpact==0.0.10rc0

Hopefully now it'll work as expected.

Best,

Will

Will,

Thank you for such a prompt answer. It is totally amaising to meet such a cooperative approach.

Unfortunately something went wrong:

tass@wonderbox ~/notebooks $ pip install tfcausalimpact==0.0.10rc0
ERROR: Could not find a version that satisfies the requirement tfcausalimpact==0.0.10rc0 (from versions: 0.0.0, 0.0.1, 0.0.2rc1, 0.0.2, 0.0.3, 0.0.4, 0.0.5)
ERROR: No matching distribution found for tfcausalimpact==0.0.10rc0

Probably these changes did not roll out yer. Will try again later.

Update It turned out that I tried to install tfcausalimpact from the python-3.10 environment. From python-3.8 I installed the new version successfuly and now it is working.

Thank you for your prompt reaction.

Thanks, Arseniy

WillianFuks commented 2 years ago

That's good to know :) I'll merge the new code then.

Thanks for the feedback!

Will