Skip to content

Commit

Permalink
Update ArrowWriter._build_writer
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvillanova committed Nov 10, 2021
1 parent 38c80cc commit 7787985
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/datasets/arrow_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def close(self):
self.stream.close() # This also closes self.pa_writer if it is opened

def _build_writer(self, inferred_schema: pa.Schema):
schema = self.schema
inferred_features = Features.from_arrow_schema(inferred_schema)
if self._features is not None:
if self.update_features: # keep original features it they match, or update them
Expand All @@ -271,17 +272,16 @@ def _build_writer(self, inferred_schema: pa.Schema):
if inferred_field == fields[name]:
inferred_features[name] = self._features[name]
self._features = inferred_features
self._schema: pa.Schema = inferred_schema
schema: pa.Schema = inferred_schema
else:
self._features = inferred_features
self._schema: pa.Schema = inferred_schema
schema: pa.Schema = inferred_schema
if self.disable_nullable:
self._schema = pa.schema(pa.field(field.name, field.type, nullable=False) for field in self._schema)
schema = pa.schema(pa.field(field.name, field.type, nullable=False) for field in schema)
if self.with_metadata:
self._schema = self._schema.with_metadata(
self._build_metadata(DatasetInfo(features=self._features), self.fingerprint)
)
self.pa_writer = pa.RecordBatchStreamWriter(self.stream, self._schema)
schema = schema.with_metadata(self._build_metadata(DatasetInfo(features=self._features), self.fingerprint))
self._schema = schema
self.pa_writer = pa.RecordBatchStreamWriter(self.stream, schema)

@property
def schema(self):
Expand Down

1 comment on commit 7787985

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show benchmarks

PyArrow==3.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.060234 / 0.011353 (0.048881) 0.004321 / 0.011008 (-0.006687) 0.030192 / 0.038508 (-0.008316) 0.031112 / 0.023109 (0.008003) 0.278888 / 0.275898 (0.002990) 0.305451 / 0.323480 (-0.018029) 0.066848 / 0.007986 (0.058863) 0.004843 / 0.004328 (0.000515) 0.008419 / 0.004250 (0.004169) 0.033606 / 0.037052 (-0.003446) 0.279572 / 0.258489 (0.021083) 0.316955 / 0.293841 (0.023114) 0.082662 / 0.128546 (-0.045884) 0.011252 / 0.075646 (-0.064395) 0.250828 / 0.419271 (-0.168444) 0.046824 / 0.043533 (0.003292) 0.297364 / 0.255139 (0.042225) 0.313601 / 0.283200 (0.030402) 0.075169 / 0.141683 (-0.066514) 1.674544 / 1.452155 (0.222390) 1.620499 / 1.492716 (0.127783)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.243492 / 0.018006 (0.225485) 0.463986 / 0.000490 (0.463496) 0.005318 / 0.000200 (0.005118) 0.000138 / 0.000054 (0.000083)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.033975 / 0.037411 (-0.003436) 0.023087 / 0.014526 (0.008561) 0.024922 / 0.176557 (-0.151635) 0.175821 / 0.737135 (-0.561314) 0.025907 / 0.296338 (-0.270431)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.522445 / 0.215209 (0.307236) 5.472551 / 2.077655 (3.394896) 2.063695 / 1.504120 (0.559575) 1.654770 / 1.541195 (0.113575) 1.698110 / 1.468490 (0.229619) 0.597301 / 4.584777 (-3.987476) 5.775371 / 3.745712 (2.029659) 4.247697 / 5.269862 (-1.022164) 1.244287 / 4.565676 (-3.321389) 0.066216 / 0.424275 (-0.358059) 0.010201 / 0.007607 (0.002594) 0.669567 / 0.226044 (0.443522) 6.603647 / 2.268929 (4.334718) 2.516356 / 55.444624 (-52.928268) 1.914255 / 6.876477 (-4.962222) 1.934219 / 2.142072 (-0.207853) 0.745764 / 4.805227 (-4.059464) 0.146913 / 6.500664 (-6.353751) 0.055575 / 0.075469 (-0.019894)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.508513 / 1.841788 (-0.333275) 11.362353 / 8.074308 (3.288045) 37.460920 / 10.191392 (27.269528) 0.716010 / 0.680424 (0.035586) 0.509320 / 0.534201 (-0.024881) 0.371421 / 0.579283 (-0.207862) 0.608229 / 0.434364 (0.173865) 0.269803 / 0.540337 (-0.270535) 0.279427 / 1.386936 (-1.107509)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.065534 / 0.011353 (0.054181) 0.003795 / 0.011008 (-0.007213) 0.028825 / 0.038508 (-0.009683) 0.029363 / 0.023109 (0.006253) 0.282205 / 0.275898 (0.006307) 0.323598 / 0.323480 (0.000118) 0.069216 / 0.007986 (0.061231) 0.004963 / 0.004328 (0.000635) 0.006998 / 0.004250 (0.002747) 0.029854 / 0.037052 (-0.007198) 0.293819 / 0.258489 (0.035329) 0.336768 / 0.293841 (0.042928) 0.084695 / 0.128546 (-0.043852) 0.010871 / 0.075646 (-0.064775) 0.249222 / 0.419271 (-0.170050) 0.051346 / 0.043533 (0.007814) 0.281585 / 0.255139 (0.026446) 0.311383 / 0.283200 (0.028184) 0.072598 / 0.141683 (-0.069085) 1.584941 / 1.452155 (0.132787) 1.657413 / 1.492716 (0.164697)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.272309 / 0.018006 (0.254302) 0.510863 / 0.000490 (0.510373) 0.006114 / 0.000200 (0.005914) 0.000640 / 0.000054 (0.000585)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.033726 / 0.037411 (-0.003686) 0.021538 / 0.014526 (0.007012) 0.026579 / 0.176557 (-0.149978) 0.184317 / 0.737135 (-0.552818) 0.027972 / 0.296338 (-0.268367)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.550065 / 0.215209 (0.334856) 5.513167 / 2.077655 (3.435512) 2.057757 / 1.504120 (0.553637) 1.730866 / 1.541195 (0.189671) 1.754236 / 1.468490 (0.285746) 0.608602 / 4.584777 (-3.976175) 5.816007 / 3.745712 (2.070295) 2.526562 / 5.269862 (-2.743300) 1.256571 / 4.565676 (-3.309106) 0.070352 / 0.424275 (-0.353923) 0.011509 / 0.007607 (0.003902) 0.713559 / 0.226044 (0.487515) 6.764024 / 2.268929 (4.495096) 2.693161 / 55.444624 (-52.751464) 2.098666 / 6.876477 (-4.777811) 2.212530 / 2.142072 (0.070457) 0.904604 / 4.805227 (-3.900624) 0.174995 / 6.500664 (-6.325669) 0.064516 / 0.075469 (-0.010953)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.537916 / 1.841788 (-0.303872) 11.324383 / 8.074308 (3.250075) 37.823694 / 10.191392 (27.632302) 0.862082 / 0.680424 (0.181658) 0.543439 / 0.534201 (0.009238) 0.379941 / 0.579283 (-0.199342) 0.608064 / 0.434364 (0.173700) 0.268571 / 0.540337 (-0.271766) 0.282113 / 1.386936 (-1.104823)

CML watermark

Please sign in to comment.