Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for pandas attribute 'is_datetime_or_timedelta_dtype' #56

Open
doharris3635 opened this issue Jun 13, 2024 · 8 comments
Open

Comments

@doharris3635
Copy link

I have tried to recreate the demo from the "Getting Started" page on two different Jupyter Notebook platforms, and I consistently get the following error when I try to execute impact.run(): Can you tell me how to solve this problem? [email protected]


AttributeError Traceback (most recent call last)
Cell In[8], line 1
----> 1 impact.run()

File /apps/jupyter/DanHarris/VirtualEnvironment/DanHarris/lib64/python3.11/site-packages/causalimpact/analysis.py:91, in CausalImpact.run(self)
90 def run(self):
---> 91 kwargs = self._format_input(
92 self.params["data"],
93 self.params["pre_period"],
94 self.params["post_period"],
95 self.params["model_args"],
96 self.params["ucm_model"],
97 self.params["post_period_response"],
98 self.params["alpha"],
99 )
101 # Depending on input, dispatch to the appropriate Run* method()
102 if self.data is not None:

File /apps/jupyter/DanHarris/VirtualEnvironment/DanHarris/lib64/python3.11/site-packages/causalimpact/analysis.py:343, in CausalImpact._format_input(self, data, pre_period, post_period, model_args, ucm_model, post_period_response, alpha)
341 # Check <pre_period> and <post_period>
342 if data is not None:
--> 343 checked = self._format_input_prepost(pre_period, post_period, data)
344 pre_period = checked["pre_period"]
345 post_period = checked["post_period"]

File /apps/jupyter/DanHarris/VirtualEnvironment/DanHarris/lib64/python3.11/site-packages/causalimpact/analysis.py:250, in CausalImpact._format_input_prepost(self, pre_period, post_period, data)
241 """Check and format the pre_period and post_period input arguments.
242
243 Args:
(...)
246 data: already-checked Pandas DataFrame, for reference only
247 """
248 self._check_periods_are_valid(pre_period, post_period)
--> 250 pre_period, post_period = self._align_periods_dtypes(
251 pre_period, post_period, data
252 )
254 if pre_period[1] > post_period[0]:
255 raise ValueError(
256 "post period must start at least 1 observation"
257 + " after the end of the pre_period"
258 )

File /apps/jupyter/DanHarris/VirtualEnvironment/DanHarris/lib64/python3.11/site-packages/causalimpact/analysis.py:186, in CausalImpact._align_periods_dtypes(pre_period, post_period, data)
184 pd.core.dtypes.common.is_datetime_or_timedelta_dtype(pre_period)
185 # if index is not datetime then error if datetime pre and post is passed
--> 186 elif pd.core.dtypes.common.is_datetime_or_timedelta_dtype(
187 pd.Series(pre_period)
188 ) or pd.core.dtypes.common.is_datetime_or_timedelta_dtype(
189 pd.Series(post_period)
190 ):
191 raise ValueError(
192 "pre_period ("
193 + pre_dtype.name
(...)
199 + ")"
200 )
201 # if index is int

AttributeError: module 'pandas.core.dtypes.common' has no attribute 'is_datetime_or_timedelta_dtype'

@bhanuprakash9980
Copy link

I am facing the same issue

@hankhaha
Copy link

I'm encountering the same issue. could we please have it fixed?

@csanden
Copy link

csanden commented Jul 17, 2024

I encountered the same issue which was caused by a mismatch in Pandas versions. I would check which version of Pandas you have installed. In my case, I had version 2.2.2 of Pandas installed. To remedy the issue, I installed version 1.5.2 as defined in the requirements.

@doharris3635
Copy link
Author

doharris3635 commented Jul 17, 2024 via email

@hankhaha
Copy link

hankhaha commented Jul 17, 2024 via email

@kangsasha
Copy link

kangsasha commented Jul 17, 2024

The problem is with line 184 in 'analysis.py': pd.core.dtypes.common.is_datetime_or_timedelta_dtype(pre_period).
This line seems to do nothing. Just comment it out and the error will go away.
I would PR it but don't know how yet.

And if you don't want to mess with the source code pandas==2.0.3 works OK.

@hankhaha
Copy link

hankhaha commented Jul 17, 2024 via email

@sashakang
Copy link

I am not sure yet how it works but this issue was fixed in this PR: #50.
It was merged on Apr 22, 2024 but failed some automatic checks and this is probably why it did not make it to the version which is installed by pip install causalimpact.

Oh, it turns out this issue is a duplicate of this issue: #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants