You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve Display formatting of DataType::Timestamp (#8425)
# Which issue does this PR close?
* Part of #8351
# Rationale for this change
DataType:s end up in a lot of error messages, and we want them easy and
readable, without and Rust-stuff in them like `Some` and `None`
# What changes are included in this PR?
Before:
> `Timestamp(Millisecond, None)`
> `Timestamp(Nanosecond, Some("UTC"))`
After
> `Timestamp(ms)`
> `Timestamp(ns, "UTC")`
# Are these changes tested?
Yes
# Are there any user-facing changes?
Yes, this is a **breaking change**
"PrimitiveArray<Timestamp(Millisecond, Some(\"Asia/Taipei\"))>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n]",
2140
+
"PrimitiveArray<Timestamp(ms, \"Asia/Taipei\")>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'Asia/Taipei'),\n]",
"PrimitiveArray<Timestamp(Millisecond, Some(\"xxx\"))>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'xxx'),\n]",
2162
+
"PrimitiveArray<Timestamp(ms, \"xxx\")>\n[\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 2018-12-31T00:00:00 (Unknown Time Zone 'xxx'),\n 1921-01-02T00:00:00 (Unknown Time Zone 'xxx'),\n]",
// chrono::NaiveDatetime::from_timestamp_opt returns None while input is invalid
2204
2204
let arr:PrimitiveArray<Time32SecondType> = vec![-7201, -60054].into();
2205
2205
assert_eq!(
2206
-
"PrimitiveArray<Time32(Second)>\n[\n Cast error: Failed to convert -7201 to temporal for Time32(Second),\n Cast error: Failed to convert -60054 to temporal for Time32(Second),\n]",
"PrimitiveArray<Time32(s)>\n[\n Cast error: Failed to convert -7201 to temporal for Time32(s),\n Cast error: Failed to convert -60054 to temporal for Time32(s),\n]",
assert_eq!("PrimitiveArray<Time32(Second)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Second),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400 to temporal for Time32(Second),\n Cast error: Failed to convert 86401 to temporal for Time32(Second),\n null,\n]",
2858
+
assert_eq!("PrimitiveArray<Time32(s)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(s),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400 to temporal for Time32(s),\n Cast error: Failed to convert 86401 to temporal for Time32(s),\n null,\n]",
2859
2859
debug_str
2860
2860
);
2861
2861
}
@@ -2872,7 +2872,7 @@ mod tests {
2872
2872
]
2873
2873
.into();
2874
2874
let debug_str = format!("{array:?}");
2875
-
assert_eq!("PrimitiveArray<Time32(Millisecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Millisecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000 to temporal for Time32(Millisecond),\n Cast error: Failed to convert 86401000 to temporal for Time32(Millisecond),\n null,\n]",
2875
+
assert_eq!("PrimitiveArray<Time32(ms)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(ms),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000 to temporal for Time32(ms),\n Cast error: Failed to convert 86401000 to temporal for Time32(ms),\n null,\n]",
2876
2876
debug_str
2877
2877
);
2878
2878
}
@@ -2890,7 +2890,7 @@ mod tests {
2890
2890
.into();
2891
2891
let debug_str = format!("{array:?}");
2892
2892
assert_eq!(
2893
-
"PrimitiveArray<Time64(Nanosecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Nanosecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000000 to temporal for Time64(Nanosecond),\n Cast error: Failed to convert 86401000000000 to temporal for Time64(Nanosecond),\n null,\n]",
2893
+
"PrimitiveArray<Time64(ns)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(ns),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000000 to temporal for Time64(ns),\n Cast error: Failed to convert 86401000000000 to temporal for Time64(ns),\n null,\n]",
2894
2894
debug_str
2895
2895
);
2896
2896
}
@@ -2907,7 +2907,7 @@ mod tests {
2907
2907
]
2908
2908
.into();
2909
2909
let debug_str = format!("{array:?}");
2910
-
assert_eq!("PrimitiveArray<Time64(Microsecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Microsecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000 to temporal for Time64(Microsecond),\n Cast error: Failed to convert 86401000000 to temporal for Time64(Microsecond),\n null,\n]", debug_str);
2910
+
assert_eq!("PrimitiveArray<Time64(µs)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(µs),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000 to temporal for Time64(µs),\n Cast error: Failed to convert 86401000000 to temporal for Time64(µs),\n null,\n]", debug_str);
Copy file name to clipboardExpand all lines: arrow-cast/src/cast/mod.rs
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4905,7 +4905,10 @@ mod tests {
4905
4905
format_options:FormatOptions::default(),
4906
4906
};
4907
4907
let err = cast_with_options(array,&to_type,&options).unwrap_err();
4908
-
assert_eq!(err.to_string(),"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(Second) type");
4908
+
assert_eq!(
4909
+
err.to_string(),
4910
+
"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(s) type"
4911
+
);
4909
4912
}
4910
4913
}
4911
4914
@@ -4947,7 +4950,10 @@ mod tests {
4947
4950
format_options:FormatOptions::default(),
4948
4951
};
4949
4952
let err = cast_with_options(array,&to_type,&options).unwrap_err();
4950
-
assert_eq!(err.to_string(),"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(Millisecond) type");
4953
+
assert_eq!(
4954
+
err.to_string(),
4955
+
"Cast error: Cannot cast string '08:08:61.091323414' to value of Time32(ms) type"
4956
+
);
4951
4957
}
4952
4958
}
4953
4959
@@ -4981,7 +4987,10 @@ mod tests {
4981
4987
format_options:FormatOptions::default(),
4982
4988
};
4983
4989
let err = cast_with_options(array,&to_type,&options).unwrap_err();
4984
-
assert_eq!(err.to_string(),"Cast error: Cannot cast string 'Not a valid time' to value of Time64(Microsecond) type");
4990
+
assert_eq!(
4991
+
err.to_string(),
4992
+
"Cast error: Cannot cast string 'Not a valid time' to value of Time64(µs) type"
4993
+
);
4985
4994
}
4986
4995
}
4987
4996
@@ -5015,7 +5024,10 @@ mod tests {
5015
5024
format_options:FormatOptions::default(),
5016
5025
};
5017
5026
let err = cast_with_options(array,&to_type,&options).unwrap_err();
5018
-
assert_eq!(err.to_string(),"Cast error: Cannot cast string 'Not a valid time' to value of Time64(Nanosecond) type");
5027
+
assert_eq!(
5028
+
err.to_string(),
5029
+
"Cast error: Cannot cast string 'Not a valid time' to value of Time64(ns) type"
5030
+
);
5019
5031
}
5020
5032
}
5021
5033
@@ -8704,7 +8716,7 @@ mod tests {
8704
8716
};
8705
8717
assert_eq!(
8706
8718
t,
8707
-
r#"Casting from Map(Field { "entries": Struct(key Utf8, value nullable Interval(DayTime)) }, false) to Map(Field { "entries": Struct(key Utf8, value Duration(Second)) }, true) not supported"#
8719
+
r#"Casting from Map(Field { "entries": Struct(key Utf8, value nullable Interval(DayTime)) }, false) to Map(Field { "entries": Struct(key Utf8, value Duration(s)) }, true) not supported"#
0 commit comments