Skip to content

Error with closed='left' and _adjust_bin_edges #1726

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

Closed
dalejung opened this issue Aug 3, 2012 · 1 comment
Closed

Error with closed='left' and _adjust_bin_edges #1726

dalejung opened this issue Aug 3, 2012 · 1 comment
Labels
Milestone

Comments

@dalejung
Copy link
Contributor

dalejung commented Aug 3, 2012

import pandas as pd

#8/6/12 is a Monday
ind = pd.DatetimeIndex(start="8/6/2012", end="8/26/2012", freq="D")
n = len(ind)
data = [[x] * 5 for x in range(n)]
df = pd.DataFrame(data, columns=['open', 'high', 'low', 'close', 'vol'], index=ind)

df.resample('W-MON', how='first', closed='left', label='left')

Will result in an error. I tracked it down to

      def _adjust_bin_edges(self, binner, ax_values):
        # Some hacks for > daily data, see #1471, #1458, #1483

        bin_edges = binner.asi8

        if self.freq != 'D' and is_superperiod(self.freq, 'D'):
            day_nanos = _delta_to_nanoseconds(timedelta(1))
            if self.closed == 'right':
                bin_edges = bin_edges + day_nanos - 1
            else:
                bin_edges = bin_edges + day_nanos

I'm not sure why the day is added when closed='left'. Even on datasets that don't start on a Monday, and thus don't error, it'll cause the intervals to start on Tuesday.

@wesm wesm closed this as completed in fc92170 Aug 13, 2012
@wesm
Copy link
Member

wesm commented Aug 13, 2012

Thanks, dale. You were indeed correct that the bin adjustment logic was incorrect.

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

No branches or pull requests

2 participants