@@ -23,7 +23,8 @@ def array(data, # type: Sequence[object]
23
23
----------
24
24
data : Sequence of objects
25
25
The scalars inside `data` should be instances of the
26
- scalar type for `dtype`.
26
+ scalar type for `dtype`. It's expected that `data`
27
+ represents a 1-dimensional array of data.
27
28
28
29
When `data` is an Index or Series, the underlying array
29
30
will be extracted from `data`.
@@ -81,6 +82,11 @@ def array(data, # type: Sequence[object]
81
82
-------
82
83
array : Union[numpy.ndarray, ExtensionArray]
83
84
85
+ Raises
86
+ ------
87
+ ValueError
88
+ When `data` is not 1-dimensional.
89
+
84
90
See Also
85
91
--------
86
92
numpy.array : Construct a NumPy array.
@@ -134,14 +140,23 @@ def array(data, # type: Sequence[object]
134
140
the dtype:
135
141
136
142
>>> pd.array([1, 2, np.nan], dtype='Int64')
137
- IntegerArray([1, 2, nan], dtype='Int64')
143
+ <IntegerArray>
144
+ [1, 2, NaN]
145
+ Length: 3, dtype: Int64
138
146
139
147
Pandas will infer an ExtensionArray for some types of data:
140
148
141
149
>>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])
142
150
<PeriodArray>
143
151
['2000-01-01', '2000-01-01']
144
152
Length: 2, dtype: period[D]
153
+
154
+ A ValueError is raised when the input has the wrong dimensionality.
155
+
156
+ >>> pd.array(1)
157
+ Traceback (most recent call last):
158
+ ...
159
+ ValueError: Cannot pass scalar '1' to 'pandas.array'.
145
160
"""
146
161
from pandas .core .arrays import (
147
162
period_array , ExtensionArray , IntervalArray
0 commit comments