Typo in utcdatetime.py?

Hi all,

I wonder if the functions _get_ns and _set_ns in utcdatetime.py do what they are supposed to do?

In line 379:

return self.__ns

might be a typo, as this variable is referred to as self._ns throughout the rest of the code except in _get_ns and _set_ns...

Kind regards

Roman Racine

Hi Roman,

nope its fine as it is - the relevant code can be found here:


_get_ns and _set_ns are setter/getter methods for the _ns attribute -
setting _ns within a setter would result in a infinite loop - you need
another parameter to store the value - in this case __ns

Also, all those methods/parameters are internal (indicated by the
starting underscore in the method/parameter name) and shouldn't be used
at all outside of the library.

If you still think there is an issue, please don't hesitate to open a
ticket at Github https://github.com/obspy/obspy/issues.


Hi Robert,

I think I found the problem. UTCDateTime objects created with an older version of the library and stored on disk using pickle are not fully compatible when used with the newest version:

File "/usr/local/lib/python2.7/dist-packages/obspy-0.0.0_archive-py2.7-linux-x86_64.egg/obspy/core/utcdatetime.py", line 1165, in __ge__
     return round((self._ns - other._ns) / 1e9, self.__precision) >= 0
AttributeError: 'UTCDateTime' object has no attribute '_ns'

In hindsight, I don't see this as a problem.



Hi Roman,

we hit the same issue with pickled UTCDateTime objects coming from
SeisHub (which uses ObsPy<1.0.3) - the issue has been fixed in master -

Until the next release you could just overwrite your local
obspy/core/utcdatetime.py with the file linked above.