Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension DType canonicalization behaves as other array types #500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion vortex-array/src/array/chunked/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ pub(crate) fn try_canonicalize_chunks(
// Extension arrays wrap an internal storage array, which can hold a ChunkedArray until
// it is safe to unpack them.
DType::Extension(ext_dtype, _) => {
if chunks.is_empty() {
Copy link
Member Author

Choose a reason for hiding this comment

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

there's a fun case of "What is the canonical storage type for an extension dtype"?

panic!("Can't canonicalize empty extension array")
}
let ext_chunk = ExtensionArray::try_from(chunks.first().unwrap()).unwrap();
let storage_chunks = chunks
.into_iter()
.map(|c| ExtensionArray::try_from(c).unwrap().storage())
.collect::<Vec<_>>();
let ext_array = ExtensionArray::new(
ext_dtype.clone(),
ChunkedArray::try_new(chunks, dtype.clone())?.into_array(),
try_canonicalize_chunks(storage_chunks, ext_chunk.storage_dtype())?.into_array(),
);

Ok(Canonical::Extension(ext_array))
Expand Down
7 changes: 6 additions & 1 deletion vortex-array/src/array/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ExtensionArray {

pub fn storage(&self) -> Array {
self.array()
.child(0, &self.metadata().storage_dtype, self.len())
.child(0, self.storage_dtype(), self.len())
.expect("Missing storage array")
}

Expand All @@ -50,6 +50,11 @@ impl ExtensionArray {
};
ext
}

#[inline]
pub(crate) fn storage_dtype(&self) -> &DType {
&self.metadata().storage_dtype
}
}

impl ArrayTrait for ExtensionArray {}
Expand Down
Loading