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

Function test_array_from_numpy_unicode

python/pyarrow/tests/test_array.py:2951–2983  ·  view source on GitHub ↗
(string_type)

Source from the content-addressed store, hash-verified

2949 pa.large_utf8(),
2950 pa.string_view()])
2951def test_array_from_numpy_unicode(string_type):
2952 # Default when no type is specified should be utf8
2953 expected_type = string_type or pa.utf8()
2954
2955 dtypes = ['<U5', '>U5']
2956
2957 for dtype in dtypes:
2958 arr = np.array(['abcde', 'abc', ''], dtype=dtype)
2959
2960 arrow_arr = pa.array(arr, string_type)
2961 assert arrow_arr.type == expected_type
2962 expected = pa.array(['abcde', 'abc', ''], type=expected_type)
2963 assert arrow_arr.equals(expected)
2964
2965 mask = np.array([False, True, False])
2966 arrow_arr = pa.array(arr, string_type, mask=mask)
2967 expected = pa.array(['abcde', None, ''], type=expected_type)
2968 assert arrow_arr.equals(expected)
2969
2970 # Strided variant
2971 arr = np.array(['abcde', 'abc', ''] * 5, dtype=dtype)[::2]
2972 mask = np.array([False, True, False] * 5)[::2]
2973 arrow_arr = pa.array(arr, string_type, mask=mask)
2974
2975 expected = pa.array(['abcde', '', None, 'abcde', '', None,
2976 'abcde', ''], type=expected_type)
2977 assert arrow_arr.equals(expected)
2978
2979 # 0 itemsize
2980 arr = np.array(['', '', ''], dtype='<U0')
2981 arrow_arr = pa.array(arr, string_type)
2982 expected = pa.array(['', '', ''], type=expected_type)
2983 assert arrow_arr.equals(expected)
2984
2985
2986@pytest.fixture

Callers

nothing calls this directly

Calls 2

equalsMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected