在试图将数据集存放在按区域分类的档案中,以将其上载到HuggingFace I ve时遇到了一种奇怪的现象:在将50-byte阵列作为一栏时,文档尺寸在>
这里的《 code法》表明:
import os
import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
tmp_dir = os.path.expanduser("~/tmp/pq") # directory for example files to be stored
n_bytes = 50
n_records = 4096 * 126
np_rng = np.random.default_rng(1)
array = np.frombuffer(
np_rng.bytes(n_bytes * n_records), dtype=np.dtype((np.bytes_, n_bytes)))
table_byte_array = pa.Table.from_pydict({ byte_data : array})
pq.write_table(table_byte_array, f {tmp_dir}/byte_array_example.parquet )
table_fixed_len_byte_array = pa.Table.from_pydict(
{ byte_data : array},
schema=pa.schema([
pa.field( byte_data , pa.binary(array.itemsize), nullable=False)]))
pq.write_table(
table_fixed_len_byte_array,
f {tmp_dir}/fixed_len_byte_array_example.parquet )
file_sizes = []
for name in [ byte_array , fixed_len_byte_array ]:
filename = f {tmp_dir}/{name}_example.parquet
table = pq.read_table(filename)
file_size = os.path.getsize(filename)
file_sizes.append(file_size)
print(f {name}: {table.schema.field("byte_data").type} {file_size} )
print(
f size ratio: {file_sizes[1] / file_sizes[0]:.3f};
f size diff: {file_sizes[1] - file_sizes[0]} )
文件:
byte_array: binary 25493170
fixed_len_byte_array: fixed_size_binary[50] 25850348
size ratio: 1.014; size diff: 357178
这似乎非常具有反面性:没有固定长度(即储存较少数据)导致档案规模扩大。 为什么情况如此?
用于上述测试的系统:Ubraham 22,04.4 LTS;3,10.11;pyarrow edition 12.0.1(使用12.0.1)。 在研究<代码>pqrs schema <name>_example.parquet -detailed的产出时,请参看<编码>encoding。 两卷:<代码>编码:编码 RLE_DITION PLAIN RLE PLAIN。