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

string-representation for Timestamp does not show nanoseconds if present #5912

Closed
cancan101 opened this issue Jan 12, 2014 · 3 comments · Fixed by #5701

Comments

@cancan101
Copy link
Contributor

commented Jan 12, 2014

See:

In [27]: str(pd.Timestamp(200))
Out[27]: '1970-01-01 00:00:00'

In [28]: repr(pd.Timestamp(200))
Out[28]: "Timestamp('1970-01-01 00:00:00.000000200', tz=None)"

whereas microseconds work fine:

In [30]: str(pd.Timestamp(2000))
Out[30]: '1970-01-01 00:00:00.000002'
@cancan101

This comment has been minimized.

Copy link
Contributor Author

commented Jan 12, 2014

One way to fix this would be to implement isoformat in Timestamp. Another would be to implement __str__ and have that method check if nanos !=0.

@cancan101

This comment has been minimized.

Copy link
Contributor Author

commented Jan 12, 2014

    def isoformat(self, sep='T'):
        base = super(_Timestamp, self).isoformat(sep=sep)
        if self.nanosecond == 0:
            return base

        if self.tzinfo is not None:
            base1, base2 = base[:-6], base[-6:]
        else:
            base1, base2 = base, ""

        if self.microsecond != 0:
            base1 += "%.3d" % self.nanosecond
        else:
            base1 += "%.9d" % self.nanosecond

        return base1 + base2
@cancan101

This comment has been minimized.

Copy link
Contributor Author

commented Jan 12, 2014

I intend to fix this (and add some test showing issue) in #5701

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