Skip to content

Commit c7d0d27

Browse files
authored
DOC: Improve reference/arrays.rst (pandas-dev#45189)
* DOC: Improve reference.arrays.rst * Fix NaT docstrings
1 parent 46ddb8e commit c7d0d27

File tree

5 files changed

+82
-24
lines changed

5 files changed

+82
-24
lines changed

doc/source/reference/arrays.rst

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
.. _api.arrays:
44

5-
=============
6-
pandas arrays
7-
=============
5+
======================================
6+
pandas arrays, scalars, and data types
7+
======================================
88

99
.. currentmodule:: pandas
1010

@@ -141,11 +141,11 @@ Methods
141141
Timestamp.weekday
142142

143143
A collection of timestamps may be stored in a :class:`arrays.DatetimeArray`.
144-
For timezone-aware data, the ``.dtype`` of a ``DatetimeArray`` is a
144+
For timezone-aware data, the ``.dtype`` of a :class:`arrays.DatetimeArray` is a
145145
:class:`DatetimeTZDtype`. For timezone-naive data, ``np.dtype("datetime64[ns]")``
146146
is used.
147147

148-
If the data are tz-aware, then every value in the array must have the same timezone.
148+
If the data are timezone-aware, then every value in the array must have the same timezone.
149149

150150
.. autosummary::
151151
:toctree: api/
@@ -206,7 +206,7 @@ Methods
206206
Timedelta.to_numpy
207207
Timedelta.total_seconds
208208

209-
A collection of timedeltas may be stored in a :class:`TimedeltaArray`.
209+
A collection of :class:`Timedelta` may be stored in a :class:`TimedeltaArray`.
210210

211211
.. autosummary::
212212
:toctree: api/
@@ -267,8 +267,8 @@ Methods
267267
Period.strftime
268268
Period.to_timestamp
269269

270-
A collection of timedeltas may be stored in a :class:`arrays.PeriodArray`.
271-
Every period in a ``PeriodArray`` must have the same ``freq``.
270+
A collection of :class:`Period` may be stored in a :class:`arrays.PeriodArray`.
271+
Every period in a :class:`arrays.PeriodArray` must have the same ``freq``.
272272

273273
.. autosummary::
274274
:toctree: api/
@@ -383,8 +383,8 @@ Categorical data
383383
----------------
384384

385385
pandas defines a custom data type for representing data that can take only a
386-
limited, fixed set of values. The dtype of a ``Categorical`` can be described by
387-
a :class:`pandas.api.types.CategoricalDtype`.
386+
limited, fixed set of values. The dtype of a :class:`Categorical` can be described by
387+
a :class:`CategoricalDtype`.
388388

389389
.. autosummary::
390390
:toctree: api/
@@ -414,7 +414,7 @@ have the categories and integer codes already:
414414

415415
Categorical.from_codes
416416

417-
The dtype information is available on the ``Categorical``
417+
The dtype information is available on the :class:`Categorical`
418418

419419
.. autosummary::
420420
:toctree: api/
@@ -425,21 +425,21 @@ The dtype information is available on the ``Categorical``
425425
Categorical.codes
426426

427427
``np.asarray(categorical)`` works by implementing the array interface. Be aware, that this converts
428-
the Categorical back to a NumPy array, so categories and order information is not preserved!
428+
the :class:`Categorical` back to a NumPy array, so categories and order information is not preserved!
429429

430430
.. autosummary::
431431
:toctree: api/
432432

433433
Categorical.__array__
434434

435-
A ``Categorical`` can be stored in a ``Series`` or ``DataFrame``.
435+
A :class:`Categorical` can be stored in a :class:`Series` or :class:`DataFrame`.
436436
To create a Series of dtype ``category``, use ``cat = s.astype(dtype)`` or
437437
``Series(..., dtype=dtype)`` where ``dtype`` is either
438438

439439
* the string ``'category'``
440-
* an instance of :class:`~pandas.api.types.CategoricalDtype`.
440+
* an instance of :class:`CategoricalDtype`.
441441

442-
If the Series is of dtype ``CategoricalDtype``, ``Series.cat`` can be used to change the categorical
442+
If the :class:`Series` is of dtype :class:`CategoricalDtype`, ``Series.cat`` can be used to change the categorical
443443
data. See :ref:`api.series.cat` for more.
444444

445445
.. _api.arrays.sparse:
@@ -488,7 +488,7 @@ we recommend using :class:`StringDtype` (with the alias ``"string"``).
488488

489489
StringDtype
490490

491-
The ``Series.str`` accessor is available for ``Series`` backed by a :class:`arrays.StringArray`.
491+
The ``Series.str`` accessor is available for :class:`Series` backed by a :class:`arrays.StringArray`.
492492
See :ref:`api.series.str` for more.
493493

494494

@@ -498,7 +498,7 @@ Boolean data with missing values
498498
--------------------------------
499499

500500
The boolean dtype (with the alias ``"boolean"``) provides support for storing
501-
boolean data (True, False values) with missing values, which is not possible
501+
boolean data (``True``, ``False``) with missing values, which is not possible
502502
with a bool :class:`numpy.ndarray`.
503503

504504
.. autosummary::

pandas/_libs/tslibs/nattype.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ class NaTType(_NaT):
623623
astimezone = _make_error_func(
624624
"astimezone",
625625
"""
626-
Convert tz-aware Timestamp to another time zone.
626+
Convert timezone-aware Timestamp to another time zone.
627627
628628
Parameters
629629
----------
@@ -1033,7 +1033,7 @@ timedelta}, default 'raise'
10331033
tz_convert = _make_nat_func(
10341034
"tz_convert",
10351035
"""
1036-
Convert tz-aware Timestamp to another time zone.
1036+
Convert timezone-aware Timestamp to another time zone.
10371037
10381038
Parameters
10391039
----------
@@ -1078,7 +1078,7 @@ timedelta}, default 'raise'
10781078
"tz_localize",
10791079
"""
10801080
Convert naive Timestamp to local time zone, or remove
1081-
timezone from tz-aware Timestamp.
1081+
timezone from timezone-aware Timestamp.
10821082
10831083
Parameters
10841084
----------

pandas/_libs/tslibs/period.pyx

+58
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,20 @@ cdef class PeriodMixin:
15711571

15721572
@property
15731573
def end_time(self) -> Timestamp:
1574+
"""
1575+
Get the Timestamp for the end of the period.
1576+
1577+
Returns
1578+
-------
1579+
Timestamp
1580+
1581+
See Also
1582+
--------
1583+
Period.start_time : Return the start Timestamp.
1584+
Period.dayofyear : Return the day of year.
1585+
Period.daysinmonth : Return the days in that month.
1586+
Period.dayofweek : Return the day of the week.
1587+
"""
15741588
return self.to_timestamp(how="end")
15751589

15761590
def _require_matching_freq(self, other, base=False):
@@ -1835,11 +1849,17 @@ cdef class _Period(PeriodMixin):
18351849

18361850
@property
18371851
def year(self) -> int:
1852+
"""
1853+
Return the year this Period falls on.
1854+
"""
18381855
base = self._dtype._dtype_code
18391856
return pyear(self.ordinal, base)
18401857

18411858
@property
18421859
def month(self) -> int:
1860+
"""
1861+
Return the month this Period falls on.
1862+
"""
18431863
base = self._dtype._dtype_code
18441864
return pmonth(self.ordinal, base)
18451865

@@ -1946,6 +1966,32 @@ cdef class _Period(PeriodMixin):
19461966

19471967
@property
19481968
def weekofyear(self) -> int:
1969+
"""
1970+
Get the week of the year on the given Period.
1971+
1972+
Returns
1973+
-------
1974+
int
1975+
1976+
See Also
1977+
--------
1978+
Period.dayofweek : Get the day component of the Period.
1979+
Period.weekday : Get the day component of the Period.
1980+
1981+
Examples
1982+
--------
1983+
>>> p = pd.Period("2018-03-11", "H")
1984+
>>> p.weekofyear
1985+
10
1986+
1987+
>>> p = pd.Period("2018-02-01", "D")
1988+
>>> p.weekofyear
1989+
5
1990+
1991+
>>> p = pd.Period("2018-01-06", "D")
1992+
>>> p.weekofyear
1993+
1
1994+
"""
19491995
base = self._dtype._dtype_code
19501996
return pweek(self.ordinal, base)
19511997

@@ -2120,6 +2166,9 @@ cdef class _Period(PeriodMixin):
21202166

21212167
@property
21222168
def quarter(self) -> int:
2169+
"""
2170+
Return the quarter this Period falls on.
2171+
"""
21232172
base = self._dtype._dtype_code
21242173
return pquarter(self.ordinal, base)
21252174

@@ -2225,14 +2274,23 @@ cdef class _Period(PeriodMixin):
22252274

22262275
@property
22272276
def is_leap_year(self) -> bool:
2277+
"""
2278+
Return True if the period's year is in a leap year.
2279+
"""
22282280
return bool(is_leapyear(self.year))
22292281

22302282
@classmethod
22312283
def now(cls, freq=None):
2284+
"""
2285+
Return the period of now's date.
2286+
"""
22322287
return Period(datetime.now(), freq=freq)
22332288

22342289
@property
22352290
def freqstr(self) -> str:
2291+
"""
2292+
Return a string representation of the frequency.
2293+
"""
22362294
return self.freq.freqstr
22372295

22382296
def __repr__(self) -> str:

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ cdef class _Timedelta(timedelta):
886886

887887
cpdef timedelta to_pytimedelta(_Timedelta self):
888888
"""
889-
Convert a pandas Timedelta object into a python timedelta object.
889+
Convert a pandas Timedelta object into a python ``datetime.timedelta`` object.
890890
891891
Timedelta objects are internally saved as numpy datetime64[ns] dtype.
892892
Use to_pytimedelta() to convert to object dtype.

pandas/_libs/tslibs/timestamps.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ cdef class _Timestamp(ABCTimestamp):
740740

741741
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str:
742742
"""
743-
Return the time formatted according to ISO.
743+
Return the time formatted according to ISO 8610.
744744

745745
The full format looks like 'YYYY-MM-DD HH:MM:SS.mmmmmmnnn'.
746746
By default, the fractional part is omitted if self.microsecond == 0
@@ -1749,7 +1749,7 @@ timedelta}, default 'raise'
17491749
def tz_localize(self, tz, ambiguous='raise', nonexistent='raise'):
17501750
"""
17511751
Convert naive Timestamp to local time zone, or remove
1752-
timezone from tz-aware Timestamp.
1752+
timezone from timezone-aware Timestamp.
17531753
17541754
Parameters
17551755
----------
@@ -1852,7 +1852,7 @@ default 'raise'
18521852

18531853
def tz_convert(self, tz):
18541854
"""
1855-
Convert tz-aware Timestamp to another time zone.
1855+
Convert timezone-aware Timestamp to another time zone.
18561856
18571857
Parameters
18581858
----------

0 commit comments

Comments
 (0)