Skip to content

Commit cb0097c

Browse files
committed
refactor: use from_epoch_days instead
1 parent 7a77f29 commit cb0097c

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

guests/python/src/conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl PythonType {
207207
maybe_val
208208
.map(|val| {
209209
let days_since_epoch = val;
210-
let epoch = NaiveDate::from_ymd_opt(1970, 1, 1)
210+
let epoch = NaiveDate::from_epoch_days(0)
211211
.ok_or_else(|| exec_datafusion_err!("cannot create epoch date"))?;
212212
let date = epoch + chrono::Duration::days(days_since_epoch as i64);
213213

@@ -568,7 +568,7 @@ impl<'py> ArrayBuilder<'py> for Date32Builder {
568568
)
569569
})?;
570570

571-
let epoch = NaiveDate::from_ymd_opt(1970, 1, 1)
571+
let epoch = NaiveDate::from_epoch_days(0)
572572
.ok_or_else(|| exec_datafusion_err!("cannot create epoch date"))?;
573573

574574
let days_since_epoch = date.signed_duration_since(epoch).num_days();

host/tests/integration_tests/python/types/date.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def foo(x: date) -> date:
7070
args: vec![ColumnarValue::Array(Arc::new(Date32Array::from_iter([
7171
Some(0),
7272
])))],
73-
arg_fields: vec![Arc::new(Field::new("a1", DataType::Date32, true))],
73+
arg_fields: vec![Arc::new(Field::new("time", DataType::Date32, true))],
7474
number_rows: 1,
7575
return_field: Arc::new(Field::new("r", DataType::Date32, true)),
7676
})
7777
.unwrap_err();
78-
// The error message will contain the actual datetime, so we just check it contains the expected type info
78+
7979
assert!(err.to_string().contains("expected `date` but got"));
8080
assert!(err.to_string().contains("of type `datetime`"));
8181
}

host/tests/integration_tests/python/types/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def foo(x: time) -> time:
144144
)),
145145
})
146146
.unwrap_err();
147-
// The error message will contain the actual datetime, so we just check it contains the expected type info
147+
148148
assert!(err.to_string().contains("expected `time` but got"));
149149
assert!(err.to_string().contains("of type `datetime`"));
150150
}

host/tests/integration_tests/python/types/timedelta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def foo(x: timedelta) -> timedelta:
137137
)),
138138
})
139139
.unwrap_err();
140-
// The error message will contain the actual datetime, so we just check it contains the expected type info
140+
141141
assert!(err.to_string().contains("expected `timedelta` but got"));
142142
assert!(err.to_string().contains("of type `datetime`"));
143143
}

0 commit comments

Comments
 (0)