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