Skip to content

Commit 5a24119

Browse files
authored
Minor: Improve arrow_cast documentation (#5825)
* Minor: Improve arrow_cast documentatin * tweaks
1 parent c2b05cd commit 5a24119

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

arrow-cast/src/base64.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Functions for Base64 encoding/decoding
18+
//! Functions for converting data in [`GenericBinaryArray`] such as [`StringArray`] to/from base64 encoded strings
19+
//!
20+
//! [`StringArray`]: arrow_array::StringArray
1921
2022
use arrow_array::{Array, GenericBinaryArray, GenericStringArray, OffsetSizeTrait};
2123
use arrow_buffer::OffsetBuffer;
@@ -25,7 +27,7 @@ use base64::engine::Config;
2527

2628
pub use base64::prelude::*;
2729

28-
/// Bas64 encode each element of `array` with the provided `engine`
30+
/// Bas64 encode each element of `array` with the provided [`Engine`]
2931
pub fn b64_encode<E: Engine, O: OffsetSizeTrait>(
3032
engine: &E,
3133
array: &GenericBinaryArray<O>,
@@ -51,7 +53,7 @@ pub fn b64_encode<E: Engine, O: OffsetSizeTrait>(
5153
unsafe { GenericStringArray::new_unchecked(offsets, buffer.into(), array.nulls().cloned()) }
5254
}
5355

54-
/// Base64 decode each element of `array` with the provided `engine`
56+
/// Base64 decode each element of `array` with the provided [`Engine`]
5557
pub fn b64_decode<E: Engine, O: OffsetSizeTrait>(
5658
engine: &E,
5759
array: &GenericBinaryArray<O>,

arrow-cast/src/display.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Functions for printing array values, as strings, for debugging
19-
//! purposes. See the `pretty` crate for additional functions for
18+
//! Functions for printing array values as human-readable strings.
19+
//!
20+
//! This is often used for debugging or logging purposes.
21+
//!
22+
//! See the [`pretty`] crate for additional functions for
2023
//! record batch pretty printing.
21-
24+
//!
25+
//! [`pretty`]: crate::pretty
2226
use std::fmt::{Display, Formatter, Write};
2327
use std::ops::Range;
2428

arrow-cast/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Cast kernel for [Apache Arrow](https://docs.rs/arrow)
19-
18+
//! Functions for converting from one data type to another in [Apache Arrow](https://docs.rs/arrow)
2019
pub mod cast;
2120
pub use cast::*;
2221
pub mod display;

arrow-cast/src/parse.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`Parser`] implementations for converting strings to Arrow types
19+
//!
20+
//! Used by the CSV and JSON readers to convert strings to Arrow types
1821
use arrow_array::timezone::Tz;
1922
use arrow_array::types::*;
2023
use arrow_array::ArrowNativeTypeOp;
@@ -405,8 +408,29 @@ fn string_to_time(s: &str) -> Option<NaiveTime> {
405408
)
406409
}
407410

408-
/// Specialized parsing implementations
409-
/// used by csv and json reader
411+
/// Specialized parsing implementations to convert strings to Arrow types.
412+
///
413+
/// This is used by csv and json reader and can be used directly as well.
414+
///
415+
/// # Example
416+
///
417+
/// To parse a string to a [`Date32Type`]:
418+
///
419+
/// ```
420+
/// use arrow_cast::parse::Parser;
421+
/// use arrow_array::types::Date32Type;
422+
/// let date = Date32Type::parse("2021-01-01").unwrap();
423+
/// assert_eq!(date, 18628);
424+
/// ```
425+
///
426+
/// To parse a string to a [`TimestampNanosecondType`]:
427+
///
428+
/// ```
429+
/// use arrow_cast::parse::Parser;
430+
/// use arrow_array::types::TimestampNanosecondType;
431+
/// let ts = TimestampNanosecondType::parse("2021-01-01T00:00:00.123456789Z").unwrap();
432+
/// assert_eq!(ts, 1609459200123456789);
433+
/// ```
410434
pub trait Parser: ArrowPrimitiveType {
411435
fn parse(string: &str) -> Option<Self::Native>;
412436

arrow-cast/src/pretty.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Utilities for pretty printing record batches. Note this module is not
19-
//! available unless `feature = "prettyprint"` is enabled.
18+
//! Utilities for pretty printing [`RecordBatch`]es and [`Array`]s.
19+
//!
20+
//! Note this module is not available unless `feature = "prettyprint"` is enabled.
21+
//!
22+
//! [`RecordBatch`]: arrow_array::RecordBatch
23+
//! [`Array`]: arrow_array::Array
2024
2125
use std::fmt::Display;
2226

0 commit comments

Comments
 (0)