Data-Frame

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "PDL" : "2.019",
            "PDL::Basic" : "0",
            "PDL::Core" : "0",
            "PDL::DateTime" : "0",
            "PDL::Lite" : "0",
            "PDL::Primitive" : "0",
            "PDL::Types" : "0",
            "POSIX" : "0",
            "Package::Stash" : "0",
            "Path::Tiny" : "0",
            "Ref::Util" : "0.204",
            "Role::Tiny" : "0",
            "Role::Tiny::With" : "0",
            "Safe::Isa" : "1.000009",
            "Scalar::Util" : "0",
            "Sereal::Encoder" : "4.005",
            "Test2::API" : "0",
            "Test2::Util::Ref" : "0",
            "Test2::Util::Table" : "0",
            "Text::CSV" : "0",
            "Text::Table::Tiny" : "0",

META.yml  view on Meta::CPAN

  PDL: '2.019'
  PDL::Basic: '0'
  PDL::Core: '0'
  PDL::DateTime: '0'
  PDL::Lite: '0'
  PDL::Primitive: '0'
  PDL::Types: '0'
  POSIX: '0'
  Package::Stash: '0'
  Path::Tiny: '0'
  Ref::Util: '0.204'
  Role::Tiny: '0'
  Role::Tiny::With: '0'
  Safe::Isa: '1.000009'
  Scalar::Util: '0'
  Sereal::Encoder: '4.005'
  Test2::API: '0'
  Test2::Util::Ref: '0'
  Test2::Util::Table: '0'
  Text::CSV: '0'
  Text::Table::Tiny: '0'

Makefile.PL  view on Meta::CPAN

    "PDL" => "2.019",
    "PDL::Basic" => 0,
    "PDL::Core" => 0,
    "PDL::DateTime" => 0,
    "PDL::Lite" => 0,
    "PDL::Primitive" => 0,
    "PDL::Types" => 0,
    "POSIX" => 0,
    "Package::Stash" => 0,
    "Path::Tiny" => 0,
    "Ref::Util" => "0.204",
    "Role::Tiny" => 0,
    "Role::Tiny::With" => 0,
    "Safe::Isa" => "1.000009",
    "Scalar::Util" => 0,
    "Sereal::Encoder" => "4.005",
    "Test2::API" => 0,
    "Test2::Util::Ref" => 0,
    "Test2::Util::Table" => 0,
    "Text::CSV" => 0,
    "Text::Table::Tiny" => 0,

Makefile.PL  view on Meta::CPAN

  "PDL" => "2.019",
  "PDL::Basic" => 0,
  "PDL::Core" => 0,
  "PDL::DateTime" => 0,
  "PDL::Lite" => 0,
  "PDL::Primitive" => 0,
  "PDL::Types" => 0,
  "POSIX" => 0,
  "Package::Stash" => 0,
  "Path::Tiny" => 0,
  "Ref::Util" => "0.204",
  "Role::Tiny" => 0,
  "Role::Tiny::With" => 0,
  "Safe::Isa" => "1.000009",
  "Scalar::Util" => 0,
  "Sereal::Encoder" => "4.005",
  "Test2::API" => 0,
  "Test2::Tools::PDL" => "0.0004",
  "Test2::Tools::Warnings" => 0,
  "Test2::Util::Ref" => 0,
  "Test2::Util::Table" => 0,

cpanfile  view on Meta::CPAN

requires "PDL" => "2.019";
requires "PDL::Basic" => "0";
requires "PDL::Core" => "0";
requires "PDL::DateTime" => "0";
requires "PDL::Lite" => "0";
requires "PDL::Primitive" => "0";
requires "PDL::Types" => "0";
requires "POSIX" => "0";
requires "Package::Stash" => "0";
requires "Path::Tiny" => "0";
requires "Ref::Util" => "0.204";
requires "Role::Tiny" => "0";
requires "Role::Tiny::With" => "0";
requires "Safe::Isa" => "1.000009";
requires "Scalar::Util" => "0";
requires "Sereal::Encoder" => "4.005";
requires "Test2::API" => "0";
requires "Test2::Util::Ref" => "0";
requires "Test2::Util::Table" => "0";
requires "Text::CSV" => "0";
requires "Text::Table::Tiny" => "0";

