1414
1515namespace Microsoft . ML . Runtime . Data . Conversion
1616{
17- using BL = Boolean ;
18- using DT = DvDateTime ;
19- using DZ = DvDateTimeZone ;
17+ using BL = Boolean ; ;
18+ using DT = DateTime ;
19+ using DZ = DateTimeOffset ;
2020 using R4 = Single ;
2121 using R8 = Double ;
2222 using I1 = SByte ;
2323 using I2 = Int16 ;
2424 using I4 = Int32 ;
2525 using I8 = Int64 ;
2626 using SB = StringBuilder ;
27- using TS = DvTimeSpan ;
2827 using TX = ReadOnlyMemory < char > ;
28+ using TS = TimeSpan ;
2929 using U1 = Byte ;
3030 using U2 = UInt16 ;
3131 using U4 = UInt32 ;
@@ -242,21 +242,12 @@ private Conversions()
242242
243243 AddIsNA < R4 > ( IsNA ) ;
244244 AddIsNA < R8 > ( IsNA ) ;
245- AddIsNA < TS > ( IsNA ) ;
246- AddIsNA < DT > ( IsNA ) ;
247- AddIsNA < DZ > ( IsNA ) ;
248245
249246 AddGetNA < R4 > ( GetNA ) ;
250247 AddGetNA < R8 > ( GetNA ) ;
251- AddGetNA < TS > ( GetNA ) ;
252- AddGetNA < DT > ( GetNA ) ;
253- AddGetNA < DZ > ( GetNA ) ;
254248
255249 AddHasNA < R4 > ( HasNA ) ;
256250 AddHasNA < R8 > ( HasNA ) ;
257- AddHasNA < TS > ( HasNA ) ;
258- AddHasNA < DT > ( HasNA ) ;
259- AddHasNA < DZ > ( HasNA ) ;
260251
261252 AddIsDef < I1 > ( IsDefault ) ;
262253 AddIsDef < I2 > ( IsDefault ) ;
@@ -826,17 +817,11 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type)
826817 #region IsNA
827818 private bool IsNA ( ref R4 src ) => src . IsNA ( ) ;
828819 private bool IsNA ( ref R8 src ) => src . IsNA ( ) ;
829- private bool IsNA ( ref TS src ) => src . IsNA ;
830- private bool IsNA ( ref DT src ) => src . IsNA ;
831- private bool IsNA ( ref DZ src ) => src . IsNA ;
832820 #endregion IsNA
833821
834822 #region HasNA
835823 private bool HasNA ( ref VBuffer < R4 > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ( ) ) return true ; } return false ; }
836824 private bool HasNA ( ref VBuffer < R8 > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ( ) ) return true ; } return false ; }
837- private bool HasNA ( ref VBuffer < TS > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
838- private bool HasNA ( ref VBuffer < DT > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
839- private bool HasNA ( ref VBuffer < DZ > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
840825 #endregion HasNA
841826
842827 #region IsDefault
@@ -868,9 +853,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type)
868853 #region GetNA
869854 private void GetNA ( ref R4 value ) => value = R4 . NaN ;
870855 private void GetNA ( ref R8 value ) => value = R8 . NaN ;
871- private void GetNA ( ref TS value ) => value = TS . NA ;
872- private void GetNA ( ref DT value ) => value = DT . NA ;
873- private void GetNA ( ref DZ value ) => value = DZ . NA ;
874856 #endregion GetNA
875857
876858 #region ToI1
@@ -1001,9 +983,9 @@ public void Convert(ref BL src, ref SB dst)
1001983 else
1002984 dst . Append ( "1" ) ;
1003985 }
1004- public void Convert ( ref TS src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:c}" , ( TimeSpan ) src ) ; }
1005- public void Convert ( ref DT src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:o}" , ( DateTime ) src ) ; }
1006- public void Convert ( ref DZ src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:o}" , ( DateTimeOffset ) src ) ; }
986+ public void Convert ( ref TS src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:c}" , src ) ; }
987+ public void Convert ( ref DT src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:o}" , src ) ; }
988+ public void Convert ( ref DZ src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:o}" , src ) ; }
1007989 #endregion ToStringBuilder
1008990
1009991 #region FromR4
@@ -1424,14 +1406,12 @@ public bool TryParse(ref TX src, out TS dst)
14241406 dst = default ;
14251407 return true ;
14261408 }
1427- TimeSpan res ;
1428- if ( TimeSpan . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , out res ) )
1429- {
1430- dst = new TS ( res ) ;
1409+
1410+ if ( TimeSpan . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , out dst ) )
14311411 return true ;
1432- }
1433- dst = TS . NA ;
1434- return IsStdMissing ( ref src ) ;
1412+
1413+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1414+ return true ;
14351415 }
14361416
14371417 public bool TryParse ( ref TX src , out DT dst )
@@ -1441,14 +1421,12 @@ public bool TryParse(ref TX src, out DT dst)
14411421 dst = default ;
14421422 return true ;
14431423 }
1444- DateTime res ;
1445- if ( DateTime . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal | DateTimeStyles . AdjustToUniversal , out res ) )
1446- {
1447- dst = new DT ( res ) ;
1424+
1425+ if ( DateTime . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal | DateTimeStyles . AdjustToUniversal , out dst ) )
14481426 return true ;
1449- }
1450- dst = DvDateTime . NA ;
1451- return IsStdMissing ( ref src ) ;
1427+
1428+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1429+ return true ;
14521430 }
14531431
14541432 public bool TryParse ( ref TX src , out DZ dst )
@@ -1458,14 +1436,12 @@ public bool TryParse(ref TX src, out DZ dst)
14581436 dst = default ;
14591437 return true ;
14601438 }
1461- DateTimeOffset res ;
1462- if ( DateTimeOffset . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal , out res ) )
1463- {
1464- dst = new DZ ( res ) ;
1439+
1440+ if ( DateTimeOffset . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal , out dst ) )
14651441 return true ;
1466- }
1467- dst = DvDateTimeZone . NA ;
1468- return IsStdMissing ( ref src ) ;
1442+
1443+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1444+ return true ;
14691445 }
14701446
14711447 // These throw an exception for unparsable and overflow values.
@@ -1731,21 +1707,10 @@ public void Convert(ref TX src, ref SB dst)
17311707 ReadOnlyMemoryUtils . AddToStringBuilder ( dst , src ) ;
17321708 }
17331709
1734- public void Convert ( ref TX span , ref TS value )
1735- {
1736- if ( ! TryParse ( ref span , out value ) )
1737- Contracts . Assert ( value . IsNA ) ;
1738- }
1739- public void Convert ( ref TX span , ref DT value )
1740- {
1741- if ( ! TryParse ( ref span , out value ) )
1742- Contracts . Assert ( value . IsNA ) ;
1743- }
1744- public void Convert ( ref TX span , ref DZ value )
1745- {
1746- if ( ! TryParse ( ref span , out value ) )
1747- Contracts . Assert ( value . IsNA ) ;
1748- }
1710+ public void Convert ( ref TX span , ref TS value ) => TryParse ( ref span , out value ) ;
1711+ public void Convert ( ref TX span , ref DT value ) => TryParse ( ref span , out value ) ;
1712+ public void Convert ( ref TX span , ref DZ value ) => TryParse ( ref span , out value ) ;
1713+
17491714 #endregion FromTX
17501715
17511716 #region FromBL
0 commit comments