MCPcopy Create free account
hub / github.com/apache/arrow-rs / fmt

Method fmt

arrow-array/src/array/primitive_array.rs:1325–1384  ·  view source on GitHub ↗
(&self, f: &mut std::fmt::Formatter)

Source from the content-addressed store, hash-verified

1323
1324impl<T: ArrowPrimitiveType> std::fmt::Debug for PrimitiveArray<T> {
1325 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1326 let data_type = self.data_type();
1327
1328 write!(f, "PrimitiveArray<{data_type}>\n[\n")?;
1329 print_long_array(self, f, |array, index, f| match data_type {
1330 DataType::Date32 | DataType::Date64 => {
1331 let v = self.value(index).to_i64().unwrap();
1332 match as_date::<T>(v) {
1333 Some(date) => write!(f, "{date:?}"),
1334 None => {
1335 write!(
1336 f,
1337 "Cast error: Failed to convert {v} to temporal for {data_type}"
1338 )
1339 }
1340 }
1341 }
1342 DataType::Time32(_) | DataType::Time64(_) => {
1343 let v = self.value(index).to_i64().unwrap();
1344 match as_time::<T>(v) {
1345 Some(time) => write!(f, "{time:?}"),
1346 None => {
1347 write!(
1348 f,
1349 "Cast error: Failed to convert {v} to temporal for {data_type}"
1350 )
1351 }
1352 }
1353 }
1354 DataType::Timestamp(_, tz_string_opt) => {
1355 let v = self.value(index).to_i64().unwrap();
1356 match tz_string_opt {
1357 // for Timestamp with TimeZone
1358 Some(tz_string) => {
1359 match tz_string.parse::<Tz>() {
1360 // if the time zone is valid, construct a DateTime<Tz> and format it as rfc3339
1361 Ok(tz) => match as_datetime_with_timezone::<T>(v, tz) {
1362 Some(datetime) => write!(f, "{}", datetime.to_rfc3339()),
1363 None => write!(f, "null"),
1364 },
1365 // if the time zone is invalid, shows NaiveDateTime with an error message
1366 Err(_) => match as_datetime::<T>(v) {
1367 Some(datetime) => {
1368 write!(f, "{datetime:?} (Unknown Time Zone '{tz_string}')")
1369 }
1370 None => write!(f, "null"),
1371 },
1372 }
1373 }
1374 // for Timestamp without TimeZone
1375 None => match as_datetime::<T>(v) {
1376 Some(datetime) => write!(f, "{datetime:?}"),
1377 None => write!(f, "null"),
1378 },
1379 }
1380 }
1381 _ => std::fmt::Debug::fmt(&array.value(index), f),
1382 })?;

Callers

nothing calls this directly

Calls 4

print_long_arrayFunction · 0.85
data_typeMethod · 0.45
to_i64Method · 0.45
valueMethod · 0.45

Tested by

no test coverage detected