Skip to content

Commit 76272e4

Browse files
committed
Merge branch 'timestamp_min_max' of https://github.com/SleepingPills/pandas into SleepingPills-timestamp_min_max
Conflicts: RELEASE.rst doc/source/v0.12.0.txt
2 parents 030f613 + d98dfe8 commit 76272e4

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

doc/source/gotchas.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ can be represented using a 64-bit integer is limited to approximately 584 years:
271271

272272
.. ipython:: python
273273
274-
begin = Timestamp(-9223285636854775809L)
274+
begin = Timestamp.min
275275
begin
276-
end = Timestamp(np.iinfo(np.int64).max)
276+
277+
end = Timestamp.max
277278
end
278279
279280
If you need to represent time series data outside the nanosecond timespan, use

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pandas 0.12
101101
- ``read_csv`` will now throw a more informative error message when a file
102102
contains no columns, e.g., all newline characters
103103
- Added ``layout`` keyword to DataFrame.hist() for more customizable layout (:issue:`4050`)
104+
- Timestamp.min and Timestamp.max now represent valid Timestamp instances instead
105+
of the default datetime.min and datetime.max (respectively), thanks @SleepingPills
104106

105107
**API Changes**
106108

doc/source/v0.12.0.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,13 @@ Other Enhancements
337337
dff.groupby('B').filter(lambda x: len(x) > 2, dropna=False)
338338

339339
- Series and DataFrame hist methods now take a ``figsize`` argument (:issue:`3834`)
340+
340341
- DatetimeIndexes no longer try to convert mixed-integer indexes during join
341342
operations (:issue:`3877`)
342343

344+
- Timestamp.min and Timestamp.max now represent valid Timestamp instances instead
345+
of the default datetime.min and datetime.max (respectively), thanks @SleepingPills
346+
343347
Experimental Features
344348
~~~~~~~~~~~~~~~~~~~~~
345349

pandas/tests/test_tseries.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from numpy import nan
44
import numpy as np
5-
from pandas import Index, isnull
5+
from pandas import Index, isnull, Timestamp
66
from pandas.util.testing import assert_almost_equal
77
import pandas.util.testing as common
88
import pandas.lib as lib
@@ -683,6 +683,22 @@ def test_int_index(self):
683683
expected = arr.sum(1)
684684
assert_almost_equal(result, expected)
685685

686+
687+
class TestTsUtil(unittest.TestCase):
688+
def test_min_valid(self):
689+
# Ensure that Timestamp.min is a valid Timestamp
690+
Timestamp(Timestamp.min)
691+
692+
def test_max_valid(self):
693+
# Ensure that Timestamp.max is a valid Timestamp
694+
Timestamp(Timestamp.max)
695+
696+
def test_to_datetime_bijective(self):
697+
# Ensure that converting to datetime and back only loses precision
698+
# by going from nanoseconds to microseconds.
699+
self.assertEqual(Timestamp(Timestamp.max.to_pydatetime()).value/1000, Timestamp.max.value/1000)
700+
self.assertEqual(Timestamp(Timestamp.min.to_pydatetime()).value/1000, Timestamp.min.value/1000)
701+
686702
if __name__ == '__main__':
687703
import nose
688704
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

pandas/tslib.pyx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,15 @@ cpdef object get_value_box(ndarray arr, object loc):
388388
return util.get_value_1d(arr, i)
389389

390390

391+
# Add the min and max fields at the class level
392+
# These are defined as magic numbers due to strange
393+
# wraparound behavior when using the true int64 lower boundary
394+
cdef int64_t _NS_LOWER_BOUND = -9223285636854775000LL
395+
cdef int64_t _NS_UPPER_BOUND = 9223372036854775807LL
396+
Timestamp.min = Timestamp(_NS_LOWER_BOUND)
397+
Timestamp.max = Timestamp(_NS_UPPER_BOUND)
398+
399+
391400
#----------------------------------------------------------------------
392401
# Frequency inference
393402

@@ -770,8 +779,6 @@ cdef inline object _get_zone(object tz):
770779
except AttributeError:
771780
return tz
772781

773-
# cdef int64_t _NS_LOWER_BOUND = -9223285636854775809LL
774-
# cdef int64_t _NS_UPPER_BOUND = -9223372036854775807LL
775782

776783
cdef inline _check_dts_bounds(int64_t value, pandas_datetimestruct *dts):
777784
cdef pandas_datetimestruct dts2

0 commit comments

Comments
 (0)