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

Documentation Improvements #4381

Merged
merged 10 commits into from
Jun 9, 2023
Merged

Documentation Improvements #4381

merged 10 commits into from
Jun 9, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Jun 7, 2023

Which issue does this PR close?

Part of #4071

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jun 7, 2023
@@ -317,6 +285,36 @@
//! assert_eq!(string.value(1), "foo");
//! ```
//!
//! # Crate Topology
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is moved lower-down so that the first thing people see is how to use an array

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good change

@@ -109,7 +77,7 @@
//! assert_eq!(min(&StringArray::from(vec!["b", "a", "c"])), Some("a"));
//! ```
//!
//! For more examples, and details consult the [arrow_array] docs.
//! **For more examples, and details consult the [arrow_array] docs.**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is very easy to miss, as it is sandwiched between a code block and heading. Making it bold helps avoid this

@tustvold tustvold requested a review from alamb June 8, 2023 11:19
@@ -57,6 +57,8 @@ impl OffsetSizeTrait for i64 {
/// An array of [variable length arrays](https://arrow.apache.org/docs/format/Columnar.html#variable-size-list-layout)
///
/// See [`ListArray`] and [`LargeListArray`]`
///
/// See [`GenericListBuilder`](crate::builder::GenericListBuilder) for how to construct a [`GenericListArray`]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the more complex types I opted to just point people to the builders, whilst the arrays can be constructed in other ways these necessarily require knowledge of how these types are structured, or are limited to a specific subset. I think it is better to just encourage people to use the builders as a first port of call

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this makes sense 👍

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @tustvold -- the examples you updated are a great improvement, but removing the per-array type examples I feel pretty strongly is a step backwards for users (though it would certainly be easier to maintain)

arrow-array/src/array/binary_array.rs Show resolved Hide resolved
/// # use arrow_array::{Array, BooleanArray};
/// let arr: BooleanArray = vec![true, true, false].into();
/// let values: Vec<_> = arr.iter().collect();
/// assert_eq!(&values, &[Some(true), Some(true), Some(false)])
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this assert adds anything to the doc example: I think it is already clear from the docs what the array contains.

Comment on lines 34 to 35
/// let arr: BooleanArray = vec![true, true, false].into();
/// let values: Vec<_> = arr.iter().collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

This example seems unnecessarily complicated to me - why would we encourage this pattern instead of what was there

let arr =  BooleanArray::from(vec![true, true, false])

arrow-array/src/array/boolean_array.rs Show resolved Hide resolved
arrow-array/src/array/boolean_array.rs Show resolved Hide resolved
arrow-array/src/array/byte_array.rs Show resolved Hide resolved
arrow-array/src/array/dictionary_array.rs Show resolved Hide resolved
@@ -57,6 +57,8 @@ impl OffsetSizeTrait for i64 {
/// An array of [variable length arrays](https://arrow.apache.org/docs/format/Columnar.html#variable-size-list-layout)
///
/// See [`ListArray`] and [`LargeListArray`]`
///
/// See [`GenericListBuilder`](crate::builder::GenericListBuilder) for how to construct a [`GenericListArray`]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this makes sense 👍

arrow-array/src/array/primitive_array.rs Show resolved Hide resolved
@@ -317,6 +285,36 @@
//! assert_eq!(string.value(1), "foo");
//! ```
//!
//! # Crate Topology
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good change

arrow-array/src/array/byte_array.rs Outdated Show resolved Hide resolved
arrow-array/src/array/primitive_array.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

👌 very nice -- thank you @tustvold

/// assert_eq!(&array, &expected);
/// ```
///
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

/// assert_eq!(false, list2.as_any().downcast_ref::<Int32Array>().unwrap().is_valid(1));
/// assert_eq!(&[6, 7], list3.as_any().downcast_ref::<Int32Array>().unwrap().values());
/// ```
/// A [`GenericListArray`] of variable size lists, storing offsets as `i32`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a link here to the builder too?

Suggested change
/// A [`GenericListArray`] of variable size lists, storing offsets as `i32`.
/// A [`GenericListArray`] of variable size lists, storing offsets as `i32`.
///
/// See [`GenericListBuilder`](crate::builder::GenericListBuilder) for how to construct a [`GenericListArray`]

/// assert_eq!(false, list2.as_any().downcast_ref::<Int32Array>().unwrap().is_valid(1));
/// assert_eq!(&[6, 7], list3.as_any().downcast_ref::<Int32Array>().unwrap().values());
/// ```
/// A [`GenericListArray`] of variable size lists, storing offsets as `i64`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// A [`GenericListArray`] of variable size lists, storing offsets as `i64`.
/// A [`GenericListArray`] of variable size lists, storing offsets as `i64`.
///
/// See [`GenericListBuilder`](crate::builder::GenericListBuilder) for how to construct a [`GenericListArray`]

pub type Decimal256Array = PrimitiveArray<Decimal256Type>;

pub use crate::types::ArrowPrimitiveType;

/// An array of [primitive values](https://arrow.apache.org/docs/format/Columnar.html#fixed-size-primitive-layout)
///
/// # Example: From a Vec
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are nice examples 👍

/// let arr: PrimitiveArray<Int32Type> = vec![Some(1), None, Some(3), None].into();
/// assert_eq!(4, arr.len());
/// assert_eq!(2, arr.null_count());
/// assert_eq!(arr.values(), &[1, 0, 3, 0])
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth pointing out that the 0 (for the null locations) are arbitrary values?

@tustvold tustvold merged commit 9b2b4ca into apache:master Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants