Skip to content

Commit 1ffaab5

Browse files
committed
Merge pull request #7933 from jreback/oob
DOC: update docs to show construction of periodindex when needing out-of bounds spans
2 parents 8d737e3 + 5004148 commit 1ffaab5

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

doc/source/gotchas.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ such as ``numpy.logical_and``.
358358
See the `this old issue <https://github.com/pydata/pandas/issues/2388>`__ for a more
359359
detailed discussion.
360360

361+
.. _gotchas.timestamp-limits:
362+
361363
Timestamp limitations
362364
---------------------
363365

@@ -375,14 +377,7 @@ can be represented using a 64-bit integer is limited to approximately 584 years:
375377
end = Timestamp.max
376378
end
377379
378-
If you need to represent time series data outside the nanosecond timespan, use
379-
PeriodIndex:
380-
381-
.. ipython:: python
382-
383-
span = period_range('1215-01-01', '1381-01-01', freq='D')
384-
span
385-
380+
See :ref:`here <timeseries.oob>` for ways to represent data outside these bound.
386381

387382
Parsing Dates from Text Files
388383
-----------------------------

doc/source/timeseries.rst

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,39 @@ the quarter end:
12721272
12731273
ts.head()
12741274
1275+
.. _timeseries.oob:
1276+
1277+
Representing out-of-bounds spans
1278+
--------------------------------
1279+
1280+
If you have data that is outside of the ``Timestamp`` bounds, see :ref:`Timestamp limitations <gotchas.timestamp-limits>`,
1281+
then you can use a ``PeriodIndex`` and/or ``Series`` of ``Periods`` to do computations.
1282+
1283+
.. ipython:: python
1284+
1285+
span = period_range('1215-01-01', '1381-01-01', freq='D')
1286+
span
1287+
1288+
To convert from a ``int64`` based YYYYMMDD representation.
1289+
1290+
.. ipython:: python
1291+
1292+
s = Series([20121231, 20141130, 99991231])
1293+
s
1294+
1295+
def conv(x):
1296+
return Period(year = x // 10000, month = x//100 % 100, day = x%100, freq='D')
1297+
1298+
s.apply(conv)
1299+
s.apply(conv)[2]
1300+
1301+
These can easily be converted to a ``PeriodIndex``
1302+
1303+
.. ipython:: python
1304+
1305+
span = PeriodIndex(s.apply(conv))
1306+
span
1307+
12751308
.. _timeseries.timezone:
12761309

12771310
Time Zone Handling
@@ -1355,13 +1388,13 @@ tz-aware data to another time zone:
13551388

13561389
Be wary of conversions between libraries. For some zones ``pytz`` and ``dateutil`` have different
13571390
definitions of the zone. This is more of a problem for unusual timezones than for
1358-
'standard' zones like ``US/Eastern``.
1391+
'standard' zones like ``US/Eastern``.
13591392

1360-
.. warning::
1393+
.. warning::
13611394

1362-
Be aware that a timezone definition across versions of timezone libraries may not
1363-
be considered equal. This may cause problems when working with stored data that
1364-
is localized using one version and operated on with a different version.
1395+
Be aware that a timezone definition across versions of timezone libraries may not
1396+
be considered equal. This may cause problems when working with stored data that
1397+
is localized using one version and operated on with a different version.
13651398
See :ref:`here<io.hdf5-notes>` for how to handle such a situation.
13661399

13671400
Under the hood, all timestamps are stored in UTC. Scalar values from a

0 commit comments

Comments
 (0)