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

TypeError when using ShiftedPearsonCorrelation with a constant time series #96

Open
ckae95 opened this issue Jan 9, 2020 · 0 comments

Comments

@ckae95
Copy link
Contributor

ckae95 commented Jan 9, 2020

Description

Error is thrown when using ShiftedPearsonCorrelation and a time series (i.e. a column in the data frame) is constant.

Steps/Code to Reproduce

This is the example as shown in the documentation with an additional column 'E' which is constant.

from giottotime.causality_tests.shifted_pearson_correlation import ShiftedPearsonCorrelation
import pandas.util.testing as testing
import numpy as np
data = testing.makeTimeDataFrame(freq="s")
data['E'] = np.ones(len(data))
spc = ShiftedPearsonCorrelation(target_col="A")
spc.fit(data)
spc.best_shifts_

spc.transform(data)

Expected Results

No error is thrown.

Actual Results


TypeError Traceback (most recent call last)
in
8 spc.best_shifts_
9
---> 10 spc.transform(data)

~/anaconda3/envs/time/lib/python3.7/site-packages/giottotime/causality_tests/shifted_pearson_correlation.py in transform(self, data)
119 for col in data_t:
120 if col != self.target_col:
--> 121 data_t[col] = data_t[col].shift(self.best_shifts_[col][self.target_col])
122
123 if self.dropna:

~/anaconda3/envs/time/lib/python3.7/site-packages/pandas/core/series.py in shift(self, periods, freq, axis, fill_value)
4371 def shift(self, periods=1, freq=None, axis=0, fill_value=None):
4372 return super().shift(
-> 4373 periods=periods, freq=freq, axis=axis, fill_value=fill_value
4374 )
4375

~/anaconda3/envs/time/lib/python3.7/site-packages/pandas/core/generic.py in shift(self, periods, freq, axis, fill_value)
9397 if freq is None:
9398 new_data = self._data.shift(
-> 9399 periods=periods, axis=block_axis, fill_value=fill_value
9400 )
9401 else:

~/anaconda3/envs/time/lib/python3.7/site-packages/pandas/core/internals/managers.py in shift(self, **kwargs)
570
571 def shift(self, **kwargs):
--> 572 return self.apply("shift", **kwargs)
573
574 def fillna(self, **kwargs):

~/anaconda3/envs/time/lib/python3.7/site-packages/pandas/core/internals/managers.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
436 kwargs[k] = obj.reindex(b_items, axis=axis, copy=align_copy)
437
--> 438 applied = getattr(b, f)(**kwargs)
439 result_blocks = _extend_blocks(applied, result_blocks)
440

~/anaconda3/envs/time/lib/python3.7/site-packages/pandas/core/internals/blocks.py in shift(self, periods, axis, fill_value)
1351 else:
1352 axis_indexer[axis] = slice(periods, None)
-> 1353 new_values[tuple(axis_indexer)] = fill_value
1354
1355 # restore original order

TypeError: slice indices must be integers or None or have an index method

Versions

Darwin-18.7.0-x86_64-i386-64bit
Python 3.7.5 (default, Oct 25 2019, 10:52:18)
[Clang 4.0.1 (tags/RELEASE_401/final)]
NumPy 1.18.0
SciPy 1.4.1
joblib 0.14.1
Scikit-Learn 0.22
giotto-Learn 0.1.3
giotto-time 0.1.0

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

1 participant