|
22 | 22 | np.array([True, False], dtype=bool),
|
23 | 23 | np.array([0, 1], dtype="datetime64[ns]"),
|
24 | 24 | np.array([0, 1], dtype="timedelta64[ns]"),
|
25 |
| - ] |
| 25 | + ], |
26 | 26 | )
|
27 | 27 | def any_numpy_array(request):
|
28 | 28 | """
|
29 | 29 | Parametrized fixture for NumPy arrays with different dtypes.
|
30 | 30 |
|
31 | 31 | This excludes string and bytes.
|
32 | 32 | """
|
33 |
| - return request.param |
| 33 | + return request.param.copy() |
34 | 34 |
|
35 | 35 |
|
36 | 36 | # ----------------------------------------------------------------------------
|
@@ -323,3 +323,30 @@ def test_factorize_unsigned():
|
323 | 323 | tm.assert_numpy_array_equal(res_codes, exp_codes)
|
324 | 324 |
|
325 | 325 | tm.assert_extension_array_equal(res_unique, NumpyExtensionArray(exp_unique))
|
| 326 | + |
| 327 | + |
| 328 | +# ---------------------------------------------------------------------------- |
| 329 | +# Output formatting |
| 330 | + |
| 331 | + |
| 332 | +def test_array_repr(any_numpy_array): |
| 333 | + # GH#61085 |
| 334 | + nparray = any_numpy_array |
| 335 | + arr = NumpyExtensionArray(nparray) |
| 336 | + if nparray.dtype == "object": |
| 337 | + values = "['a', 'b']" |
| 338 | + elif nparray.dtype == "float64": |
| 339 | + values = "[0.0, 1.0]" |
| 340 | + elif str(nparray.dtype).startswith("int"): |
| 341 | + values = "[0, 1]" |
| 342 | + elif nparray.dtype == "complex128": |
| 343 | + values = "[0j, (1+2j)]" |
| 344 | + elif nparray.dtype == "bool": |
| 345 | + values = "[True, False]" |
| 346 | + elif nparray.dtype == "datetime64[ns]": |
| 347 | + values = "[1970-01-01T00:00:00.000000000, 1970-01-01T00:00:00.000000001]" |
| 348 | + elif nparray.dtype == "timedelta64[ns]": |
| 349 | + values = "[0 nanoseconds, 1 nanoseconds]" |
| 350 | + expected = f"<NumpyExtensionArray>\n{values}\nLength: 2, dtype: {nparray.dtype}" |
| 351 | + result = repr(arr) |
| 352 | + assert result == expected, f"{result} vs {expected}" |
0 commit comments