Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Nov 17, 2024
1 parent 75c4446 commit 83d0d80
Showing 1 changed file with 10 additions and 50 deletions.
60 changes: 10 additions & 50 deletions crates/polars-time/src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let year = if year.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { year.get_unchecked(0) } {
if n == 1 {
year
} else {
&Int32Chunked::full("".into(), value, n)
}
&Int32Chunked::full("".into(), value, n)
} else {
&self.year()
}
Expand All @@ -69,11 +65,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let month = if month.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { month.get_unchecked(0) } {
if n == 1 {
month
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.month()
}
Expand All @@ -83,11 +75,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let day = if day.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { day.get_unchecked(0) } {
if n == 1 {
day
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.day()
}
Expand All @@ -97,11 +85,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let hour = if hour.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { hour.get_unchecked(0) } {
if n == 1 {
hour
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.hour()
}
Expand All @@ -111,11 +95,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let minute = if minute.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { minute.get_unchecked(0) } {
if n == 1 {
minute
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.minute()
}
Expand All @@ -125,11 +105,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let second = if second.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { second.get_unchecked(0) } {
if n == 1 {
second
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.second()
}
Expand All @@ -139,11 +115,7 @@ impl PolarsReplaceDatetime for DatetimeChunked {
let microsecond = if microsecond.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { microsecond.get_unchecked(0) } {
if n == 1 {
microsecond
} else {
&Int32Chunked::full("".into(), value, n)
}
&Int32Chunked::full("".into(), value, n)
} else {
&(self.nanosecond() / 1000)
}
Expand Down Expand Up @@ -181,11 +153,7 @@ impl PolarsReplaceDate for DateChunked {
let year = if year.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { year.get_unchecked(0) } {
if n == 1 {
year
} else {
&Int32Chunked::full("".into(), value, n)
}
&Int32Chunked::full("".into(), value, n)
} else {
&self.year()
}
Expand All @@ -195,11 +163,7 @@ impl PolarsReplaceDate for DateChunked {
let month = if month.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { month.get_unchecked(0) } {
if n == 1 {
month
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.month()
}
Expand All @@ -209,11 +173,7 @@ impl PolarsReplaceDate for DateChunked {
let day = if day.len() == 1 {
// SAFETY: array has one value.
if let Some(value) = unsafe { day.get_unchecked(0) } {
if n == 1 {
day
} else {
&Int8Chunked::full("".into(), value, n)
}
&Int8Chunked::full("".into(), value, n)
} else {
&self.day()
}
Expand Down

0 comments on commit 83d0d80

Please sign in to comment.