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

Method test_strided_data_import

python/pyarrow/tests/test_pandas.py:3169–3210  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3167 pa.Table.from_pandas(df)
3168
3169 def test_strided_data_import(self):
3170 cases = []
3171
3172 columns = ['a', 'b', 'c']
3173 N, K = 100, 3
3174 random_numbers = np.random.randn(N, K).copy() * 100
3175
3176 numeric_dtypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8',
3177 'f4', 'f8']
3178
3179 for type_name in numeric_dtypes:
3180 # Casting np.float64 -> uint32 or uint64 throws a RuntimeWarning
3181 with warnings.catch_warnings():
3182 warnings.simplefilter("ignore")
3183 cases.append(random_numbers.astype(type_name))
3184
3185 # strings
3186 cases.append(np.array([random_ascii(10) for i in range(N * K)],
3187 dtype=object)
3188 .reshape(N, K).copy())
3189
3190 # booleans
3191 boolean_objects = (np.array([True, False, True] * N, dtype=object)
3192 .reshape(N, K).copy())
3193
3194 # add some nulls, so dtype comes back as objects
3195 boolean_objects[5] = None
3196 cases.append(boolean_objects)
3197
3198 cases.append(np.arange("2016-01-01T00:00:00.001", N * K,
3199 dtype='datetime64[ms]')
3200 .reshape(N, K).copy())
3201
3202 strided_mask = (random_numbers > 0).astype(bool)[:, 0]
3203
3204 for case in cases:
3205 df = pd.DataFrame(case, columns=columns)
3206 col = df['a']
3207
3208 _check_pandas_roundtrip(df)
3209 _check_array_roundtrip(col)
3210 _check_array_roundtrip(col, mask=strided_mask)
3211
3212 def test_all_nones(self):
3213 def _check_series(s):

Callers

nothing calls this directly

Calls 6

random_asciiFunction · 0.90
_check_array_roundtripFunction · 0.85
copyMethod · 0.80
_check_pandas_roundtripFunction · 0.70
appendMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected