You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/11/22 14:19:33 UTC
[PR] Improve cast docs [arrow-rs]
tustvold opened a new pull request, #5114:
URL: https://github.com/apache/arrow-rs/pull/5114
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
As pointed out on https://github.com/apache/arrow-datafusion/issues/8302 the docs were misleading and incomplete
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve cast docs [arrow-rs]
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5114:
URL: https://github.com/apache/arrow-rs/pull/5114#discussion_r1402138352
##########
arrow-cast/src/cast.rs:
##########
@@ -272,32 +271,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
}
}
-/// Cast `array` to the provided data type and return a new Array with
-/// type `to_type`, if possible.
+/// Cast `array` to the provided data type and return a new Array with type `to_type`, if possible.
///
-/// Behavior:
Review Comment:
These are moved just onto cast_with_options, as the duplication was leading to inconsistency
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve cast docs [arrow-rs]
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #5114:
URL: https://github.com/apache/arrow-rs/pull/5114
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Improve cast docs [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5114:
URL: https://github.com/apache/arrow-rs/pull/5114#discussion_r1406025789
##########
arrow-cast/src/cast.rs:
##########
@@ -692,9 +668,9 @@ fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
})
}
-/// Cast `array` to the provided data type and return a new Array with
-/// type `to_type`, if possible. It accepts `CastOptions` to allow consumers
-/// to configure cast behavior.
+/// Cast `array` to the provided data type and return a new Array with type `to_type`, if possible.
+///
+/// Accepts [`CastOptions`] to allow configuring the cast behavior.
///
/// Behavior:
Review Comment:
```suggestion
/// ## Behavior
```
##########
arrow-cast/src/cast.rs:
##########
@@ -704,15 +680,21 @@ fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
/// in integer casts return null
/// * Numeric to boolean: 0 returns `false`, any other value returns `true`
/// * List to List: the underlying data type is cast
+/// * List to FixedSizeList: the underlying data type is cast. If safe is true and a list element
+/// has the wrong length it will be replaced with NULL, otherwise an error will be returned
Review Comment:
The documentation on `CastOptions` is pretty good
```suggestion
/// * List to FixedSizeList: the underlying data type is cast. If the list element
/// has the wrong length it will either be replaced with NULL, or an error will be returned depending on the
/// value of [`CastOptions::safe`].
```
##########
arrow-cast/src/cast.rs:
##########
@@ -272,32 +271,9 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
}
}
-/// Cast `array` to the provided data type and return a new Array with
-/// type `to_type`, if possible.
+/// Cast `array` to the provided data type and return a new Array with type `to_type`, if possible.
///
-/// Behavior:
Review Comment:
The link to `cast_with_options` is a good idea
##########
arrow-cast/src/cast.rs:
##########
@@ -704,15 +680,21 @@ fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
/// in integer casts return null
/// * Numeric to boolean: 0 returns `false`, any other value returns `true`
/// * List to List: the underlying data type is cast
+/// * List to FixedSizeList: the underlying data type is cast. If safe is true and a list element
+/// has the wrong length it will be replaced with NULL, otherwise an error will be returned
/// * Primitive to List: a list array with 1 value per slot is created
/// * Date32 and Date64: precision lost when going to higher interval
/// * Time32 and Time64: precision lost when going to higher interval
/// * Timestamp and Date{32|64}: precision lost when going to higher interval
/// * Temporal to/from backing primitive: zero-copy with data type change
+/// * Casting from `float32/float64` to `Decimal(precision, scale)` rounds to the `scale` decimals
Review Comment:
```suggestion
/// * Casting from `float32/float64` to `Decimal(precision, scale)` rounds to `scale` decimals
```
##########
arrow-cast/src/cast.rs:
##########
@@ -704,15 +680,21 @@ fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
/// in integer casts return null
/// * Numeric to boolean: 0 returns `false`, any other value returns `true`
/// * List to List: the underlying data type is cast
+/// * List to FixedSizeList: the underlying data type is cast. If safe is true and a list element
+/// has the wrong length it will be replaced with NULL, otherwise an error will be returned
/// * Primitive to List: a list array with 1 value per slot is created
/// * Date32 and Date64: precision lost when going to higher interval
/// * Time32 and Time64: precision lost when going to higher interval
/// * Timestamp and Date{32|64}: precision lost when going to higher interval
/// * Temporal to/from backing primitive: zero-copy with data type change
+/// * Casting from `float32/float64` to `Decimal(precision, scale)` rounds to the `scale` decimals
+/// (i.e. casting 6.4999 to Decimal(10, 1) becomes 6.5). This is a breaking change from `26.0.0`.
+/// It used to truncate it instead of round (i.e. outputs 6.4 instead)
Review Comment:
```suggestion
/// (i.e. casting `6.4999` to Decimal(10, 1) becomes `6.5`). Prior to version `26.0.0`,
/// casting would truncate instead (i.e. outputs `6.4` instead)
```
##########
arrow-cast/src/cast.rs:
##########
@@ -692,9 +668,9 @@ fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
})
}
-/// Cast `array` to the provided data type and return a new Array with
-/// type `to_type`, if possible. It accepts `CastOptions` to allow consumers
-/// to configure cast behavior.
+/// Cast `array` to the provided data type and return a new Array with type `to_type`, if possible.
+///
+/// Accepts [`CastOptions`] to allow configuring the cast behavior.
Review Comment:
```suggestion
/// Accepts [`CastOptions`] to specify cast behavior.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org