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

Function _check_array_roundtrip

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

Source from the content-addressed store, hash-verified

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