Skip to content

Commit

Permalink
Add ArrayBuilder::from_array
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Oct 29, 2023
1 parent 8ed83bf commit a118672
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `par_` variants for the `store_array_subset`/`retrieve_array_subset` variants in `Array`, which can encode/decode multiple chunks in parallel
- Added `ArraySubset::bound` and `Array::chunk_subset_bounded`
- Added methods to `CodecChain` to retrieve underlying codecs
- Added `Array::builder()`
- Added `Array::builder()` and `ArrayBuilder::from_array()`
- Added more `ArrayBuilder` modifiers and made internals public

### Changed
Expand Down
18 changes: 1 addition & 17 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,7 @@ impl<TStorage: ?Sized> Array<TStorage> {

/// Create an array builder matching the parameters of this array
pub fn builder(&self) -> ArrayBuilder {
let mut builder = ArrayBuilder::new(
self.shape().to_vec(),
self.data_type().clone(),
self.chunk_grid().clone(),
self.fill_value().clone(),
);
builder
.additional_fields(self.additional_fields().clone())
.attributes(self.attributes().clone())
.chunk_key_encoding(self.chunk_key_encoding().clone())
.dimension_names(self.dimension_names().clone())
.parallel_codecs(self.parallel_codecs())
.array_to_array_codecs(self.codecs().array_to_array_codecs().to_vec())
.array_to_bytes_codec(self.codecs().array_to_bytes_codec().clone())
.bytes_to_bytes_codecs(self.codecs().bytes_to_bytes_codecs().to_vec())
.storage_transformers(self.storage_transformers().clone());
builder
ArrayBuilder::from_array(self)
}

/// Return the shape of the chunk grid (i.e., the number of chunks).
Expand Down
21 changes: 21 additions & 0 deletions src/array/array_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ impl ArrayBuilder {
}
}

/// Create a new builder copying the configuration of an existing array.
pub fn from_array<T: ?Sized>(array: &Array<T>) -> Self {
let mut builder = ArrayBuilder::new(
array.shape().to_vec(),
array.data_type().clone(),
array.chunk_grid().clone(),
array.fill_value().clone(),
);
builder
.additional_fields(array.additional_fields().clone())
.attributes(array.attributes().clone())
.chunk_key_encoding(array.chunk_key_encoding().clone())
.dimension_names(array.dimension_names().clone())
.parallel_codecs(array.parallel_codecs())
.array_to_array_codecs(array.codecs().array_to_array_codecs().to_vec())
.array_to_bytes_codec(array.codecs().array_to_bytes_codec().clone())
.bytes_to_bytes_codecs(array.codecs().bytes_to_bytes_codecs().to_vec())
.storage_transformers(array.storage_transformers().clone());
builder
}

/// Set the shape.
pub fn shape(&mut self, shape: ArrayShape) -> &mut Self {
self.shape = shape;
Expand Down

0 comments on commit a118672

Please sign in to comment.