Skip to content

Commit 17cda05

Browse files
authored
Bump OpenML API Version to 1.0.0 (#29)
* Bump OpenML API Version to 1.0.0 Summary: Despite the bump, some code had to be changed to accomodate the new breaking changes * Forbide dataset schemas with no target variable. * Adrress Codacy report * Remove unused import
1 parent 8e6b0ef commit 17cda05

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

openml-python-common/src/main/java/com/feedzai/openml/python/ClassificationPythonModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ public ClassificationPythonModel(final JepInstance jepInstance,
121121
final String id,
122122
final String classifyFunctionName,
123123
final String getClassDistributionFunctionName) {
124-
124+
final int targetIndex = schema.getTargetIndex()
125+
.orElseThrow(() -> new IllegalArgumentException("Python classification models do not support datasets without schema."));
125126
this.jepInstance = jepInstance;
126127
this.schema = schema;
127128
this.predictiveFieldIndexes = IntStream.range(0, schema.getFieldSchemas().size())
128-
.filter(index -> index != schema.getTargetIndex())
129+
.filter(index -> index != targetIndex)
129130
.toArray();
130131

131132
this.id = id;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.feedzai.openml.python;/*
2+
* The copyright of this file belongs to Feedzai. The file cannot be
3+
* reproduced in whole or in part, stored in a retrieval system,
4+
* transmitted in any form, or by any means electronic, mechanical,
5+
* photocopying, or otherwise, without the prior permission of the owner.
6+
*
7+
* © 2019 Feedzai, Strictly Confidential
8+
*/
9+
10+
import com.feedzai.openml.data.schema.DatasetSchema;
11+
import com.feedzai.openml.data.schema.FieldSchema;
12+
import com.feedzai.openml.data.schema.NumericValueSchema;
13+
import com.feedzai.openml.python.jep.instance.JepInstance;
14+
import com.google.common.collect.ImmutableList;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
20+
/**
21+
* Tests the behaviour of a {@link ClassificationPythonModel}.
22+
*
23+
* @author Joao Sousa (joao.sousa@feedzai.com)
24+
* @since @@@feedzai.next.release@@@
25+
*/
26+
public class ClassificationPythonModelTest {
27+
28+
/**
29+
* A field to use in the tests.
30+
*/
31+
private static final FieldSchema FIELD_SCHEMA =
32+
new FieldSchema("field", 0, new NumericValueSchema(false));
33+
34+
35+
/**
36+
* The wrapper for the Jep object used in the tests.
37+
*/
38+
private JepInstance jepInstance;
39+
40+
/**
41+
* Initializes an instance of {@link JepInstance}.
42+
*/
43+
@Before
44+
public void setUp() {
45+
this.jepInstance = new JepInstance();
46+
this.jepInstance.start();
47+
}
48+
49+
/**
50+
* Tests that by passing a dataset schema with no target variable, will make the model creation fail.
51+
*/
52+
@Test
53+
public final void testSchemaWithoutTargetVariable() {
54+
final ImmutableList<FieldSchema> fields = ImmutableList.of(FIELD_SCHEMA);
55+
final DatasetSchema schema = new DatasetSchema(fields);
56+
57+
assertThatThrownBy(() -> new ClassificationPythonModel(this.jepInstance, schema, "classificationModel"))
58+
.as("A classification model created with a schema with no target variable")
59+
.isInstanceOf(IllegalArgumentException.class);
60+
}
61+
62+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<assertj.version>3.7.0</assertj.version>
8080
<jackson.version>2.6.7</jackson.version>
8181
<jackson-databind.version>2.6.7</jackson-databind.version>
82-
<openml-api.version>0.3.0</openml-api.version>
82+
<openml-api.version>1.0.0</openml-api.version>
8383
<jep.version>3.7.0</jep.version>
8484
</properties>
8585

0 commit comments

Comments
 (0)