Skip to content

Commit ae0a03c

Browse files
authored
Get rows from dataframe (chitralverma#131)
* get rows from dataframe * rename rowIterator to rows * add docs * add Series of Time * add remaining basic types to row * more functions for rows * fix doc lint * allow creation of struct series * allow creation of schema from fields * add struct types to row * remove unused dependencies
1 parent da38d80 commit ae0a03c

File tree

22 files changed

+1360
-276
lines changed

22 files changed

+1360
-276
lines changed

core/src/main/scala/org/polars/scala/polars/api/DataFrame.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DataFrame private (private[polars] val ptr: Long) {
1515

1616
val schema: Schema = {
1717
val schemaString = data_frame.schemaString(ptr)
18-
Schema.from(schemaString)
18+
Schema.fromString(schemaString)
1919
}
2020

2121
val width: Int = schema.getFields.length
@@ -167,6 +167,22 @@ class DataFrame private (private[polars] val ptr: Long) {
167167

168168
def count(): Long = data_frame.count(ptr)
169169

170+
/** Provides an iterator to traverse a specified number of rows from the DataFrame.
171+
* @param nRows
172+
* number of rows to traverse
173+
* @note
174+
* if `nRows` is greater than the total rows in DataFrame then all rows are included.
175+
* @return
176+
* Iterator of [[Row]]
177+
*/
178+
def rows(nRows: Long): Iterator[Row] = RowIterator.withPtr(ptr).lazyIterator(nRows)
179+
180+
/** Provides an iterator to traverse a all rows from the DataFrame.
181+
* @return
182+
* Iterator of [[Row]]
183+
*/
184+
def rows(): Iterator[Row] = rows(-1L)
185+
170186
def write(): Writeable = new Writeable(ptr)
171187

172188
}

core/src/main/scala/org/polars/scala/polars/api/JSeries.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.stream.Collectors;
1414
import java.util.stream.StreamSupport;
1515

16+
import org.polars.scala.polars.internal.jni.series;
17+
1618
class JSeries {
1719
final static String EmptyString = "";
1820

@@ -65,6 +67,7 @@ static Series ofList(String name, Iterable<Iterable> values) {
6567
sList.add(thisSeries);
6668
}
6769

68-
return Series.ofSeries(name, sList);
70+
long[] ptrs = sList.stream().map(Series::ptr).mapToLong(Long::longValue).toArray();
71+
return Series.withPtr(series.new_list_series(name, ptrs));
6972
}
7073
}

core/src/main/scala/org/polars/scala/polars/api/LazyFrame.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LazyFrame private (private[polars] val ptr: Long) {
1515

1616
val schema: Schema = {
1717
val schemaString = lazy_frame.schemaString(ptr)
18-
Schema.from(schemaString)
18+
Schema.fromString(schemaString)
1919
}
2020

2121
val width: Int = schema.getFields.length

0 commit comments

Comments
 (0)