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

feat: teach PyArray to tree_display & teach CI to doctest #900

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
rye run pytest --benchmark-disable test/
working-directory: pyvortex/

- name: Doctest - PyVortex
run: |
make clean && make doctest
working-directory: docs/

- name: License Check
run: cargo install --locked cargo-deny && cargo deny check
- uses: rustsec/[email protected]
Expand Down
42 changes: 42 additions & 0 deletions pyvortex/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,46 @@ impl PyArray {
.map_err(PyVortexError::map_err)
.and_then(|arr| Bound::new(py, PyArray { inner: arr }))
}

/// Internal technical details about the encoding of this Array.
///
/// Warnings
/// --------
/// The format of the returned string may change without notice.
///
/// Returns
/// -------
/// :class:`.str`
///
/// Examples
/// --------
///
/// Uncompressed arrays have straightforward encodings:
///
/// >>> arr = vortex.encoding.array([1, 2, None, 3])
/// >>> print(arr.tree_display())
/// root: vortex.primitive(0x03)(i64?, len=4) nbytes=33 B (100.00%)
/// metadata: PrimitiveMetadata { validity: Array }
/// buffer: 32 B
/// validity: vortex.bool(0x02)(bool, len=4) nbytes=1 B (3.03%)
/// metadata: BoolMetadata { validity: NonNullable, length: 4, bit_offset: 0 }
/// buffer: 1 B
/// <BLANKLINE>
///
/// Compressed arrays use more complex encodings:
///
/// >>> print(vortex.encoding.compress(arr).tree_display())
/// root: fastlanes.for(0x17)(i64?, len=4) nbytes=1 B (100.00%)
/// metadata: FoRMetadata { reference: Scalar { dtype: Primitive(I64, Nullable), value: Primitive(I64(1)) }, shift: 0 }
/// encoded: fastlanes.bitpacked(0x15)(u64?, len=4) nbytes=1 B (100.00%)
/// metadata: BitPackedMetadata { validity: Array, bit_width: 2, offset: 0, length: 4, has_patches: false }
/// buffer: 256 B
/// validity: vortex.bool(0x02)(bool, len=4) nbytes=1 B (100.00%)
/// metadata: BoolMetadata { validity: NonNullable, length: 4, bit_offset: 0 }
/// buffer: 1 B
/// <BLANKLINE>
///
fn tree_display(&self) -> String {
self.inner.tree_display().to_string()
}
}
6 changes: 3 additions & 3 deletions pyvortex/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use crate::error::PyVortexError;
///
/// >>> a = vortex.encoding.array([42 for _ in range(1000)])
/// >>> str(vortex.encoding.compress(a))
/// 'vortex.constant(0x0a)(i64, len=1000)'
/// 'vortex.constant(0x09)(i64, len=1000)'
///
/// Compress an array of increasing integers:
///
/// >>> a = vortex.encoding.array(list(range(1000)))
/// >>> str(vortex.encoding.compress(a))
/// 'fastlanes.for(0x0f)(i64, len=1000)'
/// 'fastlanes.for(0x17)(i64, len=1000)'
///
/// Compress an array of increasing floating-point numbers and a few nulls:
///
Expand All @@ -34,7 +34,7 @@ use crate::error::PyVortexError;
/// ... for x in range(1000)
/// ... ])
/// >>> str(vortex.encoding.compress(a))
/// 'vortex.alp(0x0d)(f64?, len=1000)'
/// 'vortex.alp(0x11)(f64?, len=1000)'
pub fn compress<'py>(array: &Bound<'py, PyArray>) -> PyResult<Bound<'py, PyArray>> {
let compressor = SamplingCompressor::default();
let inner = compressor
Expand Down
Loading