Skip to content

Commit 7d9230b

Browse files
committed
[MINOR] Frame convert test cover
Closes #2114
1 parent b979b2c commit 7d9230b

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameFromMatrixBlock.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ private static ValueType[] getSchema(MatrixBlock mb) {
8686
final int nRow = mb.getNumRows();
8787
// default boolean if possible.
8888
final ValueType[] schema = UtilFunctions.nCopies(nCol, ValueType.BOOLEAN);
89-
for(int c = 0; c < nCol; c++){
90-
for(int r = 0; r < nRow; r++){
91-
switch(schema[c]){
92-
case INT64:
93-
// keep the type as FP64 if long is detected
94-
schema[c] = ValueType.FP64;
89+
for(int c = 0; c < nCol; c++) {
90+
for(int r = 0; r < nRow; r++) {
91+
switch(schema[c]) {
9592
case FP64:
96-
break;
93+
break; // early termination of column default to highest
9794
default:
98-
final double v = mb.get(r, c);
99-
if(v > Integer.MAX_VALUE)
100-
schema[c] = ValueType.FP64; // handle Integer overflow.
101-
schema[c] = FrameUtil.isType(v, schema[c]);
95+
schema[c] = FrameUtil.isType(mb.get(r, c), schema[c]);
10296
}
10397
}
10498
}
@@ -114,15 +108,13 @@ else if(mb.isInSparseFormat())
114108
convertToFrameBlockSparse();
115109
else
116110
convertToFrameBlockDense();
117-
if(frame.getNumRows() != mb.getNumRows())
118-
throw new DMLRuntimeException("Invalid result");
119111

120112
return frame;
121113
}
122-
catch(InterruptedException | ExecutionException e) {
123-
throw new DMLRuntimeException("failed to convert to matrix block");
114+
catch(Exception e) {
115+
throw new DMLRuntimeException("failed to convert to matrix block", e);
124116
}
125-
finally{
117+
finally {
126118
if(pool != null)
127119
pool.shutdown();
128120
}

src/main/java/org/apache/sysds/runtime/frame/data/lib/FrameLibCompress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.sysds.runtime.frame.data.FrameBlock;
2323
import org.apache.sysds.runtime.frame.data.compress.CompressedFrameBlockFactory;
2424

25-
public class FrameLibCompress {
25+
public interface FrameLibCompress {
2626

2727
public static FrameBlock compress(FrameBlock in, int k) {
2828
return compress(in, k, null);

src/test/java/org/apache/sysds/test/component/frame/FrameCustomTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void castToFrame() {
3535
double maxp1 = Integer.MAX_VALUE + 1.0;
3636
MatrixBlock mb = TestUtils.generateTestMatrixBlock(100, 100, maxp1, maxp1, 1.0, 23);
3737
FrameBlock f = DataConverter.convertToFrameBlock(mb);
38-
assertTrue(f.getSchema()[0] == ValueType.FP64);
38+
assertTrue(f.getSchema()[0] == ValueType.INT64);
3939
}
4040

4141
@Test
@@ -47,10 +47,10 @@ public void castToFrame3() {
4747
}
4848

4949
@Test
50-
public void castErrorValue() {
50+
public void castIntegerValue() {
5151
MatrixBlock mb = new MatrixBlock(10, 10, Double.parseDouble("2.572306572E9"));
5252
FrameBlock f = DataConverter.convertToFrameBlock(mb);
53-
assertTrue(f.getSchema()[0] == ValueType.FP64);
53+
assertTrue(f.getSchema()[0] == ValueType.INT64);
5454
}
5555

5656
@Test

src/test/java/org/apache/sysds/test/component/frame/FrameFromMatrixBlockTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
package org.apache.sysds.test.component.frame;
2020

2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertThrows;
2223
import static org.junit.Assert.assertTrue;
2324
import static org.junit.Assert.fail;
25+
import static org.mockito.Mockito.spy;
26+
import static org.mockito.Mockito.when;
2427

2528
import org.apache.commons.logging.Log;
2629
import org.apache.commons.logging.LogFactory;
2730
import org.apache.sysds.common.Types.ValueType;
31+
import org.apache.sysds.runtime.DMLRuntimeException;
2832
import org.apache.sysds.runtime.data.DenseBlockFP64;
2933
import org.apache.sysds.runtime.frame.data.FrameBlock;
3034
import org.apache.sysds.runtime.frame.data.lib.FrameFromMatrixBlock;
@@ -162,6 +166,17 @@ public void randomVerySparse() {
162166
verifyEquivalence(mb, fb);
163167
}
164168

169+
@Test
170+
public void error(){
171+
MatrixBlock mb = TestUtils.ceil(TestUtils.generateTestMatrixBlock(1000, 1, 0, 199, 0.01, 213));
172+
MatrixBlock spy = spy(mb);
173+
when(spy.isEmpty()).thenThrow(new DMLRuntimeException("Intended Error"));
174+
Exception e = assertThrows(DMLRuntimeException.class, () -> FrameFromMatrixBlock.convertToFrameBlock(spy, new ValueType[]{ValueType.FP64}, 1));
175+
assertTrue(e.getMessage().contains("failed to convert to matrix block"));
176+
}
177+
178+
179+
165180
// @Test
166181
// public void timeChange() {
167182
// MatrixBlock mb = TestUtils.generateTestMatrixBlock(64000, 2000, 1, 1, 0.5, 2340);

0 commit comments

Comments
 (0)