Skip to content

Commit 349f818

Browse files
committed
update parameter name and docstring
1 parent 328338c commit 349f818

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

doc/source/api/series.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Attributes
2626
.. autosummary::
2727
:toctree: generated/
2828

29+
Series.array
2930
Series.values
3031
Series.dtype
3132
Series.ftype
@@ -58,10 +59,12 @@ Conversion
5859
Series.convert_objects
5960
Series.copy
6061
Series.bool
62+
Series.to_numpy
6163
Series.to_period
6264
Series.to_timestamp
6365
Series.to_list
6466
Series.get_values
67+
Series.__array__
6568

6669
Indexing, iteration
6770
-------------------

pandas/core/series.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,53 @@ def view(self, dtype=None):
662662
# ----------------------------------------------------------------------
663663
# NDArray Compat
664664

665-
def __array__(self, result=None):
665+
def __array__(self, dtype=None):
666666
"""
667-
The array interface, return my values.
667+
Return the values as a NumPy array.
668+
669+
Users should not call this directly. Rather, it is invoked by
670+
:func:`numpy.array` and :func:`numpy.asarray`.
671+
672+
Parameters
673+
----------
674+
dtype : str or numpy.dtype, optional
675+
The dtype to use for the resulting NumPy array. By default,
676+
the dtype is inferred from the data.
677+
678+
Returns
679+
-------
680+
numpy.ndarray
681+
The values in the series converted to a :class:`numpy.ndarary`
682+
with the specified `dtype`.
683+
684+
See Also
685+
--------
686+
Series.array : Zero-copy view to the array backing the Series.
687+
Series.to_numpy : Series method for similar behavior.
688+
689+
Examples
690+
--------
691+
>>> ser = pd.Series([1, 2, 3])
692+
>>> np.asarray(ser)
693+
array([1, 2, 3])
694+
695+
For timezone-aware data, the timezones may be retained with
696+
``dtype='object'``
697+
698+
>>> tzser = pd.Series(pd.date_range('2000', periods=2, tz="CET"))
699+
>>> np.asarray(tzser, dtype="object")
700+
array([Timestamp('2000-01-01 00:00:00+0100', tz='CET', freq='D'),
701+
Timestamp('2000-01-02 00:00:00+0100', tz='CET', freq='D')],
702+
dtype=object)
703+
704+
Or the values may be localized to UTC and the tzinfo discared with
705+
``dtype='datetime64[ns]'``
706+
707+
>>> np.asarray(tzser, dtype="datetime64[ns]") # doctest: +ELLIPSIS
708+
array(['1999-12-31T23:00:00.000000000', ...],
709+
dtype='datetime64[ns]')
668710
"""
669-
# TODO: change the keyword name from result to dtype?
670-
if (result is None and isinstance(self.array, ABCDatetimeArray)
711+
if (dtype is None and isinstance(self.array, ABCDatetimeArray)
671712
and getattr(self.dtype, 'tz', None)):
672713
msg = (
673714
"Converting timezone-aware DatetimeArray to timezone-naive "
@@ -678,8 +719,8 @@ def __array__(self, result=None):
678719
"To keep the old behavior, pass 'dtype=\"datetime64[ns]\"'."
679720
)
680721
warnings.warn(msg, FutureWarning, stacklevel=3)
681-
result = 'M8[ns]'
682-
return np.asarray(self.array, result)
722+
dtype = 'M8[ns]'
723+
return np.asarray(self.array, dtype)
683724

684725
def __array_wrap__(self, result, context=None):
685726
"""

0 commit comments

Comments
 (0)