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

Function _check_array_roundtrip

python/pyarrow/tests/test_pandas.py:143–164  ·  view source on GitHub ↗
(values, expected=None, mask=None,
                           type=None)

Source from the content-addressed store, hash-verified

141
142
143def _check_array_roundtrip(values, expected=None, mask=None,
144 type=None):
145 arr = pa.array(values, from_pandas=True, mask=mask, type=type)
146 result = arr.to_pandas()
147
148 values_nulls = pd.isnull(values)
149 if mask is None:
150 assert arr.null_count == values_nulls.sum()
151 else:
152 assert arr.null_count == (mask | values_nulls).sum()
153
154 if expected is None:
155 if mask is None:
156 expected = pd.Series(values)
157 else:
158 expected = pd.Series(values).copy()
159 expected[mask.copy()] = None
160
161 if expected.dtype == 'object':
162 expected = expected.replace({np.nan: None})
163
164 tm.assert_series_equal(pd.Series(result), expected, check_names=False)
165
166
167def _check_array_from_pandas_roundtrip(np_array, type=None):

Callers 11

test_boolean_to_intMethod · 0.85
test_column_of_arraysMethod · 0.85
test_column_of_listsMethod · 0.85
test_from_tuplesMethod · 0.85
test_empty_arraysMethod · 0.85
test_categoryMethod · 0.85

Calls 4

copyMethod · 0.80
arrayMethod · 0.45
isnullMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected