Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rows from dataframe #131

Merged
merged 11 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/src/main/scala/org/polars/scala/polars/api/DataFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DataFrame private (private[polars] val ptr: Long) {

val schema: Schema = {
val schemaString = data_frame.schemaString(ptr)
Schema.from(schemaString)
Schema.fromString(schemaString)
}

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

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

/** Provides an iterator to traverse a specified number of rows from the DataFrame.
* @param nRows
* number of rows to traverse
* @note
* if `nRows` is greater than the total rows in DataFrame then all rows are included.
* @return
* Iterator of [[Row]]
*/
def rows(nRows: Long): Iterator[Row] = RowIterator.withPtr(ptr).lazyIterator(nRows)

/** Provides an iterator to traverse a all rows from the DataFrame.
* @return
* Iterator of [[Row]]
*/
def rows(): Iterator[Row] = rows(-1L)

def write(): Writeable = new Writeable(ptr)

}
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/org/polars/scala/polars/api/JSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.polars.scala.polars.internal.jni.series;

class JSeries {
final static String EmptyString = "";

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

return Series.ofSeries(name, sList);
long[] ptrs = sList.stream().map(Series::ptr).mapToLong(Long::longValue).toArray();
return Series.withPtr(series.new_list_series(name, ptrs));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LazyFrame private (private[polars] val ptr: Long) {

val schema: Schema = {
val schemaString = lazy_frame.schemaString(ptr)
Schema.from(schemaString)
Schema.fromString(schemaString)
}

val width: Int = schema.getFields.length
Expand Down
Loading