votes up 1

lag must be an integer

Package:
dask
github stars 8734
Exception Class:
TypeError

Raise code

        return cov_corr(
            df, min_periods, corr=True, scalar=True, split_every=split_every
        )

    @derived_from(pd.Series)
    def autocorr(self, lag=1, split_every=False):
        if not isinstance(lag, Integral):
            raise TypeError("lag must be an integer")
        return self.corr(self if lag == 0 else self.shift(lag), split_every=split_every)

    @derived_from(pd.Series)
    def memory_usage(self, index=True, deep=False):
        result = self.map_partitions(
            M.memory_usage, index=index, deep=deep, enforce_metadata=False
        )
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 1 votes down

dask.dataframe.autocorr expects the value of the parameter lag to be an integer. That's why this exception is raised.

For steps of reproducing this exception check the section below.

Steps to reproduce the exception:

$ pipenv install dask dask[dataframe] pandas

$ pipenv shell

import pandas as pd
import dask
import dask.array as dask
import dask.dataframe as dd
import numpy as np
x = pd.Series(np.random.random(100))
dx = dd.from_pandas(x, npartitions=10)
dx.autocorr(2.5)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-107525b08c9e> in <module>()  6 x = pd.Series(np.random.random(100))  7 dx = dd.from_pandas(x, npartitions=10) ----> 8 dx.autocorr(2.5) 
/usr/local/lib/python3.7/dist-packages/dask/dataframe/core.py in autocorr(self, lag, split_every)  3102 def autocorr(self, lag=1, split_every=False):  3103 if not isinstance(lag, Integral): -> 3104 raise TypeError("lag must be an integer")  3105 return self.corr(self if lag == 0 else self.shift(lag), split_every=split_every)  3106  
TypeError: lag must be an integer

Fixed version of the code:

import pandas as pd
import dask
import dask.array as dask
import dask.dataframe as dd
import numpy as np
x = pd.Series(np.random.random(100))
dx = dd.from_pandas(x, npartitions=10)
dx.autocorr(2)
Oct 26, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix