-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Replace DvDateTimeZone, DvDateTime, DvTimeSpan with .NET standard types. #693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bc530e9
e0d66b0
54145da
e55c780
53a84d1
b7d4c6b
844da7c
dbaac06
53b4e57
ae9aede
48b4c08
7f55c59
71f8701
1ccc263
1672739
5231b51
0a1ba05
0560602
401fa64
c3a5a2d
74a652c
7cc7d9a
a42861c
ea943d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
namespace Microsoft.ML.Runtime.Data.Conversion | ||
{ | ||
using BL = DvBool; | ||
using DT = DvDateTime; | ||
using DZ = DvDateTimeZone; | ||
using DT = DateTime; | ||
using DZ = DateTimeOffset; | ||
using I1 = DvInt1; | ||
using I2 = DvInt2; | ||
using I4 = DvInt4; | ||
|
@@ -28,7 +28,7 @@ namespace Microsoft.ML.Runtime.Data.Conversion | |
using RawI4 = Int32; | ||
using RawI8 = Int64; | ||
using SB = StringBuilder; | ||
using TS = DvTimeSpan; | ||
using TS = TimeSpan; | ||
using TX = DvText; | ||
using U1 = Byte; | ||
using U2 = UInt16; | ||
|
@@ -252,9 +252,6 @@ private Conversions() | |
AddIsNA<R8>(IsNA); | ||
AddIsNA<BL>(IsNA); | ||
AddIsNA<TX>(IsNA); | ||
AddIsNA<TS>(IsNA); | ||
AddIsNA<DT>(IsNA); | ||
AddIsNA<DZ>(IsNA); | ||
|
||
AddGetNA<I1>(GetNA); | ||
AddGetNA<I2>(GetNA); | ||
|
@@ -264,9 +261,6 @@ private Conversions() | |
AddGetNA<R8>(GetNA); | ||
AddGetNA<BL>(GetNA); | ||
AddGetNA<TX>(GetNA); | ||
AddGetNA<TS>(GetNA); | ||
AddGetNA<DT>(GetNA); | ||
AddGetNA<DZ>(GetNA); | ||
|
||
AddHasNA<I1>(HasNA); | ||
AddHasNA<I2>(HasNA); | ||
|
@@ -276,9 +270,6 @@ private Conversions() | |
AddHasNA<R8>(HasNA); | ||
AddHasNA<BL>(HasNA); | ||
AddHasNA<TX>(HasNA); | ||
AddHasNA<TS>(HasNA); | ||
AddHasNA<DT>(HasNA); | ||
AddHasNA<DZ>(HasNA); | ||
|
||
AddIsDef<I1>(IsDefault); | ||
AddIsDef<I2>(IsDefault); | ||
|
@@ -853,9 +844,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type) | |
private bool IsNA(ref R4 src) => src.IsNA(); | ||
private bool IsNA(ref R8 src) => src.IsNA(); | ||
private bool IsNA(ref BL src) => src.IsNA; | ||
private bool IsNA(ref TS src) => src.IsNA; | ||
private bool IsNA(ref DT src) => src.IsNA; | ||
private bool IsNA(ref DZ src) => src.IsNA; | ||
private bool IsNA(ref TX src) => src.IsNA; | ||
#endregion IsNA | ||
|
||
|
@@ -867,9 +855,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type) | |
private bool HasNA(ref VBuffer<R4> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA()) return true; } return false; } | ||
private bool HasNA(ref VBuffer<R8> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA()) return true; } return false; } | ||
private bool HasNA(ref VBuffer<BL> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA) return true; } return false; } | ||
private bool HasNA(ref VBuffer<TS> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA) return true; } return false; } | ||
private bool HasNA(ref VBuffer<DT> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA) return true; } return false; } | ||
private bool HasNA(ref VBuffer<DZ> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA) return true; } return false; } | ||
private bool HasNA(ref VBuffer<TX> src) { for (int i = 0; i < src.Count; i++) { if (src.Values[i].IsNA) return true; } return false; } | ||
#endregion HasNA | ||
|
||
|
@@ -907,9 +892,6 @@ public ValueGetter<T> GetNAOrDefaultGetter<T>(ColumnType type) | |
private void GetNA(ref R4 value) => value = R4.NaN; | ||
private void GetNA(ref R8 value) => value = R8.NaN; | ||
private void GetNA(ref BL value) => value = BL.NA; | ||
private void GetNA(ref TS value) => value = TS.NA; | ||
private void GetNA(ref DT value) => value = DT.NA; | ||
private void GetNA(ref DZ value) => value = DZ.NA; | ||
private void GetNA(ref TX value) => value = TX.NA; | ||
#endregion GetNA | ||
|
||
|
@@ -1041,9 +1023,9 @@ public void Convert(ref BL src, ref SB dst) | |
else if (src.IsTrue) | ||
dst.Append("1"); | ||
} | ||
public void Convert(ref TS src, ref SB dst) { ClearDst(ref dst); if (!src.IsNA) dst.AppendFormat("{0:c}", (TimeSpan)src); } | ||
public void Convert(ref DT src, ref SB dst) { ClearDst(ref dst); if (!src.IsNA) dst.AppendFormat("{0:o}", (DateTime)src); } | ||
public void Convert(ref DZ src, ref SB dst) { ClearDst(ref dst); if (!src.IsNA) dst.AppendFormat("{0:o}", (DateTimeOffset)src); } | ||
public void Convert(ref TS src, ref SB dst) { ClearDst(ref dst); dst.AppendFormat("{0:c}", src); } | ||
public void Convert(ref DT src, ref SB dst) { ClearDst(ref dst); dst.AppendFormat("{0:o}", src); } | ||
public void Convert(ref DZ src, ref SB dst) { ClearDst(ref dst); dst.AppendFormat("{0:o}", src); } | ||
#endregion ToStringBuilder | ||
|
||
#region FromR4 | ||
|
@@ -1472,61 +1454,37 @@ public bool TryParse(ref TX src, out R8 dst) | |
|
||
public bool TryParse(ref TX src, out TS dst) | ||
{ | ||
dst = default; | ||
if (!src.HasChars) | ||
{ | ||
if (src.IsNA) | ||
dst = TS.NA; | ||
else | ||
dst = default(TS); | ||
return true; | ||
} | ||
TimeSpan res; | ||
if (TimeSpan.TryParse(src.ToString(), CultureInfo.InvariantCulture, out res)) | ||
{ | ||
dst = new TS(res); | ||
|
||
if (TimeSpan.TryParse(src.ToString(), CultureInfo.InvariantCulture, out dst)) | ||
return true; | ||
} | ||
dst = TS.NA; | ||
|
||
return IsStdMissing(ref src); | ||
} | ||
|
||
public bool TryParse(ref TX src, out DT dst) | ||
{ | ||
dst = default; | ||
if (!src.HasChars) | ||
{ | ||
if (src.IsNA) | ||
dst = DvDateTime.NA; | ||
else | ||
dst = default(DvDateTime); | ||
return true; | ||
} | ||
DateTime res; | ||
if (DateTime.TryParse(src.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out res)) | ||
{ | ||
dst = new DT(res); | ||
|
||
if (DateTime.TryParse(src.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out dst)) | ||
return true; | ||
} | ||
dst = DvDateTime.NA; | ||
|
||
return IsStdMissing(ref src); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So I feel like if you parse missing into a value type that does not support missing, we might expect the result to be that we would throw, rather than just the default value. #Resolved |
||
} | ||
|
||
public bool TryParse(ref TX src, out DZ dst) | ||
{ | ||
dst = default; | ||
if (!src.HasChars) | ||
{ | ||
if (src.IsNA) | ||
dst = DvDateTimeZone.NA; | ||
else | ||
dst = default(DvDateTimeZone); | ||
return true; | ||
} | ||
DateTimeOffset res; | ||
if (DateTimeOffset.TryParse(src.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out res)) | ||
{ | ||
dst = new DZ(res); | ||
|
||
if (DateTimeOffset.TryParse(src.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dst)) | ||
return true; | ||
} | ||
dst = DvDateTimeZone.NA; | ||
|
||
return IsStdMissing(ref src); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Similar for this. #Resolved |
||
} | ||
|
||
|
@@ -1804,21 +1762,10 @@ public void Convert(ref TX src, ref SB dst) | |
src.AddToStringBuilder(dst); | ||
} | ||
|
||
public void Convert(ref TX span, ref TS value) | ||
{ | ||
if (!TryParse(ref span, out value)) | ||
Contracts.Assert(value.IsNA); | ||
} | ||
public void Convert(ref TX span, ref DT value) | ||
{ | ||
if (!TryParse(ref span, out value)) | ||
Contracts.Assert(value.IsNA); | ||
} | ||
public void Convert(ref TX span, ref DZ value) | ||
{ | ||
if (!TryParse(ref span, out value)) | ||
Contracts.Assert(value.IsNA); | ||
} | ||
public void Convert(ref TX span, ref TS value) => TryParse(ref span, out value); | ||
public void Convert(ref TX span, ref DT value) => TryParse(ref span, out value); | ||
public void Convert(ref TX span, ref DZ value) => TryParse(ref span, out value); | ||
|
||
#endregion FromTX | ||
|
||
#region FromBL | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,11 @@ public CodecFactory(IHostEnvironment env, MemoryStreamPool memPool = null) | |
RegisterSimpleCodec(new UnsafeTypeCodec<ulong>(this)); | ||
RegisterSimpleCodec(new UnsafeTypeCodec<Single>(this)); | ||
RegisterSimpleCodec(new UnsafeTypeCodec<Double>(this)); | ||
RegisterSimpleCodec(new UnsafeTypeCodec<DvTimeSpan>(this)); | ||
RegisterSimpleCodec(new UnsafeTypeCodec<TimeSpan>(this)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is it still need to be UnsafeTypeCodec? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should it be? I have defined TimeSpanUnsafeTypeOps to handle this type. In reply to: 211110052 [](ancestors = 211110052) |
||
RegisterSimpleCodec(new DvTextCodec(this)); | ||
RegisterSimpleCodec(new BoolCodec(this)); | ||
RegisterSimpleCodec(new DateTimeCodec(this)); | ||
RegisterSimpleCodec(new DateTimeZoneCodec(this)); | ||
RegisterSimpleCodec(new DateTimeOffsetCodec(this)); | ||
RegisterSimpleCodec(new UnsafeTypeCodec<UInt128>(this)); | ||
|
||
// Register the old boolean reading codec. | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<see
tags perhaps #Resolved