1515namespace Microsoft . ML . Runtime . Data . Conversion
1616{
1717 using BL = DvBool ;
18- using DT = DvDateTime ;
19- using DZ = DvDateTimeZone ;
18+ using DT = DateTime ;
19+ using DZ = DateTimeOffset ;
2020 using I1 = DvInt1 ;
2121 using I2 = DvInt2 ;
2222 using I4 = DvInt4 ;
@@ -28,7 +28,7 @@ namespace Microsoft.ML.Runtime.Data.Conversion
2828 using RawI4 = Int32 ;
2929 using RawI8 = Int64 ;
3030 using SB = StringBuilder ;
31- using TS = DvTimeSpan ;
31+ using TS = TimeSpan ;
3232 using TX = DvText ;
3333 using U1 = Byte ;
3434 using U2 = UInt16 ;
@@ -252,9 +252,6 @@ private Conversions()
252252 AddIsNA < R8 > ( IsNA ) ;
253253 AddIsNA < BL > ( IsNA ) ;
254254 AddIsNA < TX > ( IsNA ) ;
255- AddIsNA < TS > ( IsNA ) ;
256- AddIsNA < DT > ( IsNA ) ;
257- AddIsNA < DZ > ( IsNA ) ;
258255
259256 AddGetNA < I1 > ( GetNA ) ;
260257 AddGetNA < I2 > ( GetNA ) ;
@@ -264,9 +261,6 @@ private Conversions()
264261 AddGetNA < R8 > ( GetNA ) ;
265262 AddGetNA < BL > ( GetNA ) ;
266263 AddGetNA < TX > ( GetNA ) ;
267- AddGetNA < TS > ( GetNA ) ;
268- AddGetNA < DT > ( GetNA ) ;
269- AddGetNA < DZ > ( GetNA ) ;
270264
271265 AddHasNA < I1 > ( HasNA ) ;
272266 AddHasNA < I2 > ( HasNA ) ;
@@ -276,9 +270,6 @@ private Conversions()
276270 AddHasNA < R8 > ( HasNA ) ;
277271 AddHasNA < BL > ( HasNA ) ;
278272 AddHasNA < TX > ( HasNA ) ;
279- AddHasNA < TS > ( HasNA ) ;
280- AddHasNA < DT > ( HasNA ) ;
281- AddHasNA < DZ > ( HasNA ) ;
282273
283274 AddIsDef < I1 > ( IsDefault ) ;
284275 AddIsDef < I2 > ( IsDefault ) ;
@@ -853,9 +844,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type)
853844 private bool IsNA ( ref R4 src ) => src . IsNA ( ) ;
854845 private bool IsNA ( ref R8 src ) => src . IsNA ( ) ;
855846 private bool IsNA ( ref BL src ) => src . IsNA ;
856- private bool IsNA ( ref TS src ) => src . IsNA ;
857- private bool IsNA ( ref DT src ) => src . IsNA ;
858- private bool IsNA ( ref DZ src ) => src . IsNA ;
859847 private bool IsNA ( ref TX src ) => src . IsNA ;
860848 #endregion IsNA
861849
@@ -867,9 +855,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type)
867855 private bool HasNA ( ref VBuffer < R4 > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ( ) ) return true ; } return false ; }
868856 private bool HasNA ( ref VBuffer < R8 > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ( ) ) return true ; } return false ; }
869857 private bool HasNA ( ref VBuffer < BL > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
870- private bool HasNA ( ref VBuffer < TS > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
871- private bool HasNA ( ref VBuffer < DT > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
872- private bool HasNA ( ref VBuffer < DZ > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
873858 private bool HasNA ( ref VBuffer < TX > src ) { for ( int i = 0 ; i < src . Count ; i ++ ) { if ( src . Values [ i ] . IsNA ) return true ; } return false ; }
874859 #endregion HasNA
875860
@@ -907,9 +892,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type)
907892 private void GetNA ( ref R4 value ) => value = R4 . NaN ;
908893 private void GetNA ( ref R8 value ) => value = R8 . NaN ;
909894 private void GetNA ( ref BL value ) => value = BL . NA ;
910- private void GetNA ( ref TS value ) => value = TS . NA ;
911- private void GetNA ( ref DT value ) => value = DT . NA ;
912- private void GetNA ( ref DZ value ) => value = DZ . NA ;
913895 private void GetNA ( ref TX value ) => value = TX . NA ;
914896 #endregion GetNA
915897
@@ -1041,9 +1023,9 @@ public void Convert(ref BL src, ref SB dst)
10411023 else if ( src . IsTrue )
10421024 dst . Append ( "1" ) ;
10431025 }
1044- public void Convert ( ref TS src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:c}" , ( TimeSpan ) src ) ; }
1045- public void Convert ( ref DT src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:o}" , ( DateTime ) src ) ; }
1046- public void Convert ( ref DZ src , ref SB dst ) { ClearDst ( ref dst ) ; if ( ! src . IsNA ) dst . AppendFormat ( "{0:o}" , ( DateTimeOffset ) src ) ; }
1026+ public void Convert ( ref TS src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:c}" , src ) ; }
1027+ public void Convert ( ref DT src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:o}" , src ) ; }
1028+ public void Convert ( ref DZ src , ref SB dst ) { ClearDst ( ref dst ) ; dst . AppendFormat ( "{0:o}" , src ) ; }
10471029 #endregion ToStringBuilder
10481030
10491031 #region FromR4
@@ -1472,62 +1454,50 @@ public bool TryParse(ref TX src, out R8 dst)
14721454
14731455 public bool TryParse ( ref TX src , out TS dst )
14741456 {
1457+ dst = default ;
14751458 if ( ! src . HasChars )
14761459 {
1477- if ( src . IsNA )
1478- dst = TS . NA ;
1479- else
1480- dst = default ( TS ) ;
1460+ Contracts . Check ( ! src . IsNA , "Missing values cannot be converted to boolean value." ) ;
14811461 return true ;
14821462 }
1483- TimeSpan res ;
1484- if ( TimeSpan . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , out res ) )
1485- {
1486- dst = new TS ( res ) ;
1463+
1464+ if ( TimeSpan . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , out dst ) )
14871465 return true ;
1488- }
1489- dst = TS . NA ;
1490- return IsStdMissing ( ref src ) ;
1466+
1467+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1468+ return true ;
14911469 }
14921470
14931471 public bool TryParse ( ref TX src , out DT dst )
14941472 {
1473+ dst = default ;
14951474 if ( ! src . HasChars )
14961475 {
1497- if ( src . IsNA )
1498- dst = DvDateTime . NA ;
1499- else
1500- dst = default ( DvDateTime ) ;
1476+ Contracts . Check ( ! src . IsNA , "Missing values cannot be converted to boolean value." ) ;
15011477 return true ;
15021478 }
1503- DateTime res ;
1504- if ( DateTime . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal | DateTimeStyles . AdjustToUniversal , out res ) )
1505- {
1506- dst = new DT ( res ) ;
1479+
1480+ if ( DateTime . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal | DateTimeStyles . AdjustToUniversal , out dst ) )
15071481 return true ;
1508- }
1509- dst = DvDateTime . NA ;
1510- return IsStdMissing ( ref src ) ;
1482+
1483+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1484+ return true ;
15111485 }
15121486
15131487 public bool TryParse ( ref TX src , out DZ dst )
15141488 {
1489+ dst = default ;
15151490 if ( ! src . HasChars )
15161491 {
1517- if ( src . IsNA )
1518- dst = DvDateTimeZone . NA ;
1519- else
1520- dst = default ( DvDateTimeZone ) ;
1492+ Contracts . Check ( ! src . IsNA , "Missing values cannot be converted to boolean value." ) ;
15211493 return true ;
15221494 }
1523- DateTimeOffset res ;
1524- if ( DateTimeOffset . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal , out res ) )
1525- {
1526- dst = new DZ ( res ) ;
1495+
1496+ if ( DateTimeOffset . TryParse ( src . ToString ( ) , CultureInfo . InvariantCulture , DateTimeStyles . AssumeUniversal , out dst ) )
15271497 return true ;
1528- }
1529- dst = DvDateTimeZone . NA ;
1530- return IsStdMissing ( ref src ) ;
1498+
1499+ Contracts . Check ( ! IsStdMissing ( ref src ) , "Missing values cannot be converted to boolean value." ) ;
1500+ return true ;
15311501 }
15321502
15331503 // These map unparsable and overflow values to "NA", which is the value Ix.MinValue. Note that this NA
@@ -1804,21 +1774,10 @@ public void Convert(ref TX src, ref SB dst)
18041774 src . AddToStringBuilder ( dst ) ;
18051775 }
18061776
1807- public void Convert ( ref TX span , ref TS value )
1808- {
1809- if ( ! TryParse ( ref span , out value ) )
1810- Contracts . Assert ( value . IsNA ) ;
1811- }
1812- public void Convert ( ref TX span , ref DT value )
1813- {
1814- if ( ! TryParse ( ref span , out value ) )
1815- Contracts . Assert ( value . IsNA ) ;
1816- }
1817- public void Convert ( ref TX span , ref DZ value )
1818- {
1819- if ( ! TryParse ( ref span , out value ) )
1820- Contracts . Assert ( value . IsNA ) ;
1821- }
1777+ public void Convert ( ref TX span , ref TS value ) => TryParse ( ref span , out value ) ;
1778+ public void Convert ( ref TX span , ref DT value ) => TryParse ( ref span , out value ) ;
1779+ public void Convert ( ref TX span , ref DZ value ) => TryParse ( ref span , out value ) ;
1780+
18221781 #endregion FromTX
18231782
18241783 #region FromBL
0 commit comments