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

Change int to float in in_interval #1

Open
gviejo opened this issue Dec 12, 2018 · 0 comments
Open

Change int to float in in_interval #1

gviejo opened this issue Dec 12, 2018 · 0 comments

Comments

@gviejo
Copy link

gviejo commented Dec 12, 2018

Hello
It's great to see that neuroseries is still updated.
I appreciate the new compatibility with pandas 0.23.
There is just one bug that is still here since the previous version.
In this function :

    def in_interval(self, tsd):
        """
        finds out in which element of the interval set each point in a time series fits.

        NaNs for those
        that don't fit a interval
        :param tsd: the tsd to be binned
        :return: an array with the interval index labels for each time stamp (NaN) for timestamps not in
        IntervalSet.
        """
        bins = self.values.ravel()
        ix = np.array(pd.cut(tsd.index, bins, labels=np.arange(len(bins) - 1, dtype=np.int64)))
        ix[np.floor(ix / 2) * 2 != ix] = np.NaN
        ix = np.floor(ix/2)
        return ix

The error is

ValueError                                Traceback (most recent call last)
<ipython-input-48-09ae7a98dd24> in <module>()
----> 1 ix[np.floor(ix/2)*2 != ix] = np.NaN

ValueError: cannot convert float NaN to integer

Basically, it is solved by changing dtype=np.int64 to dtype=np.float64 when defining ix.
Yet, I am not quite sure why I can run the tests without this being detect as an error.

If it's not quite troublesome, would it be possible to change np.int64 to np.float64 since numpy nan are considered as float?

Thanks

Guillaume

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