Skip to content

Commit 13d9592

Browse files
jorisvandenbosschesinhrks
authored andcommitted
DOC: some clean-up of wording
1 parent 06a4f36 commit 13d9592

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

doc/source/timeseries.rst

+34-29
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,40 @@ objects:
15961596
15971597
``PeriodIndex`` has its own dtype named ``period``, refer to :ref:`Period Dtypes <timeseries.period_dtype>`.
15981598

1599+
.. _timeseries.period_dtype:
1600+
1601+
Period Dtypes
1602+
~~~~~~~~~~~~~
1603+
1604+
.. versionadded:: 0.19.0
1605+
1606+
``PeriodIndex`` has a custom ``period`` dtype. This is a pandas extension
1607+
dtype similar to the timezone aware dtype (``datetime64[ns, tz]``).
1608+
1609+
The ``period`` dtype holds the ``freq`` attribute and is represented with
1610+
``period[freq]``, using :ref:`frequency strings <timeseries.offset_aliases>`.
1611+
1612+
.. ipython:: python
1613+
1614+
pi = pd.period_range('2016-01-01', periods=3, freq='M')
1615+
pi
1616+
pi.dtype
1617+
1618+
The ``period`` dtype can be used in ``.astype(...)``. It allows to change the
1619+
``freq`` of a ``PeriodIndex`` like ``.asfreq()`` and convert a
1620+
``DatetimeIndex`` to ``PeriodIndex`` like ``to_period()``:
1621+
1622+
.. ipython:: python
1623+
1624+
# change monthly freq to daily freq
1625+
pi.astype('period[D]')
1626+
1627+
# convert to PeriodIndex
1628+
dti = pd.date_range('2011-01-01', freq='M', periods=3)
1629+
dti
1630+
dti.astype('period[M]')
1631+
1632+
15991633
PeriodIndex Partial String Indexing
16001634
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16011635

@@ -2049,32 +2083,3 @@ a convert on an aware stamp.
20492083
.. ipython:: python
20502084
20512085
pd.Series(s_aware.values).dt.tz_localize('UTC').dt.tz_convert('US/Eastern')
2052-
2053-
.. _timeseries.period_dtype:
2054-
2055-
Period Dtypes
2056-
~~~~~~~~~~~~~
2057-
2058-
.. versionadded:: 0.19.0
2059-
2060-
``PeriodIndex`` has its own ``period`` dtype. ``period`` dtype is a
2061-
pandas extension dtype as the same as timezone aware dtype, ``datetime64[ns, tz]``.
2062-
2063-
``period`` dtype is represented with a ``period[freq]``, using :ref:`frequency strings <timeseries.offset_aliases>`.
2064-
2065-
.. ipython:: python
2066-
2067-
pi = pd.period_range('2016-01-01', periods=3, freq='M')
2068-
pi
2069-
2070-
``period`` dtype can be used in ``.astype(...)``. It allows change ``freq`` of ``PeriodIndex`` as the same as ``.asfreq()`` and convert ``DatetimeIndex`` to ``PeriodIndex`` like ``to_period()``.
2071-
2072-
.. ipython:: python
2073-
2074-
# change monthly freq to daily freq
2075-
pi.astype('period[D]')
2076-
2077-
# convert to PeriodIndex
2078-
dti = pd.date_range('2011-01-01', freq='M', periods=3)
2079-
dti
2080-
dti.astype('period[M]')

doc/source/whatsnew/v0.19.0.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,22 @@ Furthermore:
633633
``PeriodIndex`` now has ``period`` dtype
634634
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
635635

636-
``PeriodIndex`` now has its own ``period`` dtype. ``period`` dtype is a
637-
pandas extension dtype which extends NumPy dtype like ``"category"``. (:issue:`13941`)
636+
``PeriodIndex`` now has its own ``period`` dtype. The ``period`` dtype is a
637+
pandas extension dtype which extends NumPy dtype like ``"category"`` (:issue:`13941`).
638+
As a consequence of this change, `PeriodIndex` no longer has an integer dtype:
638639

639640
Previous Behavior:
640641

641642
.. code-block:: ipython
642643

643644
In [1]: pi = pd.PeriodIndex(['2016-08-01'], freq='D')
645+
644646
In [2]: pi
645647
Out[2]: PeriodIndex(['2016-08-01'], dtype='int64', freq='D')
648+
646649
In [3]: pd.api.types.is_integer_dtype(pi)
647650
Out[3]: True
651+
648652
In [4]: pi.dtype
649653
Out[4]: dtype('int64')
650654

@@ -656,7 +660,6 @@ New Behavior:
656660
pi
657661
pd.api.types.is_integer_dtype(pi)
658662
pd.api.types.is_period_dtype(pi)
659-
660663
pi.dtype
661664
type(pi.dtype)
662665

0 commit comments

Comments
 (0)