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

'Pre' and 'post' step interpolations loose precision #3878

Closed
randomstuff opened this issue Aug 5, 2019 · 2 comments · Fixed by #3958
Closed

'Pre' and 'post' step interpolations loose precision #3878

randomstuff opened this issue Aug 5, 2019 · 2 comments · Fixed by #3958
Labels
bug
Milestone

Comments

@randomstuff
Copy link
Contributor

@randomstuff randomstuff commented Aug 5, 2019

When using .step() with datetime, it looses precisions.

This is especially noticeable when comparing the hover information of .hvlplot() and .hvplot.step():

import pandas as pd
import hvplot.pandas

index = pd.to_datetime([
                    "2019-07-01 12:00:00+00:00",
                    "2019-07-01 16:30:47+00:00",
                    "2019-07-01 17:03:48+00:00",
                    "2019-07-01 18:27:06+00:00",
                    "2019-07-01 18:41:31+00:00",
                    "2019-07-01 19:23:19+00:00",
                    "2019-07-01 19:23:45+00:00",
                    "2019-07-01 21:11:57+00:00",
                    "2019-07-01 21:12:53+00:00",
                    "2019-07-01 23:12:42+00:00",
                  ])
Z = pd.Series([1, 0,1,0,1,0,1,0,1,0], index=index)
Z.hvplot() + Z.hvplot.step(where="post")

As fas as I understand, this caused by the float conversion here:

    def _process_layer(self, element, key=None):
        INTERPOLATE_FUNCS = {'steps-pre': self.pts_to_prestep,
                             'steps-mid': self.pts_to_midstep,
                             'steps-post': self.pts_to_poststep}
        if self.p.interpolation not in INTERPOLATE_FUNCS:
            return element
        x = element.dimension_values(0)
        is_datetime = isdatetime(x)
        if is_datetime:
            dt_type = 'datetime64[ns]'
            x = x.astype(dt_type).astype('int64')
        dvals = tuple(element.dimension_values(d) for d in element.dimensions()[1:])
        xs, dvals = INTERPOLATE_FUNCS[self.p.interpolation](x.astype('f'), dvals)
        if is_datetime:
            xs = xs.astype(dt_type)
        return element.clone((xs,)+dvals)

    def _process(self, element, key=None):
        return element.map(self._process_layer, Element)

The float conversion might be useful for the mid interpolation but is not necessary for the pre and post interpolations.

@philippjfr philippjfr added the bug label Aug 5, 2019
@SvenWarnke

This comment has been minimized.

Copy link

@SvenWarnke SvenWarnke commented Sep 12, 2019

I would love to see this fixed, displaying curves as a step function instead of linearly interpolated makes a huge difference visually.

@philippjfr

This comment has been minimized.

Copy link
Member

@philippjfr philippjfr commented Sep 12, 2019

We'd be very happy to see a PR, for now we could simply fix the pre/post interpolations using the simple suggested fix:

x = x.astype('f') if self.p.interpolation != 'mid' else x
xs, dvals = INTERPOLATE_FUNCS[self.p.interpolation](x, dvals)

but a proper fix for all interpolation methods would of course be preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.