SmileConverter { public DataFrame toDataFrame() { StructType schema = DataTypes.struct( table.columns().stream() .map(col -> new StructField(col.name(), toSmileType(col.type()))) .collect(Collectors.toList())); return toDataFrame(schema); } SmileConverter(Relation table); DataFrame toDataFrame(); DataFrame toDataFrame(StructType schema);  }
@Test public void regression() throws IOException { Table moneyball = Table.read().csv("../data/baseball.csv"); moneyball.addColumns( moneyball.numberColumn("RS").subtract(moneyball.numberColumn("RA")).setName("RD")); LinearModel winsModel = OLS.fit(Formula.lhs("RD"), moneyball.select("W", "RD").smile().toDataFrame()); assertNotNull(winsModel.toString()); }
@Test public void allColumnTypes() throws IOException { Table table = Table.create(); table.addColumns(BooleanColumn.create("boolean", new boolean[] {true, false})); table.addColumns(DoubleColumn.create("double", new double[] {1.2, 3.4})); table.addColumns(FloatColumn.create("float", new float[] {5.6f, 7.8f})); table.addColumns( InstantColumn.create( "instant", new Instant[] { Instant.ofEpochMilli(1578452479123l), Instant.ofEpochMilli(1578451111111l) })); table.addColumns(IntColumn.create("int", new int[] {8, 9})); table.addColumns( DateColumn.create( "date", new LocalDate[] {LocalDate.of(2020, 01, 01), LocalDate.of(2020, 01, 07)})); table.addColumns( DateTimeColumn.create( "datetime", new LocalDateTime[] { LocalDateTime.ofInstant(Instant.ofEpochMilli(1333352479123l), ZoneOffset.UTC), LocalDateTime.ofInstant(Instant.ofEpochMilli(1333333333333l), ZoneOffset.UTC) })); table.addColumns( TimeColumn.create( "time", new LocalTime[] {LocalTime.of(8, 37, 48), LocalTime.of(8, 59, 06)})); table.addColumns(LongColumn.create("long", new long[] {3l, 4l})); table.addColumns(ShortColumn.create("short", new short[] {1, 2})); table.addColumns(StringColumn.create("string", new String[] {"james", "bond"})); table.addColumns(TextColumn.create("text", new String[] {"foo", "bar"})); DataFrame dataframe = table.smile().toDataFrame(); assertEquals(2, dataframe.nrows()); }