Skip to content

Commit e0ce169

Browse files
authored
Some adjustments to methods on ExtDTypeRef (#6716)
## Summary Makes some adjustments to code that slipped into the a previous PR. Mostly related to display logic. Ideally we would make it so that all of them don't have this `impl Display` logic but we can do that another time. ## API Changes Some of these methods shouldn't be public, and this reverts it. ## Testing N/A Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 0abfb33 commit e0ce169

File tree

4 files changed

+57
-53
lines changed

4 files changed

+57
-53
lines changed

vortex-array/public-api.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6612,8 +6612,6 @@ impl vortex_array::dtype::extension::ExtDTypeRef
66126612

66136613
pub fn vortex_array::dtype::extension::ExtDTypeRef::display_metadata(&self) -> impl core::fmt::Display + '_
66146614

6615-
pub fn vortex_array::dtype::extension::ExtDTypeRef::display_storage_value<'a>(&'a self, storage_value: &'a vortex_array::scalar::ScalarValue) -> impl core::fmt::Display + 'a
6616-
66176615
pub fn vortex_array::dtype::extension::ExtDTypeRef::eq_ignore_nullability(&self, other: &Self) -> bool
66186616

66196617
pub fn vortex_array::dtype::extension::ExtDTypeRef::id(&self) -> vortex_array::dtype::extension::ExtId
@@ -6626,8 +6624,6 @@ pub fn vortex_array::dtype::extension::ExtDTypeRef::serialize_metadata(&self) ->
66266624

66276625
pub fn vortex_array::dtype::extension::ExtDTypeRef::storage_dtype(&self) -> &vortex_array::dtype::DType
66286626

6629-
pub fn vortex_array::dtype::extension::ExtDTypeRef::validate_storage_value(&self, storage_value: &vortex_array::scalar::ScalarValue) -> vortex_error::VortexResult<()>
6630-
66316627
pub fn vortex_array::dtype::extension::ExtDTypeRef::with_nullability(&self, nullability: vortex_array::dtype::Nullability) -> Self
66326628

66336629
impl vortex_array::dtype::extension::ExtDTypeRef

vortex-array/src/dtype/extension/erased.rs

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ impl ExtDTypeRef {
6767
}
6868
}
6969

70+
/// Compute equality ignoring nullability.
71+
pub fn eq_ignore_nullability(&self, other: &Self) -> bool {
72+
self.id() == other.id()
73+
&& self.0.metadata_eq(other.0.metadata_any())
74+
&& self
75+
.storage_dtype()
76+
.eq_ignore_nullability(other.storage_dtype())
77+
}
78+
79+
// TODO(connor): We should add a different type that returns something that can be serialized.
7080
/// Serialize the metadata into a byte vector.
7181
pub fn serialize_metadata(&self) -> VortexResult<Vec<u8>> {
7282
self.0.metadata_serialize()
@@ -78,26 +88,18 @@ impl ExtDTypeRef {
7888
}
7989

8090
/// Formats an extension scalar value using the current dtype for metadata context.
81-
pub fn display_storage_value<'a>(
91+
pub(crate) fn fmt_storage_value<'a>(
8292
&'a self,
93+
f: &mut fmt::Formatter<'_>,
8394
storage_value: &'a ScalarValue,
84-
) -> impl fmt::Display + 'a {
85-
StorageValueDisplay(&*self.0, storage_value)
95+
) -> fmt::Result {
96+
self.0.value_display(f, storage_value)
8697
}
8798

8899
/// Validates that the given storage scalar value is valid for this dtype.
89-
pub fn validate_storage_value(&self, storage_value: &ScalarValue) -> VortexResult<()> {
100+
pub(crate) fn validate_storage_value(&self, storage_value: &ScalarValue) -> VortexResult<()> {
90101
self.0.value_validate(storage_value)
91102
}
92-
93-
/// Compute equality ignoring nullability.
94-
pub fn eq_ignore_nullability(&self, other: &Self) -> bool {
95-
self.id() == other.id()
96-
&& self.0.metadata_eq(other.0.metadata_any())
97-
&& self
98-
.storage_dtype()
99-
.eq_ignore_nullability(other.storage_dtype())
100-
}
101103
}
102104

