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

Function test_chunked_array_asarray

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

Source from the content-addressed store, hash-verified

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