|
1 | 1 | import numpy as np
|
2 | 2 |
|
3 |
| -from pandas.core.dtypes.dtypes import registry |
4 | 3 | from pandas.core.dtypes.common import is_extension_array_dtype
|
| 4 | +from pandas.core.dtypes.dtypes import registry |
5 | 5 | from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
|
6 | 6 |
|
7 | 7 |
|
@@ -32,12 +32,29 @@ def array(data, dtype=None, copy=False):
|
32 | 32 |
|
33 | 33 | Examples
|
34 | 34 | --------
|
| 35 | + If a dtype is not specified, `data` is passed through to |
| 36 | + :meth:`numpy.array`, and an ndarray is returned. |
| 37 | +
|
35 | 38 | >>> pd.array([1, 2])
|
36 | 39 | array([1, 2])
|
37 | 40 |
|
| 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 | +
|
38 | 48 | >>> pd.array(['a', 'b', 'a'], dtype='category')
|
39 | 49 | [a, b, a]
|
40 | 50 | 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] |
41 | 58 | """
|
42 | 59 | if isinstance(data, (ABCSeries, ABCIndexClass)):
|
43 | 60 | data = data._values
|
|
0 commit comments