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

Method test_strided_data_import

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

Source from the content-addressed store, hash-verified

3147 pa.Table.from_pandas(df)
3148
3149 def test_strided_data_import(self):
3150 cases = []
3151
3152 columns = ['a', 'b', 'c']
3153 N, K = 100, 3
3154 random_numbers = np.random.randn(N, K).copy() * 100
3155
3156 numeric_dtypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8',
3157 'f4', 'f8']
3158
3159 for type_name in numeric_dtypes:
3160 # Casting np.float64 -> uint32 or uint64 throws a RuntimeWarning
3161 with warnings.catch_warnings():
3162 warnings.simplefilter("ignore")
3163 cases.append(random_numbers.astype(type_name))
3164
3165 # strings
3166 cases.append(np.array([random_ascii(10) for i in range(N * K)],
3167 dtype=object)
3168 .reshape(N, K).copy())
3169
3170 # booleans
3171 boolean_objects = (np.array([True, False, True] * N, dtype=object)
3172 .reshape(N, K).copy())
3173
3174 # add some nulls, so dtype comes back as objects
3175 boolean_objects[5] = None
3176 cases.append(boolean_objects)
3177
3178 cases.append(np.arange("2016-01-01T00:00:00.001", N * K,
3179 dtype='datetime64[ms]')
3180 .reshape(N, K).copy())
3181
3182 strided_mask = (random_numbers > 0).astype(bool)[:, 0]
3183
3184 for case in cases:
3185 df = pd.DataFrame(case, columns=columns)
3186 col = df['a']
3187
3188 _check_pandas_roundtrip(df)
3189 _check_array_roundtrip(col)
3190 _check_array_roundtrip(col, mask=strided_mask)
3191
3192 def test_all_nones(self):
3193 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