lib/Data/Frame.pm  view on Meta::CPAN

use PDL::Core qw(pdl null);
use List::AllUtils 0.19 qw(
  each_arrayref pairgrep pairkeys pairmap pairwise reduce zip
);

use PDL::DateTime  ();
use PDL::Primitive ();
use PDL::Factor    ();
use PDL::SV        ();
use PDL::StringfiableExtension;
use Ref::Util qw(is_plain_arrayref is_plain_hashref);
use Scalar::Util qw(blessed looks_like_number);
use Sereal::Encoder 4.005;
use Text::Table::Tiny;
use Type::Params;
use Types::Standard qw(
  Any ArrayRef CodeRef Enum CycleTuple HashRef Maybe Str
);
use Types::PDL qw(Piddle Piddle1D);

use Data::Frame::Column::Helper;

lib/Data/Frame.pm  view on Meta::CPAN


# Relative tolerance. This can be used for data frame comparison.
our $TOLERANCE_REL = undef;
our $doubleformat = '%.8g';

# Check if all columns have same length or have a length of 1.
around BUILDARGS($orig, $class : @args) {
    my %args = @args;   

    if ( my $columns = $args{columns} ) {
        my $columns_is_aref = Ref::Util::is_plain_arrayref($columns);
        my $columns_href;
        if ($columns_is_aref) {
            $columns_href = {@$columns};
        }
        else {
            $columns_href = $columns;
        }

        my @lengths    = map { $_->length } values %$columns_href;
        my $max_length = List::AllUtils::max(@lengths);

lib/Data/Frame.pm  view on Meta::CPAN

method exists ($col_name) {
    $self->_columns->exists($col_name);
}

method delete ($col_name) {
    $self->_columns->delete($col_name);
}

method rename ((HashRef | CodeRef) $href_or_coderef) {
    my $f =
      Ref::Util::is_plain_coderef($href_or_coderef)
      ? $href_or_coderef
      : sub { $href_or_coderef->{ $_[0] } };
    my $new_names = $self->names->map( sub { $f->($_) // $_ } );
    $self->names($new_names);
    return $self;
}


method set ($indexer, $data) {
    state $check =

lib/Data/Frame.pm  view on Meta::CPAN

}


method isempty () { $self->nrow == 0; }


method column_names(@rest) {
    my @colnames =
      (
        @rest == 1
          and ( Ref::Util::is_plain_arrayref( $rest[0] )
            or $rest[0]->$_can('flatten') )
      )
      ? $rest[0]->flatten
      : @rest;

	if( @colnames ) {
        unless (@colnames == $self->length) {
			failure::columns::length->throw({
					msg => "incorrect number of column names",
					trace => failure->croak_trace,

lib/Data/Frame.pm  view on Meta::CPAN


*col_names = \&column_names;
*names = \&column_names;

sub row_names {
	my ($self, @rest) = @_;
	if( @rest ) {
		# setting row names
		my $new_rows;
        if ( ref $rest[0] ) {
            if ( Ref::Util::is_plain_arrayref($rest[0]) ) {
                $new_rows = [ @{$rest[0]} ];
            }
            elsif ( $rest[0]->isa('PDL') ) {

                # TODO just run uniq?
                $new_rows = $rest[0]->unpdl;
            }
        }
        $new_rows //= [ @rest ];

lib/Data/Frame.pm  view on Meta::CPAN

        (
            CodeRef | ( HashRef [ Maybe [CodeRef] ] ) |
              ( CycleTuple [ Str, Maybe [CodeRef] ] )
        )
    );
    ($func) = $check->($func);

    my $class = ref($self);

    my @columns;
    if ( Ref::Util::is_coderef($func) ) {
        @columns =
          $self->names->map( sub {
            $_ => $func->( $self->column($_), $self );
          } )->flatten;
    }
    else {    # hashref or arrayref
        my $column_names = $self->names;
        my $hashref;
        my @new_column_names;
        if ( Ref::Util::is_hashref($func) ) {
            $hashref = $func;
            @new_column_names =
              grep { !$self->exists($_) } sort( keys %$hashref );
        }
        else {    # arrayref
            $hashref = {@$func};
            @new_column_names = grep { !$self->exists($_) } ( pairkeys @$func );
        }

        @columns = $column_names->map(

lib/Data/Frame.pm  view on Meta::CPAN



method sort ($by_columns, $ascending=true) {
    return $self->clone if $by_columns->length == 0;

    my $row_indices = $self->sorti( $by_columns, $ascending );
    return $self->select_rows($row_indices);
}

method sorti ($by_columns, $ascending=true) {
    if (Ref::Util::is_plain_arrayref($ascending)) {
        $ascending = logical($ascending);
    }

    return pdl( [ 0 .. $self->nrow - 1 ] ) if $by_columns->length == 0;

    my $is_number = $by_columns->map( sub { $self->is_numeric_column($_) } );
    my $compare = sub {
        my ( $a, $b ) = @_;
        for my $i ( 0 .. $#$is_number ) {
            my $rslt = (

lib/Data/Frame/Autobox.pm  view on Meta::CPAN

sub setdiff {
    my ($array, $other) = @_;
    my %hash = map { $_ => 1 } @$other;
    return [ grep { not exists( $hash{$_} ) } @$array ];
}
 

package Data::Frame::Autobox::HASH;
$Data::Frame::Autobox::HASH::VERSION = '0.006004';
use Carp;
use Ref::Util;
use List::AllUtils qw(pairmap);


sub isempty { keys %{ $_[0] } == 0 } 

sub delete {
    my ($hash, $key) = @_;
    CORE::delete $hash->{$key};
}
 

lib/Data/Frame/Autobox.pm  view on Meta::CPAN

    [ CORE::values %$hash ];
}
 

sub copy { { %{ $_[0] } } }

sub rename {
    my ( $hash, $href_or_coderef ) = @_;

    my %new_hash;
    if ( Ref::Util::is_coderef($href_or_coderef) ) {
        %new_hash = pairmap { ( $href_or_coderef->($a) // $a ) => $b } %$hash;
    }
    else {
        %new_hash = pairmap { ( $href_or_coderef->{$a} // $a ) => $b } %$hash;
    }
    return \%new_hash;
}

1;

lib/Data/Frame/IO/CSV.pm  view on Meta::CPAN


use PDL::Core qw(pdl null);
use PDL::Primitive ();
use PDL::Factor    ();
use PDL::SV        ();
use PDL::DateTime  ();
use PDL::Types     ();

use List::AllUtils qw(uniq);
use Package::Stash;
use Ref::Util qw(is_plain_arrayref is_plain_hashref);
use Scalar::Util qw(openhandle looks_like_number);
use Type::Params;
use Types::Standard qw(Any ArrayRef CodeRef Enum HashRef Map Maybe Str);
use Types::PDL qw(Piddle);
use Text::CSV;

use Data::Frame::Util qw(guess_and_convert_to_pdl);
use Data::Frame::Types qw(DataType);


lib/Data/Frame/Indexer.pm  view on Meta::CPAN

my $NumericIndices =
  ColumnLike->where( sub { $_->type ne 'byte' and not is_discrete($_) } );

fun _as_indexer ($fallback_indexer_class) {
    return sub {
        my $x = @_ > 1 ? \@_ : @_ == 1 ? $_[0] : [];

        return undef unless defined $x;
        return $x if ( Indexer->check($x) );

        unless ( Ref::Util::is_plain_arrayref($x) or $x->$_DOES('PDL') ) {
            $x = [$x];
        }
        if ( $NumericIndices->check($x) ) {
            return Data::Frame::Indexer::Integer->new( indexer => $x->unpdl );
        }
        $fallback_indexer_class->new( indexer => $x );
    };
}

*indexer_s  = _as_indexer('Data::Frame::Indexer::Label');

lib/Data/Frame/Partial/Sugar.pm  view on Meta::CPAN

        my $self = shift;
        state $check = Type::Params::compile(Value | ArrayRef | Piddle);
        my ($key) = $check->(@_);
        return $key;
    }

    sub STORE {
        my ( $self, $key, $val ) = @_;
        $key = $self->_check_key($key);

        if ( Ref::Util::is_ref($key) ) {
            $self->object->slice($key) .= $val;
        } else {
            $self->object->set($key, $val);
        }
    }

    sub FETCH {
        my ( $self, $key ) = @_;
        $key = $self->_check_key($key);

        if ( Ref::Util::is_ref($key) ) {
            return $self->object->slice($key);
        } else {
            return $self->object->at($key);
        }
    }

    sub EXISTS {
        my ($self, $key) = @_;
        return $self->object->exists($key);
    }

lib/Data/Frame/Setup.pm  view on Meta::CPAN


use utf8;
use feature ':5.16';

use Import::Into;

use Carp;
use Data::Dumper ();
use Function::Parameters 2.001003;
use PDL::Lite ();   # PDL::Lite is the minimal to get PDL work
use Ref::Util 0.204           ();
use Safe::Isa 1.000009        ();
use Feature::Compat::Try ();
use boolean ();

use Moo 2.003004 ();
use Moo::Role ();

use List::AllUtils qw(uniq);

use Data::Frame::Autobox ();

lib/Data/Frame/Setup.pm  view on Meta::CPAN


    if ( $tag eq ':base' ) {
        strict->import::into($target);
        warnings->import::into($target);
        utf8->import::into($target);
        feature->import::into( $target, ':5.16' );

        Carp->import::into($target);
        Data::Dumper->import::into($target);
        Function::Parameters->import::into($target);
        Ref::Util->import::into($target);
        Safe::Isa->import::into($target);
        Feature::Compat::Try->import::into($target);
        boolean->import::into($target);

        Data::Frame::Autobox->import::into($target);
    }
    elsif ( $tag eq ':class' ) {
        $class->_import_tag( $target, ':base' );

        Function::Parameters->import::into( $target,

lib/PDL/Factor.pm  view on Meta::CPAN

use 5.016;
use warnings;

use failures qw/levels::mismatch levels::number/;

use PDL::Lite ();   # PDL::Lite is the minimal to get PDL work
use PDL::Core qw(pdl);
use PDL::Primitive qw(which);

use Module::Load;
use Ref::Util qw(is_plain_arrayref);
use Safe::Isa;
use Scalar::Util qw(blessed);
use Type::Params;
use Types::Standard qw(slurpy ArrayRef ConsumerOf Int);
use List::AllUtils ();

use parent 'PDL';
use Class::Method::Modifiers;

use Role::Tiny::With;

lib/PDL/Logical.pm  view on Meta::CPAN

package PDL::Logical;
$PDL::Logical::VERSION = '0.006004';
# ABSTRACT: PDL subclass for keeping logical data

use 5.016;
use warnings;

use PDL::Lite ();   # PDL::Lite is the minimal to get PDL work
use PDL::Core qw(pdl);

use Ref::Util qw(is_plain_arrayref);
use Safe::Isa;

use parent 'PDL';
use Class::Method::Modifiers;

sub new {
    my ( $class, @args ) = @_;

    my $data;
    if ( @args % 2 != 0 ) {

lib/PDL/SV.pm  view on Meta::CPAN

$PDL::SV::VERSION = '0.006004';
# ABSTRACT: PDL subclass for keeping scalar data (like strings)

use 5.016;
use warnings;

use PDL::Lite ();   # PDL::Lite is the minimal to get PDL work
use PDL::Core qw(pdl);
use PDL::Primitive qw(which);

use Ref::Util qw(is_plain_arrayref);
use Safe::Isa;
use Type::Params;
use Types::Standard qw(slurpy ArrayRef ConsumerOf Int);
use List::AllUtils ();

use parent 'PDL';
use Class::Method::Modifiers;

use Role::Tiny::With;
with qw(PDL::Role::Stringifiable);



( run in 0.369 second using v1.01-cache-2.11-cpan-a5abf4f5562 )