From 698fb83034801ba719e16cafd756c013729a10d2 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Wed, 1 Jan 2025 12:05:59 +1100 Subject: [PATCH] refactor!: rename binary data type to bytes (#118) closes #114 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- zarrs/doc/status/data_types.md | 4 ++-- zarrs/src/array/codec/array_to_bytes/bytes.rs | 4 ++-- zarrs/src/array/data_type.rs | 14 +++++++------- zarrs/src/array/element.rs | 2 +- zarrs/tests/array_sync.rs | 2 +- zarrs_metadata/CHANGELOG.md | 3 +++ zarrs_metadata/Cargo.toml | 2 +- zarrs_metadata/src/v3/array/data_type.rs | 8 ++++---- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 536f5b81..08437eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking**: Make `{Array,Bytes}PartialDecoderCache` private - **Breaking**: Make `Any` a supertrait of partial encoder/decoder traits - **Breaking**: Add `ArrayError::UnsupportedMethod` +- **Breaking**: Rename `DataType::Binary` to `Bytes` for compatibility with `zarr-python` +- **Breaking**: Make `array::codec::array_to_bytes::bytes::reverse_endianness` private ### Fixed - Cleanup unnecessary lifetime constraints in partial decoders diff --git a/Cargo.toml b/Cargo.toml index 6b7dbe64..1f8d50c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ missing_panics_doc = "warn" missing_errors_doc = "warn" [workspace.dependencies.zarrs_metadata] -version = "0.2.0" +version = "0.3.0-dev" path = "zarrs_metadata" [workspace.dependencies.zarrs_storage] diff --git a/zarrs/doc/status/data_types.md b/zarrs/doc/status/data_types.md index bf66c75a..af053bf6 100644 --- a/zarrs/doc/status/data_types.md +++ b/zarrs/doc/status/data_types.md @@ -4,7 +4,7 @@ [r* (raw bits)] | [ZEP0001] | ✓ | | | | [bfloat16] | [zarr-specs #130] | ✓ | | | | [string] (experimental) | [ZEP0007 (draft)] | ✓ | | | -| [binary] (experimental) | [ZEP0007 (draft)] | ✓ | | | +| [bytes] (experimental) | [ZEP0007 (draft)] | ✓ | | | † Experimental data types are recommended for evaluation only. @@ -25,7 +25,7 @@ [bfloat16]: crate::array::data_type::DataType::BFloat16 [r* (raw bits)]: crate::array::data_type::DataType::RawBits [string]: crate::array::data_type::DataType::String -[binary]: crate::array::data_type::DataType::Binary +[bytes]: crate::array::data_type::DataType::Bytes [ZEP0001]: https://zarr.dev/zeps/accepted/ZEP0001.html [zarr-specs #130]: https://github.com/zarr-developers/zarr-specs/issues/130 diff --git a/zarrs/src/array/codec/array_to_bytes/bytes.rs b/zarrs/src/array/codec/array_to_bytes/bytes.rs index e6997f26..98ba7fc9 100644 --- a/zarrs/src/array/codec/array_to_bytes/bytes.rs +++ b/zarrs/src/array/codec/array_to_bytes/bytes.rs @@ -47,7 +47,7 @@ pub(crate) fn create_codec_bytes(metadata: &MetadataV3) -> Result {} DataType::Int16 | DataType::UInt16 | DataType::Float16 | DataType::BFloat16 => { @@ -72,7 +72,7 @@ pub fn reverse_endianness(v: &mut [u8], data_type: &DataType) { v.chunks_exact_mut(8).for_each(swap); } // Variable-sized data types are not supported and are rejected outside of this function - DataType::String | DataType::Binary => unreachable!(), + DataType::String | DataType::Bytes => unreachable!(), } } diff --git a/zarrs/src/array/data_type.rs b/zarrs/src/array/data_type.rs index 315d10a6..478a8907 100644 --- a/zarrs/src/array/data_type.rs +++ b/zarrs/src/array/data_type.rs @@ -56,7 +56,7 @@ pub enum DataType { /// A UTF-8 encoded string. String, /// Variable-sized binary data. - Binary, + Bytes, } /// An unsupported data type error. @@ -104,7 +104,7 @@ impl DataType { Self::Complex128 => "complex128", Self::RawBits(_usize) => "r*", Self::String => "string", - Self::Binary => "binary", + Self::Bytes => "bytes", // Self::Extension(extension) => extension.identifier(), } } @@ -140,7 +140,7 @@ impl DataType { Self::Complex128 => DataTypeMetadataV3::Complex128, Self::RawBits(size) => DataTypeMetadataV3::RawBits(*size), Self::String => DataTypeMetadataV3::String, - Self::Binary => DataTypeMetadataV3::Binary, + Self::Bytes => DataTypeMetadataV3::Bytes, } } @@ -154,7 +154,7 @@ impl DataType { Self::Int64 | Self::UInt64 | Self::Float64 | Self::Complex64 => DataTypeSize::Fixed(8), Self::Complex128 => DataTypeSize::Fixed(16), Self::RawBits(size) => DataTypeSize::Fixed(*size), - Self::String | Self::Binary => DataTypeSize::Variable, + Self::String | Self::Bytes => DataTypeSize::Variable, // Self::Extension(extension) => extension.size(), } } @@ -192,7 +192,7 @@ impl DataType { DataTypeMetadataV3::Complex128 => Ok(Self::Complex128), DataTypeMetadataV3::RawBits(size) => Ok(Self::RawBits(*size)), DataTypeMetadataV3::String => Ok(Self::String), - DataTypeMetadataV3::Binary => Ok(Self::Binary), + DataTypeMetadataV3::Bytes => Ok(Self::Bytes), DataTypeMetadataV3::Unknown(metadata) => { Err(UnsupportedDataTypeError(metadata.to_string())) } @@ -241,7 +241,7 @@ impl DataType { } Err(err()) } - Self::Binary => { + Self::Bytes => { if let FillValueMetadataV3::ByteArray(bytes) = fill_value { Ok(FillValue::new(bytes.clone())) } else { @@ -329,7 +329,7 @@ impl DataType { Self::String => FillValueMetadataV3::String( String::from_utf8(fill_value.as_ne_bytes().to_vec()).unwrap(), ), - Self::Binary => FillValueMetadataV3::ByteArray(fill_value.as_ne_bytes().to_vec()), + Self::Bytes => FillValueMetadataV3::ByteArray(fill_value.as_ne_bytes().to_vec()), } } } diff --git a/zarrs/src/array/element.rs b/zarrs/src/array/element.rs index c57dfafb..c28c8612 100644 --- a/zarrs/src/array/element.rs +++ b/zarrs/src/array/element.rs @@ -221,7 +221,7 @@ macro_rules! impl_element_binary { ($raw_type:ty) => { impl Element for $raw_type { fn validate_data_type(data_type: &DataType) -> Result<(), ArrayError> { - (data_type == &DataType::Binary).then_some(()).ok_or(IET) + (data_type == &DataType::Bytes).then_some(()).ok_or(IET) } fn into_array_bytes<'a>( diff --git a/zarrs/tests/array_sync.rs b/zarrs/tests/array_sync.rs index 52691c7d..85a65f84 100644 --- a/zarrs/tests/array_sync.rs +++ b/zarrs/tests/array_sync.rs @@ -324,7 +324,7 @@ fn array_binary() -> Result<(), Box> { let array_path = "/array"; let mut builder = ArrayBuilder::new( vec![4, 4], // array shape - DataType::Binary, + DataType::Bytes, vec![2, 2].try_into().unwrap(), // regular chunk shape FillValue::from([]), ); diff --git a/zarrs_metadata/CHANGELOG.md b/zarrs_metadata/CHANGELOG.md index 5ef6d6d3..c8fed74b 100644 --- a/zarrs_metadata/CHANGELOG.md +++ b/zarrs_metadata/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- **Breaking**: Rename `DataTypeMetadataV3::Binary` to `Bytes` for compatibility with `zarr-python` + ## [0.2.0] - 2024-11-15 ### Added diff --git a/zarrs_metadata/Cargo.toml b/zarrs_metadata/Cargo.toml index f0e8a47c..4ad61a0c 100644 --- a/zarrs_metadata/Cargo.toml +++ b/zarrs_metadata/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zarrs_metadata" -version = "0.2.0" +version = "0.3.0-dev" authors = ["Lachlan Deakin "] edition = "2021" rust-version = "1.77" diff --git a/zarrs_metadata/src/v3/array/data_type.rs b/zarrs_metadata/src/v3/array/data_type.rs index 5a540105..ffbbfeb4 100644 --- a/zarrs_metadata/src/v3/array/data_type.rs +++ b/zarrs_metadata/src/v3/array/data_type.rs @@ -46,7 +46,7 @@ pub enum DataTypeMetadataV3 { /// A UTF-8 encoded string. String, /// Variable-sized binary data. - Binary, + Bytes, /// An unknown data type. Unknown(MetadataV3), } @@ -105,7 +105,7 @@ impl DataTypeMetadataV3 { Self::Complex64 => "complex64".to_string(), Self::Complex128 => "complex128".to_string(), Self::String => "string".to_string(), - Self::Binary => "binary".to_string(), + Self::Bytes => "bytes".to_string(), Self::RawBits(size) => format!("r{}", size * 8), Self::Unknown(metadata) => metadata.name().to_string(), } @@ -134,7 +134,7 @@ impl DataTypeMetadataV3 { } Self::Complex128 => Some(DataTypeSize::Fixed(16)), Self::RawBits(size) => Some(DataTypeSize::Fixed(*size)), - Self::String | Self::Binary => Some(DataTypeSize::Variable), + Self::String | Self::Bytes => Some(DataTypeSize::Variable), Self::Unknown(_) => None, } } @@ -170,7 +170,7 @@ impl DataTypeMetadataV3 { "complex64" => return Self::Complex64, "complex128" => return Self::Complex128, "string" => return Self::String, - "binary" => return Self::Binary, + "bytes" => return Self::Bytes, _ => {} };