Skip to content

Commit

Permalink
DataFrame: sampleFromRows method added (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Dec 17, 2020
1 parent 51db910 commit e6be0f6
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 155 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci_pipeline.yml
@@ -0,0 +1,37 @@
name: CI pipeline

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

container:
image: google/dart:latest

steps:
- uses: actions/checkout@v2

- name: Print Dart SDK version
run: dart --version

- name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze --fatal-infos

- name: Run tests
run: dart test

- name: Code coverage
run: dart pub run test_coverage

- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 0.3.0
- `DataFrame`: `sampleFromRows` method added
- `CI`: github actions set up

## 0.2.0
- `DataFrame`: `shuffle` method added

Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.com/gyrdym/ml_dataframe.svg?branch=master)](https://travis-ci.com/gyrdym/ml_dataframe)
[![Build Status](https://github.com/gyrdym/ml_dataframe/workflows/CI%20pipeline/badge.svg)](https://github.com/gyrdym/ml_dataframe/actions?query=branch%3Amaster+)
[![Coverage Status](https://coveralls.io/repos/github/gyrdym/ml_dataframe/badge.svg?branch=master)](https://coveralls.io/github/gyrdym/ml_dataframe?branch=master)
[![pub package](https://img.shields.io/pub/v/ml_dataframe.svg)](https://pub.dartlang.org/packages/ml_dataframe)
[![Gitter Chat](https://badges.gitter.im/gyrdym/gyrdym.svg)](https://gitter.im/gyrdym/)
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
@@ -1 +1 @@
include: package:ml_tech/analysis_options.yaml
include: package:pedantic/analysis_options.yaml
8 changes: 7 additions & 1 deletion lib/src/data_frame/data_frame.dart
Expand Up @@ -148,7 +148,7 @@ abstract class DataFrame implements Serializable {
DataFrame addSeries(Series series);

/// Returns a dataframe, sampled from series that are obtained from the
/// provided series [indices] or series [names].
/// series [indices] or series [names].
///
/// If [indices] are specified, [names] parameter will be ignored.
///
Expand All @@ -158,6 +158,12 @@ abstract class DataFrame implements Serializable {
Iterable<String> names,
});

/// Returns a dataframe, sampled from rows that are obtained from the
/// rows [indices]
///
/// Rows indices may be repeating.
DataFrame sampleFromRows(Iterable<int> indices);

/// Returns a new [DataFrame] without specified series
DataFrame dropSeries({
Iterable<int> seriesIndices,
Expand Down
13 changes: 12 additions & 1 deletion lib/src/data_frame/data_frame_impl.dart
Expand Up @@ -13,7 +13,6 @@ import 'package:ml_linalg/dtype.dart';
import 'package:ml_linalg/linalg.dart';
import 'package:ml_linalg/matrix.dart';
import 'package:quiver/iterables.dart';
import 'dart:math' as math;

part 'data_frame_impl.g.dart';

Expand Down Expand Up @@ -107,6 +106,18 @@ class DataFrameImpl with SerializableMixin implements DataFrame {
return _sampleFromSeries(names);
}

@override
DataFrame sampleFromRows(Iterable<int> indices) {
final rowsAsList = rows.toList(growable: false);
final selectedRows = indices.map((index) => rowsAsList[index]);

return DataFrame(
selectedRows,
headerExists: false,
header: header,
);
}

@override
DataFrame addSeries(Series newSeries) {
if (newSeries.data.length != shape.first) {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/data_frame/factories/from_raw_data.dart
Expand Up @@ -14,13 +14,17 @@ DataFrame fromRawData(Iterable<Iterable<dynamic>> data, {
}) {
final columnsNum = columns.isNotEmpty
? columns.length
: data.first.length;
: data.isEmpty
? predefinedHeader.length
: data.first.length;

final header = getHeader(
columnsNum,
autoHeaderPrefix,
headerExists
? data.first.map((dynamic el) => el.toString())
? data.isEmpty
? []
: data.first.map((dynamic el) => el.toString())
: [],
predefinedHeader);

Expand Down

0 comments on commit e6be0f6

Please sign in to comment.