MCPcopy Create free account
hub / github.com/apache/arrow / test_chunked_array_asarray

Function test_chunked_array_asarray

python/pyarrow/tests/test_table.py:425–462  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

423@pytest.mark.pandas
424@pytest.mark.nopandas
425def test_chunked_array_asarray():
426 # ensure this is tested both when pandas is present or not (ARROW-6564)
427
428 data = [
429 pa.array([0]),
430 pa.array([1, 2, 3])
431 ]
432 chunked_arr = pa.chunked_array(data)
433
434 np_arr = np.asarray(chunked_arr)
435 assert np_arr.tolist() == [0, 1, 2, 3]
436 assert np_arr.dtype == np.dtype('int64')
437
438 # An optional type can be specified when calling np.asarray
439 np_arr = np.asarray(chunked_arr, dtype='str')
440 assert np_arr.tolist() == ['0', '1', '2', '3']
441
442 # Types are modified when there are nulls
443 data = [
444 pa.array([1, None]),
445 pa.array([1, 2, 3])
446 ]
447 chunked_arr = pa.chunked_array(data)
448
449 np_arr = np.asarray(chunked_arr)
450 elements = np_arr.tolist()
451 assert elements[0] == 1.
452 assert np.isnan(elements[1])
453 assert elements[2:] == [1., 2., 3.]
454 assert np_arr.dtype == np.dtype('float64')
455
456 # DictionaryType data will be converted to dense numpy array
457 arr = pa.DictionaryArray.from_arrays(
458 pa.array([0, 1, 2, 0, 1]), pa.array(['a', 'b', 'c']))
459 chunked_arr = pa.chunked_array([arr, arr])
460 np_arr = np.asarray(chunked_arr)
461 assert np_arr.dtype == np.dtype('object')
462 assert np_arr.tolist() == ['a', 'b', 'c', 'a', 'b'] * 2
463
464
465def test_chunked_array_flatten():

Callers

nothing calls this directly

Calls 3

chunked_arrayMethod · 0.80
dtypeMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected