Skip to content

BUG: Timestamp rounding wrong implementation fixed #11963 #11964

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
wants to merge 1 commit into from
Closed

Conversation

Tux1
Copy link
Contributor

@Tux1 Tux1 commented Jan 5, 2016

closes #11963

attribs = self._get_attributes_dict()
if 'freq' in attribs:
attribs['freq'] = None
if 'tz' in attribs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls reuse the existing code rather than repeating, e.g. something like:

def _round(self, freq, rounder):
        from pandas.tseries.frequencies import to_offset
         unit = to_offset(freq).nanos

         if getattr(self,'tz',None) is not None:
             values = self.tz_localize(None).asi8
         else:
             values = self.asi8
          result = (unit*rounder(values/unit)).astype('i8')
          attribs = self._get_attributes_dict()
          if 'freq' in attribs:
              result = result.tz_localize(self.tz)
          return result

def round(self, freq):
    return self._round(freq, np.round)

def floor(self, freq):
    return self._round(freq, np.floor)

furtther use an Appender on the doc-string to avoid repeating

@jreback
Copy link
Contributor

jreback commented Jan 5, 2016

pls update Timedelta as well. need impl and tests.

@jreback jreback added Bug Datetime Datetime data dtype Timedelta Timedelta data type labels Jan 5, 2016
@jreback jreback added this to the 0.18.0 milestone Jan 5, 2016
-----
For values exactly halfway between rounded decimal values,
Numpy rounds to the nearest even value. Thus the new Timedelta
may be lower than the original Timedelta.
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback please note the warning I add in the round documentation about rounding of float. The behaviour is slightly different than the arithmetical definition but it refers to Numpy implementation

@jreback
Copy link
Contributor

jreback commented Jan 11, 2016

looks good.

small comments. pls run git diff master | flake8 --diff and incorporate pep8 fixes.

@jreback
Copy link
Contributor

jreback commented Jan 11, 2016

ping on green.

@Tux1
Copy link
Contributor Author

Tux1 commented Jan 11, 2016

I think it's okay

@jreback
Copy link
Contributor

jreback commented Jan 12, 2016

merged via 4437e9c

@jreback jreback closed this Jan 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timestamp rounding wrong implementation
2 participants