Skip to content

Commit afe3e61

Browse files
author
Prashanth Govindarajan
authored
Throw for incompatible inPlace (dotnet#2778)
* Throw if inPlace is set and types mismatch * Unit test * Better error message * Remove empty lines
1 parent f09c30c commit afe3e61

7 files changed

+218
-48
lines changed

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.cs

+80
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ internal DataFrameColumn AddImplementation<U>(PrimitiveDataFrameColumn<U> column
580580
}
581581
else
582582
{
583+
if (inPlace)
584+
{
585+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
586+
}
583587
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
584588
decimalColumn._columnContainer.Add(column.CloneAsDecimalColumn()._columnContainer);
585589
return decimalColumn;
@@ -609,6 +613,10 @@ internal DataFrameColumn AddImplementation<U>(PrimitiveDataFrameColumn<U> column
609613
}
610614
else
611615
{
616+
if (inPlace)
617+
{
618+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
619+
}
612620
if (typeof(U) == typeof(decimal))
613621
{
614622
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -648,6 +656,10 @@ internal DataFrameColumn AddImplementation<U>(U value, bool inPlace)
648656
}
649657
else
650658
{
659+
if (inPlace)
660+
{
661+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
662+
}
651663
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
652664
decimalColumn._columnContainer.Add(DecimalConverter<U>.Instance.GetDecimal(value));
653665
return decimalColumn;
@@ -677,6 +689,10 @@ internal DataFrameColumn AddImplementation<U>(U value, bool inPlace)
677689
}
678690
else
679691
{
692+
if (inPlace)
693+
{
694+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
695+
}
680696
if (typeof(U) == typeof(decimal))
681697
{
682698
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -720,6 +736,10 @@ internal DataFrameColumn SubtractImplementation<U>(PrimitiveDataFrameColumn<U> c
720736
}
721737
else
722738
{
739+
if (inPlace)
740+
{
741+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
742+
}
723743
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
724744
decimalColumn._columnContainer.Subtract(column.CloneAsDecimalColumn()._columnContainer);
725745
return decimalColumn;
@@ -749,6 +769,10 @@ internal DataFrameColumn SubtractImplementation<U>(PrimitiveDataFrameColumn<U> c
749769
}
750770
else
751771
{
772+
if (inPlace)
773+
{
774+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
775+
}
752776
if (typeof(U) == typeof(decimal))
753777
{
754778
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -788,6 +812,10 @@ internal DataFrameColumn SubtractImplementation<U>(U value, bool inPlace)
788812
}
789813
else
790814
{
815+
if (inPlace)
816+
{
817+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
818+
}
791819
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
792820
decimalColumn._columnContainer.Subtract(DecimalConverter<U>.Instance.GetDecimal(value));
793821
return decimalColumn;
@@ -817,6 +845,10 @@ internal DataFrameColumn SubtractImplementation<U>(U value, bool inPlace)
817845
}
818846
else
819847
{
848+
if (inPlace)
849+
{
850+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
851+
}
820852
if (typeof(U) == typeof(decimal))
821853
{
822854
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -860,6 +892,10 @@ internal DataFrameColumn MultiplyImplementation<U>(PrimitiveDataFrameColumn<U> c
860892
}
861893
else
862894
{
895+
if (inPlace)
896+
{
897+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
898+
}
863899
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
864900
decimalColumn._columnContainer.Multiply(column.CloneAsDecimalColumn()._columnContainer);
865901
return decimalColumn;
@@ -889,6 +925,10 @@ internal DataFrameColumn MultiplyImplementation<U>(PrimitiveDataFrameColumn<U> c
889925
}
890926
else
891927
{
928+
if (inPlace)
929+
{
930+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
931+
}
892932
if (typeof(U) == typeof(decimal))
893933
{
894934
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -928,6 +968,10 @@ internal DataFrameColumn MultiplyImplementation<U>(U value, bool inPlace)
928968
}
929969
else
930970
{
971+
if (inPlace)
972+
{
973+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
974+
}
931975
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
932976
decimalColumn._columnContainer.Multiply(DecimalConverter<U>.Instance.GetDecimal(value));
933977
return decimalColumn;
@@ -957,6 +1001,10 @@ internal DataFrameColumn MultiplyImplementation<U>(U value, bool inPlace)
9571001
}
9581002
else
9591003
{
1004+
if (inPlace)
1005+
{
1006+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
1007+
}
9601008
if (typeof(U) == typeof(decimal))
9611009
{
9621010
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -1000,6 +1048,10 @@ internal DataFrameColumn DivideImplementation<U>(PrimitiveDataFrameColumn<U> col
10001048
}
10011049
else
10021050
{
1051+
if (inPlace)
1052+
{
1053+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
1054+
}
10031055
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
10041056
decimalColumn._columnContainer.Divide(column.CloneAsDecimalColumn()._columnContainer);
10051057
return decimalColumn;
@@ -1029,6 +1081,10 @@ internal DataFrameColumn DivideImplementation<U>(PrimitiveDataFrameColumn<U> col
10291081
}
10301082
else
10311083
{
1084+
if (inPlace)
1085+
{
1086+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
1087+
}
10321088
if (typeof(U) == typeof(decimal))
10331089
{
10341090
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -1068,6 +1124,10 @@ internal DataFrameColumn DivideImplementation<U>(U value, bool inPlace)
10681124
}
10691125
else
10701126
{
1127+
if (inPlace)
1128+
{
1129+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
1130+
}
10711131
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
10721132
decimalColumn._columnContainer.Divide(DecimalConverter<U>.Instance.GetDecimal(value));
10731133
return decimalColumn;
@@ -1097,6 +1157,10 @@ internal DataFrameColumn DivideImplementation<U>(U value, bool inPlace)
10971157
}
10981158
else
10991159
{
1160+
if (inPlace)
1161+
{
1162+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
1163+
}
11001164
if (typeof(U) == typeof(decimal))
11011165
{
11021166
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -1140,6 +1204,10 @@ internal DataFrameColumn ModuloImplementation<U>(PrimitiveDataFrameColumn<U> col
11401204
}
11411205
else
11421206
{
1207+
if (inPlace)
1208+
{
1209+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
1210+
}
11431211
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
11441212
decimalColumn._columnContainer.Modulo(column.CloneAsDecimalColumn()._columnContainer);
11451213
return decimalColumn;
@@ -1169,6 +1237,10 @@ internal DataFrameColumn ModuloImplementation<U>(PrimitiveDataFrameColumn<U> col
11691237
}
11701238
else
11711239
{
1240+
if (inPlace)
1241+
{
1242+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
1243+
}
11721244
if (typeof(U) == typeof(decimal))
11731245
{
11741246
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
@@ -1208,6 +1280,10 @@ internal DataFrameColumn ModuloImplementation<U>(U value, bool inPlace)
12081280
}
12091281
else
12101282
{
1283+
if (inPlace)
1284+
{
1285+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
1286+
}
12111287
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();
12121288
decimalColumn._columnContainer.Modulo(DecimalConverter<U>.Instance.GetDecimal(value));
12131289
return decimalColumn;
@@ -1237,6 +1313,10 @@ internal DataFrameColumn ModuloImplementation<U>(U value, bool inPlace)
12371313
}
12381314
else
12391315
{
1316+
if (inPlace)
1317+
{
1318+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
1319+
}
12401320
if (typeof(U) == typeof(decimal))
12411321
{
12421322
PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();

src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperations.tt

+22
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ namespace Microsoft.Data.Analysis
209209
}
210210
else
211211
{
212+
<# if (method.MethodType == MethodType.BinaryScalar) { #>
213+
if (inPlace)
214+
{
215+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
216+
}
217+
<# } else if (method.MethodType == MethodType.Binary) { #>
218+
if (inPlace)
219+
{
220+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
221+
}
222+
<# } #>
212223
<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #>
213224
PrimitiveDataFrameColumn<bool> newColumn = CloneAsBoolColumn();
214225
<# if (method.MethodType == MethodType.ComparisonScalar) { #>
@@ -277,6 +288,17 @@ namespace Microsoft.Data.Analysis
277288
}
278289
else
279290
{
291+
<# if (method.MethodType == MethodType.BinaryScalar) { #>
292+
if (inPlace)
293+
{
294+
throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(T)), nameof(value));
295+
}
296+
<# } else if (method.MethodType == MethodType.Binary) { #>
297+
if (inPlace)
298+
{
299+
throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));
300+
}
301+
<# } #>
280302
if (typeof(U) == typeof(decimal))
281303
{
282304
<# if (method.MethodType == MethodType.ComparisonScalar || method.MethodType == MethodType.Comparison) { #>

0 commit comments

Comments
 (0)