@@ -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-
179159impl 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+ // }
0 commit comments