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

Function alltypes_sample

python/pyarrow/tests/parquet/common.py:147–179  ·  view source on GitHub ↗
(size=10000, seed=0, categorical=False)

Source from the content-addressed store, hash-verified

145
146
147def alltypes_sample(size=10000, seed=0, categorical=False):
148 import pandas as pd
149
150 np.random.seed(seed)
151 arrays = {
152 'uint8': np.arange(size, dtype=np.uint8),
153 'uint16': np.arange(size, dtype=np.uint16),
154 'uint32': np.arange(size, dtype=np.uint32),
155 'uint64': np.arange(size, dtype=np.uint64),
156 'int8': np.arange(size, dtype=np.int16),
157 'int16': np.arange(size, dtype=np.int16),
158 'int32': np.arange(size, dtype=np.int32),
159 'int64': np.arange(size, dtype=np.int64),
160 'float16': np.arange(size, dtype=np.float16),
161 'float32': np.arange(size, dtype=np.float32),
162 'float64': np.arange(size, dtype=np.float64),
163 'bool': np.random.randn(size) > 0,
164 'datetime_ms': np.arange("2016-01-01T00:00:00.001", size,
165 dtype='datetime64[ms]'),
166 'datetime_us': np.arange("2016-01-01T00:00:00.000001", size,
167 dtype='datetime64[us]'),
168 'datetime_ns': np.arange("2016-01-01T00:00:00.000000001", size,
169 dtype='datetime64[ns]'),
170 'timedelta': np.arange(0, size, dtype="timedelta64[s]"),
171 'str': pd.Series([str(x) for x in range(size)]),
172 'empty_str': [''] * size,
173 'str_with_nulls': [None] + [str(x) for x in range(size - 2)] + [None],
174 'null': [None] * size,
175 'null_list': [None] * 2 + [[None] * (x % 4) for x in range(size - 2)],
176 }
177 if categorical:
178 arrays['str_category'] = arrays['str'].astype('category')
179 return pd.DataFrame(arrays)

Calls

no outgoing calls