Skip to content

Commit a635649

Browse files
committed
update doc examples
1 parent dcb7931 commit a635649

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pandas/core/arrays/array_.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22

3-
from pandas.core.dtypes.dtypes import registry
43
from pandas.core.dtypes.common import is_extension_array_dtype
4+
from pandas.core.dtypes.dtypes import registry
55
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
66

77

@@ -32,12 +32,29 @@ def array(data, dtype=None, copy=False):
3232
3333
Examples
3434
--------
35+
If a dtype is not specified, `data` is passed through to
36+
:meth:`numpy.array`, and an ndarray is returned.
37+
3538
>>> pd.array([1, 2])
3639
array([1, 2])
3740
41+
Or the NumPy dtype can be specified
42+
43+
>>> pd.array([1, 2], dtype=np.int32)
44+
array([1, 2], dtype=int32)
45+
46+
You can use the string alias for `dtype`
47+
3848
>>> pd.array(['a', 'b', 'a'], dtype='category')
3949
[a, b, a]
4050
Categories (2, object): [a, b]
51+
52+
Or specify the actual dtype
53+
54+
>>> pd.array(['a', 'b', 'a'],
55+
... dtype=pd.CategoricalDtype(['a', 'b', 'c'], ordered=True))
56+
[a, b, a]
57+
Categories (3, object): [a < b < c]
4158
"""
4259
if isinstance(data, (ABCSeries, ABCIndexClass)):
4360
data = data._values

0 commit comments

Comments
 (0)