static bool TryReadTimePrecision(ref feather.fbs.Column column, out DateTimePrecisionType precision, out string errorMessage) { var metadata = column.Metadata <TimeMetadata>(); if (metadata == null) { precision = default(DateTimePrecisionType); errorMessage = $"Couldn't read Precision for column {column.Name}, no TimeMetadata"; return(false); } var metadataValue = metadata.Value; var unit = metadataValue.Unit; switch (unit) { case TimeUnit.MICROSECOND: precision = DateTimePrecisionType.Microsecond; break; case TimeUnit.MILLISECOND: precision = DateTimePrecisionType.Millisecond; break; case TimeUnit.NANOSECOND: precision = DateTimePrecisionType.Nanosecond; break; case TimeUnit.SECOND: precision = DateTimePrecisionType.Second; break; default: precision = default(DateTimePrecisionType); errorMessage = $"Couldn't understand TimeUnit {unit}"; return(false); } errorMessage = null; return(true); }
static bool TryReadTimestampPrecision(ref feather.fbs.Column column, out DateTimePrecisionType precision, out string errorMessage) { var metadata = column.Metadata <TimestampMetadata>(); if (metadata == null) { precision = default(DateTimePrecisionType); errorMessage = $"Couldn't read Precision for column {column.Name}, no TimestampMetadada"; return(false); } var metadataValue = metadata.Value; var timezoneName = metadataValue.Timezone; var unit = metadataValue.Unit; // note: supporting other timezones would be nice, // but the timezone included appears to just be // a passthrough from as.POSIXct (in R anyway) // which lets a bunch of ambiguous junk through // (timezone abbreviations are NOT unique, or // properly spec'd even). // the only thing we can rely on being the same // everywhere is UTC, so constrain to that. var isntUtc = timezoneName != null && !timezoneName.Equals("UTC", StringComparison.InvariantCultureIgnoreCase) && !timezoneName.Equals("GMT", StringComparison.InvariantCultureIgnoreCase); if (isntUtc) { errorMessage = $"Cannot read Timestamp in timezone {timezoneName}, only UTC/GMT is supported"; precision = default(DateTimePrecisionType); return(false); } switch (unit) { case TimeUnit.MICROSECOND: precision = DateTimePrecisionType.Microsecond; break; case TimeUnit.MILLISECOND: precision = DateTimePrecisionType.Millisecond; break; case TimeUnit.NANOSECOND: precision = DateTimePrecisionType.Nanosecond; break; case TimeUnit.SECOND: precision = DateTimePrecisionType.Second; break; default: precision = default(DateTimePrecisionType); errorMessage = $"Couldn't understand TimeUnit {unit}"; return(false); } errorMessage = null; return(true); }
static bool TryReadCategoryLevels(MemoryMappedViewAccessor view, ref feather.fbs.Column column, out string[] categoryLevels, out string errorMessage) { var metadata = column.Metadata <CategoryMetadata>(); if (metadata == null) { categoryLevels = null; errorMessage = $"Couldn't read Category levels for column {column.Name}, no CategoryMetadata"; return(false); } var metadataValue = metadata.Value; if (metadataValue.Levels == null) { categoryLevels = null; errorMessage = $"Couldn't read Category levels for column {column.Name}, no Levels"; return(false); } var levels = metadataValue.Levels.Value; if (levels.Type != feather.fbs.Type.UTF8) { categoryLevels = null; errorMessage = $"Found non-string ({levels.Type}) for column {column.Name}"; return(false); } ColumnSpec categoryColumn; if (!TryMakeColumnSpec(nameof(TryReadCategoryLevels) + "__FAKE__", levels.Type, ref levels, null, default(DateTimePrecisionType), out categoryColumn, out errorMessage)) { categoryLevels = null; return(false); } categoryLevels = new string[levels.Length]; for (var i = 0; i < levels.Length; i++) { var categoryName = DataFrame.ReadString(view, levels.Length, null, ref categoryColumn, i); categoryLevels[i] = categoryName; } errorMessage = null; return(true); }