103105
/// Methods for downcasting type-erased extension dtypes.
@@ -154,28 +156,6 @@ impl ExtDTypeRef {
154156
}
155157
}
156158

157-
impl fmt::Display for ExtDTypeRef {
158-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159-
let metadata = self.display_metadata().to_string();
160-
if metadata.is_empty() {
161-
write!(f, "{}", self.id())?;
162-
} else {
163-
write!(f, "{}[{}]", self.id(), metadata)?;
164-
}
165-
write!(f, "({})", self.storage_dtype())
166-
}
167-
}
168-
169-
impl fmt::Debug for ExtDTypeRef {
170-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171-
f.debug_struct("ExtDType")
172-
.field("id", &self.id())
173-
.field("metadata", &MetadataDebug(&*self.0))
174-
.field("storage_dtype", &self.storage_dtype())
175-
.finish()
176-
}
177-
}
178-
179159
impl PartialEq for ExtDTypeRef {
180160
fn eq(&self, other: &Self) -> bool {
181161
self.id() == other.id()
@@ -193,28 +173,54 @@ impl Hash for ExtDTypeRef {
193173
}
194174
}
195175

196-
// Private formatting helpers for Display and Debug impls.
197-
198-
struct MetadataDisplay<'a>(&'a dyn DynExtDType);
199-
200-
impl fmt::Display for MetadataDisplay<'_> {
176+
impl fmt::Debug for ExtDTypeRef {
201177
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
202-
self.0.metadata_display(f)
178+
let metadata = self.0.metadata_debug(f);
179+
180+
f.debug_struct("ExtDType")
181+
.field("id", &self.id())
182+
.field("metadata", &metadata)
183+
.field("storage_dtype", &self.storage_dtype())
184+
.finish()
203185
}
204186
}
205187

206-
struct MetadataDebug<'a>(&'a dyn DynExtDType);
207-
208-
impl fmt::Debug for MetadataDebug<'_> {
188+
impl fmt::Display for ExtDTypeRef {
209189
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
210-
self.0.metadata_debug(f)
190+
let metadata = MetadataDisplay(&*self.0).to_string();
191+
192+
if metadata.is_empty() {
193+
write!(f, "{}", self.id())?;
194+
} else {
195+
write!(f, "{}[{}]", self.id(), metadata)?;
196+
}
197+
198+
write!(f, "({})", self.storage_dtype())
211199
}
212200
}
213201

214-
struct StorageValueDisplay<'a>(&'a dyn DynExtDType, &'a ScalarValue);
202+
// Private formatting helpers for Display and Debug impls.
215203

216-
impl fmt::Display for StorageValueDisplay<'_> {
204+
struct MetadataDisplay<'a>(&'a dyn DynExtDType);
205+
impl fmt::Display for MetadataDisplay<'_> {
217206
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
218-
self.0.value_display(f, self.1)
207+
self.0.metadata_display(f)
219208
}
220209
}
210+
211+
// struct PythonDisplay<'a>(&'a dyn DynExtDType);
212+
// impl fmt::Display for PythonDisplay<'_> {
213+
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214+
// let metadata = MetadataDisplay(self.0).to_string();
215+
216+
// let id = self.0.id();
217+
// let escaped_id = id.as_ref().escape_default();
218+
// if metadata.is_empty() {
219+
// write!(f, "\"{escaped_id}\"",)?;
220+
// } else {
221+
// write!(f, "\"{escaped_id}\"[{}]", metadata)?;
222+
// }
223+
224+
// write!(f, "({})", self.0.storage_dtype())
225+
// }
226+
// }

vortex-array/src/scalar/typed_view/extension/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ impl fmt::Display for ExtScalar<'_> {
3939
let Some(value) = self.value else {
4040
return write!(f, "null");
4141
};
42-
self.ext_dtype.display_storage_value(value).fmt(f)
42+
43+
self.ext_dtype.fmt_storage_value(f, value)
4344
}
4445
}
4546

vortex-python/src/python_repr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl PythonRepr for DType {
2323
}
2424
}
2525

26+
// TODO(connor): We should probably just use the `Display` impl on `DType`.
2627
impl Display for DTypePythonRepr<'_> {
2728
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2829
let DTypePythonRepr(dtype) = self;

0 commit comments

Comments
 (0)