-
Notifications
You must be signed in to change notification settings - Fork 784
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
Cleanup ArrowNativeType
(#1918)
#2793
Conversation
impl ArrowNativeType for $t { | ||
#[inline] | ||
fn from_usize(v: usize) -> Option<Self> { | ||
v.try_into().ok() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryInto behaves the same for integer types as num::FromPrimitive
@@ -102,7 +101,7 @@ pub unsafe fn unset_bit_raw(data: *mut u8, i: usize) { | |||
pub fn ceil(value: usize, divisor: usize) -> usize { | |||
// Rewrite as `value.div_ceil(&divisor)` after | |||
// https://github.com/rust-lang/rust/issues/88581 is merged. | |||
Integer::div_ceil(&value, &divisor) | |||
value / divisor + (0 != value % divisor) as usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copied wholesale from Integer::div_ceil
Remove num dependency from arrow-buffer Deprecate unnecessary methods
738596a
to
45aa763
Compare
@@ -38,7 +38,6 @@ path = "src/lib.rs" | |||
bench = false | |||
|
|||
[dependencies] | |||
num = { version = "0.4", default-features = false, features = ["std"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a dependency elsewhere, but every little helps 😅
@@ -308,20 +308,13 @@ impl<K: ArrowPrimitiveType> DictionaryArray<K> { | |||
|
|||
/// Return an iterator over the keys (indexes into the dictionary) | |||
pub fn keys_iter(&self) -> impl Iterator<Item = Option<usize>> + '_ { | |||
self.keys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks make no sense as we have already validated the dictionary offsets are non-negative
/// Convert to usize according to the [`as`] operator | ||
/// | ||
/// [`as`]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#numeric-cast | ||
fn as_usize(self) -> usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't entirely sure about this, but taking a Copy type by reference seems strange, so I changed to take it by value, happy to revert if people feel strongly
fn from_usize(_: usize) -> Option<Self> { | ||
None | ||
} | ||
/// Convert native integer type from usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't change the behaviour, just documents it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
impl private::Sealed for f32 {} | ||
impl ArrowNativeType for f64 {} | ||
impl private::Sealed for f64 {} | ||
native_float!(f16, self, self.to_f32() as _); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that as usize
on a f32
does the right thing (truncates to integer) rather than reinterpreting as bytes
@@ -97,20 +97,20 @@ impl Parser for Date32Type { | |||
fn parse(string: &str) -> Option<i32> { | |||
use chrono::Datelike; | |||
let date = string.parse::<chrono::NaiveDate>().ok()?; | |||
Self::Native::from_i32(date.num_days_from_ce() - EPOCH_DAYS_FROM_CE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes? That's why I removed it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, wondering why we had it before. 😄
#[inline] | ||
/// | ||
/// Returns `None` if [`Self`] is not `i32` | ||
#[deprecated(note = "please use `Option::Some` instead")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation message looks a bit confused at first glance. I think it means that like Self::Native::from_i32(date.num_days_from_ce() - EPOCH_DAYS_FROM_CE)
such a redundant case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only case where the method returned something other than None is when the type matches, in which case Some is the same behaviour
Benchmark runs are scheduled for baseline = 7639f28 and contender = 178319b. 178319b is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
ArrowNativeType
(#1918)
Which issue does this PR close?
Closes #1918
Rationale for this change
The ArrowNativeType has been a pet peeve of mine for a while, this cleans it up a bit:
What changes are included in this PR?
Are there any user-facing changes?
ArrowNativeType::to_usize
andArrowNativeType::to_isize
take values by value, instead of reference