Skip to content

Commit

Permalink
refactor!: rename binary data type to bytes (#118)
Browse files Browse the repository at this point in the history
closes #114
  • Loading branch information
LDeakin authored Jan 1, 2025
1 parent 6a8baed commit 698fb83
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions zarrs/doc/status/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[r* (raw bits)] | [ZEP0001] | ✓ | | |
| [bfloat16] | [zarr-specs #130] | ✓ | | |
| [string] (experimental) | [ZEP0007 (draft)] | ✓ | | |
| [binary] (experimental) | [ZEP0007 (draft)] | ✓ | | |
| [bytes] (experimental) | [ZEP0007 (draft)] | ✓ | | |

<sup>† Experimental data types are recommended for evaluation only.</sup>

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions zarrs/src/array/codec/array_to_bytes/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn create_codec_bytes(metadata: &MetadataV3) -> Result<Codec, PluginC
}

/// Reverse the endianness of bytes for a given data type.
pub fn reverse_endianness(v: &mut [u8], data_type: &DataType) {
pub(crate) fn reverse_endianness(v: &mut [u8], data_type: &DataType) {
match data_type {
DataType::Bool | DataType::Int8 | DataType::UInt8 | DataType::RawBits(_) => {}
DataType::Int16 | DataType::UInt16 | DataType::Float16 | DataType::BFloat16 => {
Expand All @@ -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!(),
}
}

Expand Down
14 changes: 7 additions & 7 deletions zarrs/src/array/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum DataType {
/// A UTF-8 encoded string.
String,
/// Variable-sized binary data.
Binary,
Bytes,
}

/// An unsupported data type error.
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zarrs/src/array/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
2 changes: 1 addition & 1 deletion zarrs/tests/array_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ fn array_binary() -> Result<(), Box<dyn std::error::Error>> {
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([]),
);
Expand Down
3 changes: 3 additions & 0 deletions zarrs_metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zarrs_metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zarrs_metadata"
version = "0.2.0"
version = "0.3.0-dev"
authors = ["Lachlan Deakin <[email protected]>"]
edition = "2021"
rust-version = "1.77"
Expand Down
8 changes: 4 additions & 4 deletions zarrs_metadata/src/v3/array/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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,
_ => {}
};

Expand Down

0 comments on commit 698fb83

Please sign in to comment.