| 1 |
|
| package Data::Frame; |
| 2 |
11 |
| $Data::Frame::VERSION = '0.006005'; |
| 3 |
|
| # ABSTRACT: data frame implementation |
| 4 |
|
| |
| 5 |
11 |
▶ | use 5.016; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 6 |
11 |
▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 7 |
|
| |
| 8 |
13 |
▶ | use Data::Frame::Class; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 9 |
11 |
| with 'MooX::Traits'; |
| 10 |
|
| |
| 11 |
16 |
▶ | use failures qw{ |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 12 |
|
| columns::mismatch columns::length columns::unbalanced |
| 13 |
|
| rows::mismatch rows::length rows::unique |
| 14 |
|
| column::exists column::name::string |
| 15 |
|
| index index::exists |
| 16 |
16 |
| }; |
| 17 |
|
| |
| 18 |
13 |
▶ | use Hash::Ordered; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 19 |
14 |
▶ | use PDL::Basic qw(sequence); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 20 |
11 |
▶ | use PDL::Core qw(pdl null); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 21 |
11 |
▶ | use List::AllUtils 0.19 qw( |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 22 |
|
| each_arrayref pairgrep pairkeys pairmap pairwise reduce zip |
| 23 |
11 |
| ); |
| 24 |
|
| |
| 25 |
11 |
▶ | use PDL::DateTime (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 26 |
11 |
▶ | use PDL::Primitive (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 27 |
11 |
▶ | use PDL::Factor (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 28 |
11 |
▶ | use PDL::SV (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 29 |
11 |
▶ | use PDL::StringfiableExtension; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 30 |
11 |
▶ | use Ref::Util qw(is_plain_arrayref is_plain_hashref); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 31 |
11 |
▶ | use Scalar::Util qw(blessed looks_like_number); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 32 |
11 |
▶ | use Sereal::Encoder 4.005; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 33 |
11 |
▶ | use Text::Table::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 34 |
11 |
▶ | use Type::Params; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 35 |
11 |
▶ | use Types::Standard qw( |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 36 |
|
| Any ArrayRef CodeRef Enum CycleTuple HashRef Maybe Str |
| 37 |
11 |
| ); |
| 38 |
11 |
▶ | use Types::PDL qw(Piddle Piddle1D); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 39 |
|
| |
| 40 |
11 |
▶ | use Data::Frame::Column::Helper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 41 |
|
| |
| 42 |
11 |
▶ | use Data::Frame::Indexer qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 43 |
11 |
▶ | use Data::Frame::Types qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 44 |
11 |
▶ | use Data::Frame::Util qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 45 |
|
| |
| 46 |
11 |
▶ | use overload ( |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
|
| 47 |
12 |
▶ | '""' => sub { $_[0]->string }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 48 |
3 |
▶ | '.=' => sub { # this is similar to PDL |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 49 |
3 |
| my ( $self, $other ) = @_; |
| 50 |
3 |
| $self->assign($other); |
| 51 |
|
| }, |
| 52 |
3 |
▶ | '==' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 53 |
3 |
| my ( $self, $other ) = @_; |
| 54 |
3 |
| $self->_compare( $other, 'eq' ); |
| 55 |
|
| }, |
| 56 |
0 |
▶ | 'eq' => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
|
| 57 |
0 |
| my ( $self, $other ) = @_; |
| 58 |
0 |
| $self->_compare( $other, 'eq' ); |
| 59 |
|
| }, |
| 60 |
61 |
▶ | '!=' => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 61 |
61 |
| my ( $self, $other ) = @_; |
| 62 |
61 |
| $self->_compare( $other, 'ne' ); |
| 63 |
|
| }, |
| 64 |
4 |
▶ | '<' => sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
|
| 65 |
4 |
| my ( $self, $other, $swap ) = @_; |
| 66 |
4 |
▶ | $self->_compare( $other, ( $swap ? 'ge' : 'lt' ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| $swap ? : |
1 |
82 |
83 |
|
| 67 |
|
| }, |
| 68 |
2 |
▶ | '<=' => sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
|
| 69 |
2 |
| my ( $self, $other, $swap ) = @_; |
| 70 |
2 |
▶ | $self->_compare( $other, ( $swap ? 'gt' : 'le' ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| $swap ? : |
2 |
5 |
7 |
|
| 71 |
|
| }, |
| 72 |
2 |
▶ | '>' => sub { # use '<' overload |
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
|
| 73 |
2 |
| my ( $self, $other, $swap ) = @_; |
| 74 |
2 |
▶ | $swap ? ( $self < $other ) : ( $other < $self ); |
Branch: 1 branch
| Branch | True | False | Total |
| $swap ? : |
0 |
3 |
3 |
|
| 75 |
|
| }, |
| 76 |
1 |
▶ | '>=' => sub { # use '<=' overload |
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
|
| 77 |
1 |
| my ( $self, $other, $swap ) = @_; |
| 78 |
1 |
▶ | $swap ? ( $self <= $other ) : ( $other <= $self ); |
Branch: 1 branch
| Branch | True | False | Total |
| $swap ? : |
0 |
3 |
3 |
|
| 79 |
|
| }, |
| 80 |
11 |
| fallback => 1 |
| 81 |
11 |
| ); |
| 82 |
|
| |
| 83 |
|
| # Relative tolerance. This can be used for data frame comparison. |
| 84 |
11 |
| our $TOLERANCE_REL = undef; |
| 85 |
11 |
| our $doubleformat = '%.8g'; |
| 86 |
|
| |
| 87 |
|
| # Check if all columns have same length or have a length of 1. |
| 88 |
323 |
▶ | around BUILDARGS($orig, $class : @args) { |
|
Subroutine
__ANON__: called CC=8 SCAR=21.1
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for around BUILDARGS (expected 2, got ' . @_ . ')') |
0 |
323 |
323 |
|
| 89 |
323 |
| my %args = @args; |
| 90 |
|
| |
| 91 |
323 |
▶ | if ( my $columns = $args{columns} ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (my $columns = $args{"columns"}) |
323 |
0 |
323 |
|
| 92 |
323 |
| my $columns_is_aref = Ref::Util::is_plain_arrayref($columns); |
| 93 |
323 |
| my $columns_href; |
| 94 |
323 |
▶ | if ($columns_is_aref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($columns_is_aref) { } |
322 |
1 |
323 |
|
| 95 |
322 |
| $columns_href = {@$columns}; |
| 96 |
|
| } |
| 97 |
|
| else { |
| 98 |
1 |
| $columns_href = $columns; |
| 99 |
|
| } |
| 100 |
|
| |
| 101 |
323 |
| my @lengths = map { $_->length } values %$columns_href; |
| 102 |
323 |
| my $max_length = List::AllUtils::max(@lengths); |
| 103 |
323 |
| for my $column_name ( sort keys %$columns_href ) { |
| 104 |
1085 |
| my $data = $columns_href->{$column_name}; |
| 105 |
1085 |
▶ | if ( $data->length != $max_length ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($data->length != $max_length) |
2 |
1083 |
1085 |
|
| 106 |
2 |
▶ | if ( $data->length == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($data->length == 1) { } |
2 |
0 |
2 |
|
| 107 |
2 |
▶ | if ($columns_is_aref) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($columns_is_aref) { } |
2 |
0 |
2 |
|
| 108 |
3 |
▶ | my $idx = List::AllUtils::lastidx { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 109 |
3 |
| $_ eq $column_name |
| 110 |
|
| } |
| 111 |
2 |
| List::AllUtils::pairkeys(@$columns); |
| 112 |
2 |
| $columns->[ 2 * $idx + 1 ] = $data->repeat($max_length); |
| 113 |
|
| } |
| 114 |
|
| else { # hashref |
| 115 |
0 |
| $columns->{$column_name} = $data->repeat($max_length); |
| 116 |
|
| } |
| 117 |
|
| } |
| 118 |
|
| else { |
| 119 |
0 |
| die |
| 120 |
|
| "Column piddles must all be same length or have a length of 1"; |
| 121 |
|
| } |
| 122 |
|
| } |
| 123 |
|
| } |
| 124 |
|
| } |
| 125 |
323 |
| return $class->$orig(\%args); |
| 126 |
11 |
| } |
| 127 |
|
| |
| 128 |
70 |
▶ | sub _trait_namespace { 'Data::Frame::Role' } # override for MooX::Traits |
|
Subroutine
_trait_namespace: called CC=1 SCAR=0.0
|
| 129 |
|
| |
| 130 |
323 |
▶ | has _columns => ( is => 'ro', default => sub { Hash::Ordered->new; } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 131 |
|
| |
| 132 |
11 |
| has _row_names => ( is => 'rw', predicate => 1 ); |
| 133 |
|
| |
| 134 |
11 |
| with qw( |
| 135 |
|
| Data::Frame::Role::Rlike |
| 136 |
|
| Data::Frame::IO::CSV |
| 137 |
|
| Data::Frame::Partial::Eval |
| 138 |
|
| Data::Frame::Partial::Sugar |
| 139 |
|
| ); |
| 140 |
|
| |
| 141 |
323 |
▶ | sub BUILD { |
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
|
| 142 |
323 |
| my ($self, $args) = @_; |
| 143 |
323 |
| my $colspec = delete $args->{columns}; |
| 144 |
|
| |
| 145 |
323 |
▶ | if( defined $colspec ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (defined $colspec) |
323 |
0 |
323 |
|
| 146 |
|
| my @columns = |
| 147 |
|
| ref $colspec eq 'HASH' |
| 148 |
323 |
▶ | ? map { ($_, $colspec->{$_} ) } sort { $a cmp $b } keys %$colspec |
Branch: 1 branch
| Branch | True | False | Total |
| ref $colspec eq 'HASH' ? : |
1 |
322 |
323 |
|
| 149 |
|
| : @$colspec; |
| 150 |
323 |
| $self->add_columns(@columns); |
| 151 |
|
| } |
| 152 |
|
| |
| 153 |
323 |
| my $row_names = $args->{row_names}; |
| 154 |
323 |
▶ | if ( defined $row_names ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (defined $row_names) |
43 |
280 |
323 |
|
| 155 |
43 |
| $self->row_names($row_names); |
| 156 |
|
| } |
| 157 |
|
| |
| 158 |
323 |
| $self->_initialize_sugar(); |
| 159 |
|
| } |
| 160 |
|
| |
| 161 |
|
| |
| 162 |
2634 |
▶ | method _format_cell ($col, $ridx, |
|
Subroutine
_format_cell: called CC=12 SCAR=25.3
|
| 163 |
|
| :$na='BAD', :$isbad=$col->isbad) |
| 164 |
2634 |
▶ | { |
Branch: 5 branches
| Branch | True | False | Total |
| @_ < 3 and Function::Parameters::_croak('Too few arguments for method _format_cell (expected 3, got ' . @_ . ')') |
0 |
2634 |
2634 |
| @_ > 3 and (@_ - 3) % 2 and Function::Parameters::_croak("Odd number of paired arguments for method _format_cell") |
0 |
2634 |
2634 |
| exists ${__rest}{'na'} ? : |
1288 |
1346 |
2634 |
| exists ${__rest}{'isbad'} ? : |
1288 |
1346 |
2634 |
| keys %{__rest} and Function::Parameters::_croak('In method _format_cell: no such named parameter: ' . join(", ", sort(keys %{__rest}))) |
0 |
2634 |
2634 |
MC/DC0%0/2
@_ > 3 and (@_ - 3) % 2
@_ > 3
(@_ - 3) % 2
Truth table66%2/3
A and B
A= @_ > 3B= (@_ - 3) % 2
|
| 165 |
2634 |
| my $is_numeric = $self->_is_numeric_column($col); |
| 166 |
2634 |
▶ | if ($isbad->at($ridx)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($isbad->at($ridx)) |
48 |
2586 |
2634 |
|
| 167 |
48 |
▶ | return $is_numeric ? $na : "<$na>"; |
Branch: 1 branch
| Branch | True | False | Total |
| $is_numeric ? : |
48 |
0 |
48 |
|
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
2586 |
▶ | if ( $col->$_DOES('PDL::DateTime') ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ($col->$Data::Frame::_DOES('PDL::DateTime')) { } |
29 |
2557 |
2586 |
| elsif ($is_numeric) { } |
2407 |
150 |
2557 |
|
| 171 |
29 |
| return $col->dt_at($ridx); |
| 172 |
|
| } |
| 173 |
|
| elsif ( $is_numeric ) { |
| 174 |
2407 |
▶ | if ( $col->type >= PDL::float ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($col->type >= PDL::float()) |
2407 |
0 |
2407 |
|
| 175 |
|
| |
| 176 |
|
| # This is to fix some float precision problem with perl |
| 177 |
|
| # of nvsize=16, which can cause $df->string to get untidy |
| 178 |
|
| # float data to cause our test to fail. |
| 179 |
|
| return |
| 180 |
2407 |
| sprintf( $doubleformat, $col->slice($ridx)->squeeze->string ); |
| 181 |
|
| } |
| 182 |
|
| } |
| 183 |
150 |
| return $col->slice($ridx)->squeeze->string; |
| 184 |
11 |
| } |
| 185 |
|
| |
| 186 |
26 |
▶ | method _string() { |
|
Subroutine
_string: called CC=4 SCAR=13.9
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method _string (expected 1, got ' . @_ . ')') |
0 |
26 |
26 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method _string (expected 1, got ' . @_ . ')') |
0 |
26 |
26 |
|
| 187 |
26 |
| my @rows = ( [ '', @{ $self->column_names } ] ); |
| 188 |
26 |
| for my $r_idx ( 0 .. $self->number_of_rows - 1 ) { |
| 189 |
|
| my $r = [ |
| 190 |
|
| $self->row_names->slice($r_idx)->squeeze->string, |
| 191 |
|
| map { |
| 192 |
246 |
| my $col = $self->nth_column($_); |
| 193 |
1346 |
| $self->_format_cell( $col, $r_idx ); |
| 194 |
|
| } 0 .. $self->number_of_columns - 1 |
| 195 |
|
| ]; |
| 196 |
246 |
| push @rows, $r; |
| 197 |
|
| } |
| 198 |
|
| { |
| 199 |
|
| # clear column separators |
| 200 |
26 |
| local $Text::Table::Tiny::COLUMN_SEPARATOR = ''; |
| 201 |
26 |
| local $Text::Table::Tiny::CORNER_MARKER = ''; |
| 202 |
|
| |
| 203 |
26 |
| Text::Table::Tiny::table( rows => \@rows, header_row => 1 ) |
| 204 |
|
| } |
| 205 |
11 |
| } |
| 206 |
|
| |
| 207 |
26 |
▶ | method string( $row_limit = 10 ) { |
|
Subroutine
string: called CC=7 SCAR=20.0
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method string (expected 1, got ' . @_ . ')') |
0 |
26 |
26 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method string (expected 2, got ' . @_ . ')') |
0 |
26 |
26 |
| @_ < 1 and $row_limit = 10 |
26 |
0 |
26 |
|
| 208 |
26 |
▶ | if ( $row_limit < 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($row_limit < 0) |
0 |
26 |
26 |
|
| 209 |
0 |
| $row_limit = $self->nrow; |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
26 |
| my $more_rows = $self->nrow - $row_limit; |
| 213 |
26 |
▶ | my $df = $more_rows > 0 ? $self->head($row_limit) : $self; |
Branch: 1 branch
| Branch | True | False | Total |
| $more_rows > 0 ? : |
17 |
9 |
26 |
|
| 214 |
26 |
| my $text = $df->_string() . "\n"; |
| 215 |
26 |
▶ | if ( $more_rows > 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($more_rows > 0) |
17 |
9 |
26 |
|
| 216 |
17 |
| $text .= "# ... with $more_rows more rows\n"; |
| 217 |
|
| } |
| 218 |
|
| |
| 219 |
26 |
| return $text; |
| 220 |
11 |
| } |
| 221 |
|
| |
| 222 |
|
| |
| 223 |
6199 |
▶ | method number_of_columns() { |
|
Subroutine
number_of_columns: called CC=3 SCAR=11.3
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method number_of_columns (expected 1, got ' . @_ . ')') |
0 |
6199 |
6199 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method number_of_columns (expected 1, got ' . @_ . ')') |
0 |
6199 |
6199 |
|
| 224 |
6199 |
| return scalar($self->_columns->keys); |
| 225 |
11 |
| } |
| 226 |
|
| |
| 227 |
11 |
| *ncol = \&number_of_columns; |
| 228 |
11 |
| *length = \&number_of_columns; |
| 229 |
|
| |
| 230 |
|
| |
| 231 |
1344 |
▶ | sub number_of_rows { |
|
Subroutine
number_of_rows: called CC=2 SCAR=7.6
Pod
documented
|
| 232 |
1344 |
| my ($self) = @_; |
| 233 |
1344 |
▶ | if( $self->number_of_columns ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($self->number_of_columns) |
1344 |
0 |
1344 |
|
| 234 |
1344 |
| return $self->nth_column(0)->length; |
| 235 |
|
| } |
| 236 |
0 |
| 0; |
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
11 |
| *nrow = \&Data::Frame::number_of_rows; |
| 240 |
|
| |
| 241 |
|
| |
| 242 |
4 |
▶ | method dims () { |
|
Subroutine
dims: called CC=3 SCAR=11.3
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method dims (expected 1, got ' . @_ . ')') |
0 |
4 |
4 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method dims (expected 1, got ' . @_ . ')') |
0 |
4 |
4 |
|
| 243 |
4 |
| return ( $self->nrow, $self->ncol ); |
| 244 |
11 |
| } |
| 245 |
|
| |
| 246 |
2 |
▶ | method shape () { |
|
Subroutine
shape: called CC=3 SCAR=11.3
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method shape (expected 1, got ' . @_ . ')') |
0 |
2 |
2 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method shape (expected 1, got ' . @_ . ')') |
0 |
2 |
2 |
|
| 247 |
2 |
| return pdl( $self->dims ); |
| 248 |
11 |
| } |
| 249 |
|
| |
| 250 |
|
| |
| 251 |
84 |
▶ | method _indexer_to_indices ($indexer, $row_or_column) { |
|
Subroutine
_indexer_to_indices: called CC=4 SCAR=14.0
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 3 and Function::Parameters::_croak('Too few arguments for method _indexer_to_indices (expected 3, got ' . @_ . ')') |
0 |
84 |
84 |
| @_ > 3 and Function::Parameters::_croak('Too many arguments for method _indexer_to_indices (expected 3, got ' . @_ . ')') |
0 |
84 |
84 |
|
| 252 |
84 |
▶ | if ( $indexer->$_isa('Data::Frame::Indexer::Integer') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($indexer->$Data::Frame::_isa('Data::Frame::Indexer::Integer')) { } |
77 |
7 |
84 |
|
| 253 |
77 |
| return $indexer->indexer; |
| 254 |
|
| } |
| 255 |
|
| else { |
| 256 |
7 |
| my $names_getter = "${row_or_column}_names"; |
| 257 |
7 |
| my @names = $self->$names_getter()->flatten; |
| 258 |
|
| return $indexer->indexer->map( |
| 259 |
12 |
▶ | sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
|
| 260 |
12 |
| my ($name) = @_; |
| 261 |
12 |
▶ | my $ridx = List::AllUtils::firstidx { $name eq $_ } @names; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 262 |
12 |
▶ | if ( $ridx < 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($ridx < 0) |
0 |
12 |
12 |
|
| 263 |
0 |
| die "Cannot find $row_or_column name '$name'."; |
| 264 |
|
| } |
| 265 |
12 |
| return $ridx; |
| 266 |
|
| } |
| 267 |
7 |
| ); |
| 268 |
|
| } |
| 269 |
11 |
| } |
| 270 |
|
| |
| 271 |
11 |
▶ | method _cindexer_to_indices (Indexer $indexer) { |
|
Subroutine
_cindexer_to_indices: called CC=6 SCAR=18.6
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method _cindexer_to_indices (expected 2, got ' . @_ . ')') |
0 |
11 |
11 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method _cindexer_to_indices (expected 2, got ' . @_ . ')') |
0 |
11 |
11 |
| do {
package Type::Tiny;
builtin::blessed($indexer) and do {
my $method = $indexer->can("DOES") || $indexer->can("isa");
$indexer->$method("Data::Frame::Indexer::Role")
}
} or Function::Parameters::_croak('In method _cindexer_to_indices: parameter 1 ($indexer): ' . ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('Data::Frame::Indexer::Role') } };},"display_name" => "to_Indexer","name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 22,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "Indexer","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "Indexer","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"Data::Frame::Indexer::Role\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "Data::Frame::Indexer::Role","uniq" => 79}, 'Type::Tiny::Role' ),"uniq" => 80}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"}; \$v}->get_message($indexer)) |
11 |
0 |
11 |
|
| 272 |
73 |
| return $self->_indexer_to_indices( $indexer, 'column' ); |
| 273 |
11 |
| } |
| 274 |
|
| |
| 275 |
73 |
▶ | method _rindexer_to_indices (Indexer $indexer) { |
|
Subroutine
_rindexer_to_indices: called CC=7 SCAR=20.3
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method _rindexer_to_indices (expected 2, got ' . @_ . ')') |
0 |
73 |
73 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method _rindexer_to_indices (expected 2, got ' . @_ . ')') |
0 |
73 |
73 |
| do {
package Type::Tiny;
builtin::blessed($indexer) and do {
my $method = $indexer->can("DOES") || $indexer->can("isa");
$indexer->$method("Data::Frame::Indexer::Role")
}
} or Function::Parameters::_croak('In method _rindexer_to_indices: parameter 1 ($indexer): ' . ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('Data::Frame::Indexer::Role') } };},"display_name" => "to_Indexer","name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 22,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "Indexer","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "Indexer","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"Data::Frame::Indexer::Role\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "Data::Frame::Indexer::Role","uniq" => 79}, 'Type::Tiny::Role' ),"uniq" => 80}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"}; \$v}->get_message($indexer)) |
73 |
0 |
73 |
|
| 276 |
290 |
▶ | if ( $indexer->$_DOES('Data::Frame::Indexer::Label') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($indexer->$Data::Frame::_DOES("Data::Frame::Indexer::Label")) |
0 |
290 |
290 |
|
| 277 |
290 |
| die "select_rows() does not yet support label indexer"; |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
290 |
| return $self->_indexer_to_indices( $indexer, 'row' ); |
| 281 |
11 |
| } |
| 282 |
|
| |
| 283 |
290 |
▶ | method at (@rest) { |
|
Subroutine
at: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method at (expected 1, got ' . @_ . ')') |
4 |
286 |
290 |
|
| 284 |
290 |
| my ( $rindexer, $cindexer ) = $self->_check_slice_args(@_); |
| 285 |
|
| |
| 286 |
3 |
| my $cindex = $cindexer->indexer->[0]; |
| 287 |
287 |
| my $col; |
| 288 |
3292 |
▶ | if ( $cindexer->$_DOES('Data::Frame::Indexer::Integer') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($cindexer->$Data::Frame::_DOES('Data::Frame::Indexer::Integer')) { } |
3 |
287 |
290 |
|
| 289 |
3292 |
| $col = $self->nth_column($cindex); |
| 290 |
|
| } |
| 291 |
|
| else { # Label; |
| 292 |
3292 |
| $col = $self->column($cindex); |
| 293 |
|
| } |
| 294 |
|
| |
| 295 |
3292 |
▶ | if ( defined $rindexer ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (defined $rindexer) { } |
0 |
3292 |
3292 |
|
| 296 |
3292 |
| return $col->at( $rindexer->indexer->[0] ); |
| 297 |
|
| } |
| 298 |
|
| else { |
| 299 |
3292 |
| return $col; |
| 300 |
|
| } |
| 301 |
11 |
| } |
| 302 |
|
| |
| 303 |
|
| |
| 304 |
5 |
▶ | method exists ($col_name) { |
|
Subroutine
exists: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method exists (expected 2, got ' . @_ . ')') |
0 |
3292 |
3292 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method exists (expected 2, got ' . @_ . ')') |
0 |
5 |
5 |
|
| 305 |
5 |
| $self->_columns->exists($col_name); |
| 306 |
11 |
| } |
| 307 |
|
| |
| 308 |
2 |
▶ | method delete ($col_name) { |
|
Subroutine
delete: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method delete (expected 2, got ' . @_ . ')') |
0 |
5 |
5 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method delete (expected 2, got ' . @_ . ')') |
0 |
2 |
2 |
|
| 309 |
2 |
| $self->_columns->delete($col_name); |
| 310 |
11 |
| } |
| 311 |
|
| |
| 312 |
2 |
▶ | method rename ((HashRef | CodeRef) $href_or_coderef) { |
|
Subroutine
rename: called CC=5 SCAR=16.4
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method rename (expected 2, got ' . @_ . ')') |
0 |
2 |
2 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method rename (expected 2, got ' . @_ . ')') |
2 |
0 |
2 |
| Type::Tiny::XS::AUTO::TC4($href_or_coderef) or Function::Parameters::_croak('In method rename: parameter 1 ($href_or_coderef): ' . ${my $v = bless( {"compiled_type_constraint" => sub ;,"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame.pm","line" => 312,"package" => "Data::Frame"},"deprecated" => !!0,"name" => "__ANON__","type_constraints" => [bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; Ref::Util::XS::is_plain_hashref($_[0]) or _failed_check(22, 'HashRef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_HashRef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"coercion_generator" => bless( ["HashRef","coercion_generator"], 'Types::Standard::LazyLoad' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_ eq 'HASH';},"constraint_generator" => bless( ["HashRef","constraint_generator"], 'Types::Standard::LazyLoad' ),"deep_explanation" => bless( ["HashRef","deep_explanation"], 'Types::Standard::LazyLoad' ),"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 544,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "HashRef","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => bless( ["HashRef","inline_generator"], 'Types::Standard::LazyLoad' ),"inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_plain_hashref($_[1])" : "ref($_[1]) eq 'HASH'";},"library" => "Types::Standard","my_methods" => {"hashref_allows_key" => bless( ["HashRef","hashref_allows_key"], 'Types::Standard::LazyLoad' ),"hashref_allows_value" => bless( ["HashRef","hashref_allows_value"], 'Types::Standard::LazyLoad' )},"name" => "HashRef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; not ref $_[0] and _failed_check(16, 'Ref', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Ref","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_;},"constraint_generator" => sub { package Types::Standard; no warnings; use strict; return $meta->get_type('Ref') unless @_; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'Ref', \@_, 1); my $reftype = shift(); $reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or _croak "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype"; $reftype = "$reftype"; return sub { ref $_[0] and builtin::reftype($_[0]) eq $reftype; } ;},"deep_explanation" => sub { package Types::Standard; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; return if $type->check($value); my $reftype = builtin::reftype($value); return [sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)), sprintf('reftype(%s) is %s', $varname, defined $reftype ? B::perlstring($reftype) : 'undef')];},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 438,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Ref","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard; no warnings; use strict; my $reftype = shift(); return sub { my $v = $_[1]; &$maybe_load_modules('Scalar::Util', "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"); } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; "!!ref($_[1])";},"library" => "Types::Standard","name" => "Ref","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 16}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return {};},"type_default_generator" => sub { package Types::Standard; no warnings; use strict; return $Type::Tiny::parameterize_type->type_default if @_ < 2; return undef;},"uniq" => 22}, 'Type::Tiny' ),bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; Ref::Util::XS::is_plain_coderef($_[0]) or _failed_check(17, 'CodeRef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_CodeRef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_ eq 'CODE';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 452,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "CodeRef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_plain_coderef($_[1])" : "ref($_[1]) eq 'CODE'";},"library" => "Types::Standard","name" => "CodeRef","parent" => {},"type_default" => sub { package Types::Standard; no warnings; use strict; return sub { } ;},"uniq" => 17}, 'Type::Tiny' )],"uniq" => 93,"xs_sub" => "Type::Tiny::XS::AUTO::TC4"}, 'Type::Tiny::Union' );$v->{"type_constraints"}[0]{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0];$v->{"type_constraints"}[0]{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"};$v->{"type_constraints"}[0]{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"type_constraints"}[0]{"parent"}{"parent"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"type_constraints"}[0]{"parent"}{"parent"}{"parent"} = $v->{"type_constraints"}[0]{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"type_constraints"}[1]{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1];$v->{"type_constraints"}[1]{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"} = $v->{"type_constraints"}[0]{"parent"}; \$v}->get_message($href_or_coderef)) |
1 |
1 |
2 |
|
| 313 |
|
| my $f = |
| 314 |
|
| Ref::Util::is_plain_coderef($href_or_coderef) |
| 315 |
|
| ? $href_or_coderef |
| 316 |
10 |
▶ | : sub { $href_or_coderef->{ $_[0] } }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| Branch | True | False | Total |
| Ref::Util::XS::is_plain_coderef($href_or_coderef) ? : |
0 |
10 |
10 |
|
| 317 |
10 |
▶ | my $new_names = $self->names->map( sub { $f->($_) // $_ } ); |
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
|
| 318 |
10 |
| $self->names($new_names); |
| 319 |
10 |
| return $self; |
| 320 |
11 |
| } |
| 321 |
|
| |
| 322 |
|
| |
| 323 |
0 |
▶ | method set ($indexer, $data) { |
|
Subroutine
set: called CC=7 SCAR=25.7
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 3 and Function::Parameters::_croak('Too few arguments for method set (expected 3, got ' . @_ . ')') |
0 |
10 |
10 |
| @_ > 3 and Function::Parameters::_croak('Too many arguments for method set (expected 3, got ' . @_ . ')') |
0 |
10 |
10 |
|
| 324 |
|
| state $check = |
| 325 |
|
| Type::Params::compile( Indexer->plus_coercions(IndexerFromLabels), |
| 326 |
10 |
▶ | ColumnLike->plus_coercions( ArrayRef, sub { PDL::SV->new($_) } ) ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 327 |
0 |
| ($indexer) = $check->( $indexer, $data ); |
| 328 |
|
| |
| 329 |
0 |
▶ | if ( $data->length == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($data->length == 1) |
10 |
0 |
10 |
|
| 330 |
0 |
| $data = $data->repeat( $self->nrow ); |
| 331 |
|
| } |
| 332 |
|
| |
| 333 |
|
| # Only Label indexer can be used to add new columns. |
| 334 |
0 |
| my $name; |
| 335 |
10 |
▶ | if ( $indexer->$_DOES('Data::Frame::Indexer::Label') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($indexer->$Data::Frame::_DOES('Data::Frame::Indexer::Label')) { } |
0 |
0 |
0 |
|
| 336 |
4 |
| $name = $indexer->indexer->[0]; |
| 337 |
|
| } |
| 338 |
|
| else { |
| 339 |
4 |
| my $cidx = $indexer->indexer->[0]; |
| 340 |
6 |
▶ | if ( $cidx >= $self->ncol ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($cidx >= $self->ncol) |
4 |
6 |
10 |
|
| 341 |
10 |
| die "Invalid column index: $cidx"; |
| 342 |
|
| } |
| 343 |
1 |
| $name = $self->column_names->at($cidx); |
| 344 |
|
| } |
| 345 |
|
| |
| 346 |
0 |
▶ | if ( $self->exists($name) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($self->exists($name)) { } |
0 |
0 |
0 |
|
| 347 |
0 |
| $self->_column_validate( $name => $data ); |
| 348 |
0 |
| $self->_columns->set( $name => $data ); |
| 349 |
|
| } |
| 350 |
|
| else { |
| 351 |
0 |
| $self->add_column( $name, $data ); |
| 352 |
|
| } |
| 353 |
0 |
| return; |
| 354 |
11 |
| } |
| 355 |
|
| |
| 356 |
|
| |
| 357 |
710 |
▶ | method isempty () { $self->nrow == 0; } |
|
Subroutine
isempty: not called CC=3 SCAR=11.8
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method isempty (expected 1, got ' . @_ . ')') |
0 |
0 |
0 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method isempty (expected 1, got ' . @_ . ')') |
0 |
710 |
710 |
|
| 358 |
|
| |
| 359 |
|
| |
| 360 |
5 |
▶ | method column_names(@rest) { |
|
Subroutine
column_names: called CC=7 SCAR=19.5
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method column_names (expected 1, got ' . @_ . ')') |
2 |
708 |
710 |
|
| 361 |
3 |
▶ | my @colnames = |
Branch: 1 branch
| Branch | True | False | Total |
| @rest == 1 && (is_plain_arrayref($rest[0]) || $rest[0]->$Data::Frame::_can('flatten')) ? : |
5 |
705 |
710 |
Condition83%5/6
@rest == 1 and is_plain_arrayref($rest[0]) || $rest[0]->$Data::Frame::_can("flatten")
is_plain_arrayref($rest[0]) or $rest[0]->$Data::Frame::_can("flatten")
MC/DC33%1/3
@rest == 1 and is_plain_arrayref($rest[0]) || $rest[0]->$Data::Frame::_can("flatten")
@rest == 1
is_plain_arrayref($rest[0])
$rest[0]->$Data::Frame::_can("flatten")
Truth table50%2/4
A and B or C
A= @rest == 1B= is_plain_arrayref($rest[0])C= $rest[0]->$Data::Frame::_can("flatten")
| A | B | C | result |
| 0 | X | X | 0 |
| 1 | 0 | 0 | 0 |
| 1 | 1 | X | 1 |
| 1 | 0 | 1 | 1 |
|
| 362 |
|
| ( |
| 363 |
|
| @rest == 1 |
| 364 |
|
| and ( Ref::Util::is_plain_arrayref( $rest[0] ) |
| 365 |
|
| or $rest[0]->$_can('flatten') ) |
| 366 |
|
| ) |
| 367 |
|
| ? $rest[0]->flatten |
| 368 |
|
| : @rest; |
| 369 |
|
| |
| 370 |
708 |
▶ | if( @colnames ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (@colnames) |
2 |
3 |
5 |
|
| 371 |
547 |
▶ | unless (@colnames == $self->length) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (@colnames == $self->length) |
45 |
502 |
547 |
|
| 372 |
547 |
| failure::columns::length->throw({ |
| 373 |
|
| msg => "incorrect number of column names", |
| 374 |
|
| trace => failure->croak_trace, |
| 375 |
|
| }); |
| 376 |
|
| } |
| 377 |
|
| # rename column names |
| 378 |
45 |
| my @values = $self->_columns->values; |
| 379 |
45 |
| $self->_columns->clear; |
| 380 |
|
| |
| 381 |
|
| # List::AllUtils and List::Util 's zip func are different. |
| 382 |
|
| # See also https://github.com/houseabsolute/List-AllUtils/issues/12 |
| 383 |
43 |
| $self->_columns->push( zip( @colnames, @values ) ); |
| 384 |
|
| } |
| 385 |
19 |
| return [ $self->_columns->keys ]; |
| 386 |
|
| } |
| 387 |
|
| |
| 388 |
|
| *col_names = \&column_names; |
| 389 |
|
| *names = \&column_names; |
| 390 |
|
| |
| 391 |
547 |
▶ | sub row_names { |
|
Subroutine
row_names: called CC=9 SCAR=22.0
Pod
documented
|
| 392 |
19 |
| my ($self, @rest) = @_; |
| 393 |
24 |
▶ | if( @rest ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (@rest) |
43 |
2 |
45 |
|
| 394 |
|
| # setting row names |
| 395 |
45 |
| my $new_rows; |
| 396 |
45 |
▶ | if ( ref $rest[0] ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ref $rest[0]) |
19 |
24 |
43 |
|
| 397 |
44 |
▶ | if ( Ref::Util::is_plain_arrayref($rest[0]) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (is_plain_arrayref($rest[0])) { } |
24 |
0 |
24 |
| elsif ($rest[0]->isa('PDL')) { } |
1 |
44 |
45 |
|
| 398 |
43 |
| $new_rows = [ @{$rest[0]} ]; |
| 399 |
|
| } |
| 400 |
|
| elsif ( $rest[0]->isa('PDL') ) { |
| 401 |
|
| |
| 402 |
|
| # TODO just run uniq? |
| 403 |
163 |
| $new_rows = $rest[0]->unpdl; |
| 404 |
|
| } |
| 405 |
|
| } |
| 406 |
339 |
▶ | $new_rows //= [ @rest ]; |
MC/DC100%1/1
$new_rows //= [@rest]
$new_rows
|
| 407 |
|
| |
| 408 |
73 |
▶ | failure::rows::length->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| if $self->number_of_rows != $new_rows->length |
1 |
43 |
44 |
|
| 409 |
|
| msg => "invalid row names length", |
| 410 |
|
| trace => failure->croak_trace, |
| 411 |
|
| }) if $self->number_of_rows != $new_rows->length; |
| 412 |
73 |
▶ | failure::rows::unique->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| if $new_rows->length != $new_rows->uniq->length |
163 |
339 |
502 |
|
| 413 |
|
| msg => "non-unique row names", |
| 414 |
|
| trace => failure->croak_trace, |
| 415 |
|
| }) if $new_rows->length != $new_rows->uniq->length; |
| 416 |
|
| |
| 417 |
15 |
| return $self->_row_names( PDL::SV->new($new_rows) ); |
| 418 |
|
| } |
| 419 |
2173 |
▶ | if( not $self->_has_row_names ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless ($self->_has_row_names) |
15 |
58 |
73 |
|
| 420 |
|
| # if it has never been set before |
| 421 |
2173 |
| return sequence($self->number_of_rows); |
| 422 |
|
| } |
| 423 |
|
| # else, if row_names has been set |
| 424 |
2173 |
| return $self->_row_names; |
| 425 |
|
| } |
| 426 |
|
| |
| 427 |
73 |
▶ | sub _make_actual_row_names { |
|
Subroutine
_make_actual_row_names: called CC=2 SCAR=7.1
|
| 428 |
2173 |
| my ($self) = @_; |
| 429 |
2173 |
▶ | if( not $self->_has_row_names ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (not $self->_has_row_names) |
0 |
2173 |
2173 |
|
| 430 |
2173 |
| $self->_row_names( $self->row_names ); |
| 431 |
|
| } |
| 432 |
|
| } |
| 433 |
|
| |
| 434 |
|
| |
| 435 |
2171 |
▶ | method column($colname) { |
|
Subroutine
column: called CC=4 SCAR=14.0
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method column (expected 2, got ' . @_ . ')') |
0 |
2173 |
2173 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method column (expected 2, got ' . @_ . ')') |
2 |
2171 |
2173 |
|
| 436 |
3358 |
▶ | failure::column::exists->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| unless $self->exists($colname) |
0 |
3358 |
3358 |
|
| 437 |
|
| msg => "column $colname does not exist", |
| 438 |
|
| trace => failure->croak_trace, |
| 439 |
|
| }) unless $self->exists( $colname ); |
| 440 |
3358 |
| return $self->_columns->get($colname); |
| 441 |
|
| } |
| 442 |
|
| |
| 443 |
|
| # supports negative indices |
| 444 |
3358 |
▶ | method nth_column($index) { |
|
Subroutine
nth_column: called CC=5 SCAR=16.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method nth_column (expected 2, got ' . @_ . ')') |
0 |
3358 |
3358 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method nth_column (expected 2, got ' . @_ . ')') |
0 |
3358 |
3358 |
|
| 445 |
1096 |
▶ | failure::index->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| unless defined $index |
2 |
3356 |
3358 |
|
| 446 |
|
| msg => "requires index", |
| 447 |
|
| trace => failure->croak_trace |
| 448 |
|
| }) unless defined $index; |
| 449 |
773 |
▶ | failure::index::exists->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| if $index >= $self->number_of_columns |
1 |
1096 |
1097 |
|
| 450 |
|
| msg => "column index out of bounds", |
| 451 |
|
| trace => failure->croak_trace, |
| 452 |
|
| }) if $index >= $self->number_of_columns; |
| 453 |
|
| # fine if $index < 0 because negative indices are supported |
| 454 |
1 |
| return ($self->_columns->values)[$index]; |
| 455 |
|
| } |
| 456 |
|
| |
| 457 |
|
| |
| 458 |
1097 |
▶ | sub _column_validate { |
|
Subroutine
_column_validate: called CC=4 SCAR=13.9
|
| 459 |
1 |
| my ($self, $name, $data) = @_; |
| 460 |
1 |
▶ | if( $name =~ /^\d+$/ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($name =~ /^\d+$/u) |
773 |
323 |
1096 |
|
| 461 |
1095 |
| failure::column::name::string->throw({ |
| 462 |
|
| msg => "invalid column name: $name can not be an integer", |
| 463 |
|
| trace => failure->croak_trace, |
| 464 |
|
| }); |
| 465 |
|
| } |
| 466 |
324 |
▶ | if( $self->number_of_columns ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($self->number_of_columns) |
1 |
772 |
773 |
|
| 467 |
324 |
▶ | if( $data->length != $self->number_of_rows ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($data->length != $self->number_of_rows) |
0 |
324 |
324 |
|
| 468 |
324 |
| failure::rows::length->throw({ |
| 469 |
324 |
| msg => "number of rows in column is @{[ $data->length ]}; expected @{[ $self->number_of_rows ]}", |
| 470 |
|
| trace => failure->croak_trace, |
| 471 |
|
| }); |
| 472 |
|
| } |
| 473 |
|
| } |
| 474 |
323 |
| 1; |
| 475 |
|
| } |
| 476 |
|
| |
| 477 |
|
| |
| 478 |
1085 |
▶ | method add_columns(@columns) { |
|
Subroutine
add_columns: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method add_columns (expected 1, got ' . @_ . ')') |
1 |
323 |
324 |
|
| 479 |
1093 |
▶ | failure::columns::unbalanced->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| unless @columns % 2 == 0 |
2 |
1093 |
1095 |
|
| 480 |
|
| msg => "uneven number of elements for column specification", |
| 481 |
|
| trace => failure->croak_trace, |
| 482 |
|
| }) unless @columns % 2 == 0; |
| 483 |
1093 |
| for ( List::AllUtils::pairs(@columns) ) { |
| 484 |
1091 |
| my ( $name, $data ) = @$_; |
| 485 |
6 |
| $self->add_column( $name => $data ); |
| 486 |
|
| } |
| 487 |
|
| } |
| 488 |
|
| |
| 489 |
|
| |
| 490 |
1095 |
▶ | sub add_column { |
|
Subroutine
add_column: called CC=3 SCAR=11.0
Pod
documented
|
| 491 |
6 |
| my ($self, $name, $data) = @_; |
| 492 |
6 |
▶ | failure::column::exists->throw({ |
Branch: 1 branch
| Branch | True | False | Total |
| if $self->exists($name) |
14 |
1079 |
1093 |
|
| 493 |
|
| msg => "column $name already exists", |
| 494 |
|
| trace => failure->croak_trace, |
| 495 |
|
| }) if $self->exists( $name ); |
| 496 |
|
| |
| 497 |
|
| # TODO apply column role to data |
| 498 |
6 |
▶ | $data = PDL::SV->new( $data ) if ref $data eq 'ARRAY'; |
Branch: 1 branch
| Branch | True | False | Total |
| if ref $data eq "ARRAY" |
0 |
6 |
6 |
|
| 499 |
|
| |
| 500 |
6 |
| $self->_column_validate( $name => $data); |
| 501 |
57 |
| $self->_columns->push( $name => $data ); |
| 502 |
|
| } |
| 503 |
|
| |
| 504 |
|
| |
| 505 |
2 |
▶ | method copy () { |
|
Subroutine
copy: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method copy (expected 1, got ' . @_ . ')') |
0 |
6 |
6 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method copy (expected 1, got ' . @_ . ')') |
0 |
2 |
2 |
|
| 506 |
|
| return ref($self)->new( |
| 507 |
2 |
▶ | columns => $self->names->map( sub { $_ => $self->column($_)->copy } ), |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 508 |
|
| row_names => $self->row_names->copy |
| 509 |
|
| ); |
| 510 |
|
| } |
| 511 |
|
| *clone = \© |
| 512 |
|
| |
| 513 |
|
| |
| 514 |
0 |
▶ | method summary ($percentiles=[0.25, 0.75]) { |
|
Subroutine
summary: called CC=7 SCAR=19.7
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method summary (expected 1, got ' . @_ . ')') |
0 |
2 |
2 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method summary (expected 2, got ' . @_ . ')') |
1 |
1 |
2 |
| @_ < 1 and $percentiles = ["0.25", "0.75"] |
0 |
2 |
2 |
|
| 515 |
2 |
▶ | if ( List::AllUtils::any { $_ < 0 or $_ > 1 } @$percentiles ) { |
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Branch: 2 branches
| Branch | True | False | Total |
| if (&List::AllUtils::any(sub {
$_ < 0 or $_ > 1;
}
, @$percentiles)) |
8 |
2 |
10 |
| $_ < 0 or $_ > 1 |
0 |
12 |
12 |
|
| 516 |
10 |
| die "percentiles should all be in the interval [0, 1]."; |
| 517 |
|
| } |
| 518 |
|
| |
| 519 |
8 |
▶ | state $std = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 520 |
12 |
| my ($p) = @_; |
| 521 |
12 |
| $p = $p->where( $p->isgood ); |
| 522 |
12 |
| return sqrt( ( ( ( $p - $p->average )**2 )->sum ) / $p->length ); |
| 523 |
10 |
| }; |
| 524 |
|
| |
| 525 |
10 |
| my $class = ref($self); |
| 526 |
8 |
| my @pct = sort { $a <=> $b } |
| 527 |
|
| List::AllUtils::uniq( ( ( $percentiles->flatten ), 0.5 ) ); |
| 528 |
|
| my %summary = map { |
| 529 |
8 |
| my $col = $self->column($_); |
| 530 |
|
| |
| 531 |
20 |
| my $count = $col->ngood; |
| 532 |
8 |
▶ | if ( $self->is_numeric_column($_) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($self->is_numeric_column($_)) { } |
0 |
8 |
8 |
|
| 533 |
0 |
| my $average = $col->average; |
| 534 |
8 |
| my $min = $col->min; |
| 535 |
2 |
| my $max = $col->max; |
| 536 |
2 |
| my @pct_data = map { $col->pct($_) } @pct; |
| 537 |
5 |
▶ | if ( $col->$_DOES('PDL::DateTime') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($col->$Data::Frame::_DOES('PDL::DateTime')) { } |
0 |
3 |
3 |
|
| 538 |
5 |
| $_ => PDL::DateTime->new( |
| 539 |
|
| [ 0, $average, 0, $min, @pct_data, $max ] ) |
| 540 |
|
| ->setbadif( pdl( [ 1, 0, 1, 0, ( (0) x @pct ), 0 ] ) ); |
| 541 |
|
| } |
| 542 |
|
| else { |
| 543 |
3 |
| $_ => pdl( |
| 544 |
|
| [ |
| 545 |
|
| $count, $average, $std->($col), |
| 546 |
|
| $min, @pct_data, $max |
| 547 |
|
| ] |
| 548 |
|
| ); |
| 549 |
|
| } |
| 550 |
|
| } |
| 551 |
|
| else { |
| 552 |
8 |
| $_ => |
| 553 |
|
| pdl( [ $count, ( ("nan") x ( @pct + 4 ) ) ] )->setnantobad(); |
| 554 |
|
| } |
| 555 |
|
| } $self->names->flatten; |
| 556 |
|
| return $class->new( |
| 557 |
8 |
| columns => [ map { $_ => $summary{$_} } $self->names->flatten ], |
| 558 |
|
| row_names => [ |
| 559 |
|
| qw(count mean std min), |
| 560 |
|
| ( |
| 561 |
|
| map { |
| 562 |
8 |
| my $nof_digits = int( 4 + log($_) / log(10) ); |
| 563 |
12 |
| sprintf( "%.${nof_digits}g%%", $_ * 100 ); |
| 564 |
|
| } @pct |
| 565 |
|
| ), |
| 566 |
|
| 'max' |
| 567 |
|
| ], |
| 568 |
|
| ); |
| 569 |
|
| } |
| 570 |
|
| |
| 571 |
|
| |
| 572 |
11 |
▶ | method select_columns (@rest) { |
|
Subroutine
select_columns: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method select_columns (expected 1, got ' . @_ . ')') |
1 |
11 |
12 |
|
| 573 |
77 |
| my $indexer = indexer_s(@rest); |
| 574 |
77 |
▶ | return $self if ( not defined $indexer or $indexer->indexer->length == 0 ); |
Branch: 1 branch
| Branch | True | False | Total |
| if not defined $indexer or $indexer->indexer->length == 0 |
0 |
77 |
77 |
Condition66%2/3
not defined $indexer or $indexer->indexer->length == 0
MC/DC50%1/2
not defined $indexer or $indexer->indexer->length == 0
not defined $indexer
$indexer->indexer->length == 0
Truth table66%2/3
not(A) or B
A= not defined $indexerB= $indexer->indexer->length == 0
|
| 575 |
|
| |
| 576 |
77 |
| my $indices = $self->_cindexer_to_indices($indexer); |
| 577 |
77 |
| my $column_names = $self->column_names; |
| 578 |
|
| return ref($self)->new( |
| 579 |
|
| columns => $indices->map( |
| 580 |
77 |
▶ | sub { $column_names->at($_) => $self->_nth_column($_) } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 581 |
77 |
| ), |
| 582 |
|
| row_names => $self->row_names |
| 583 |
|
| ); |
| 584 |
|
| } |
| 585 |
|
| |
| 586 |
|
| # R |
| 587 |
|
| # > iris[c(1,2,3,3,3,3),] |
| 588 |
|
| # PDL |
| 589 |
|
| # $ sequence(10,4)->dice(X,[0,1,1,0]) |
| 590 |
|
| |
| 591 |
73 |
▶ | method select_rows(@rest) { |
|
Subroutine
select_rows: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method select_rows (expected 1, got ' . @_ . ')') |
4 |
73 |
77 |
|
| 592 |
253 |
| my $indexer = indexer_i(@rest); |
| 593 |
73 |
▶ | return $self unless defined $indexer; |
Branch: 1 branch
| Branch | True | False | Total |
| unless defined $indexer |
0 |
300 |
300 |
|
| 594 |
|
| |
| 595 |
73 |
| my $indices = $self->_rindexer_to_indices($indexer); |
| 596 |
|
| |
| 597 |
73 |
| my $which = PDL::Core::topdl($indices); # ensure it is a PDL |
| 598 |
|
| |
| 599 |
0 |
| my $colnames = $self->column_names; |
| 600 |
|
| my $colspec = [ map { |
| 601 |
0 |
| ( $colnames->[$_] => $self->nth_column($_)->dice($which) ) |
| 602 |
|
| } 0..$self->number_of_columns-1 ]; |
| 603 |
|
| |
| 604 |
21 |
| $self->_make_actual_row_names; |
| 605 |
300 |
| my $select_df = $self->new( |
| 606 |
|
| columns => $colspec, |
| 607 |
|
| _row_names => $self->row_names->dice( $which ) ); |
| 608 |
300 |
| $select_df; |
| 609 |
|
| } |
| 610 |
|
| |
| 611 |
|
| |
| 612 |
|
| # below lvalue methods are for slice() |
| 613 |
300 |
▶ | sub _column : lvalue { my $col = shift->column(@_); return $col; } |
|
Subroutine
_column: not called CC=1 SCAR=0.0
|
| 614 |
300 |
▶ | sub _nth_column : lvalue { my $col = shift->nth_column(@_); return $col; } |
|
Subroutine
_nth_column: called CC=1 SCAR=0.0
|
| 615 |
|
| |
| 616 |
300 |
▶ | classmethod _check_slice_args (@rest) { |
|
Subroutine
_check_slice_args: called CC=6 SCAR=17.9
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for classmethod _check_slice_args (expected 1, got ' . @_ . ')') |
292 |
308 |
600 |
|
| 617 |
302 |
| state $check_labels = |
| 618 |
|
| Type::Params::compile( Indexer->plus_coercions(IndexerFromLabels) ); |
| 619 |
302 |
| state $check_indices = |
| 620 |
|
| Type::Params::compile( Indexer->plus_coercions(IndexerFromIndices) ); |
| 621 |
|
| |
| 622 |
|
| my ( $row_indexer, $column_indexer ) = |
| 623 |
|
| map { |
| 624 |
300 |
▶ | if ( !defined($_) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (not defined $_) { } |
6 |
302 |
308 |
| elsif (&Indexer()->check($_)) { } |
290 |
12 |
302 |
|
| 625 |
10 |
| undef; |
| 626 |
|
| } |
| 627 |
|
| elsif ( Indexer->check($_) ) { |
| 628 |
10 |
| $_; |
| 629 |
|
| } |
| 630 |
|
| else { |
| 631 |
10 |
| my $p = guess_and_convert_to_pdl($_); |
| 632 |
10 |
▶ | ($p->$_DOES('PDL::SV') ? $check_labels : $check_indices)->($p); |
Branch: 2 branches
| Branch | True | False | Total |
| $p->$Data::Frame::_DOES('PDL::SV') ? : |
9 |
291 |
300 |
| @rest > 1 ? : |
0 |
10 |
10 |
|
| 633 |
|
| } |
| 634 |
|
| } ( @rest > 1 ? @rest : ( undef, $rest[0] ) ); |
| 635 |
10 |
| return ( $row_indexer, $column_indexer ); |
| 636 |
|
| } |
| 637 |
|
| |
| 638 |
0 |
▶ | method slice(@rest) : lvalue { |
|
Subroutine
slice: called CC=2 SCAR=14.0
Pod
documented
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method slice (expected 1, got ' . @_ . ')') |
0 |
0 |
0 |
|
| 639 |
0 |
| my ( $rindexer, $cindexer ) = $self->_check_slice_args(@rest); |
| 640 |
0 |
| my $new_df = $self->select_rows($rindexer); |
| 641 |
0 |
| $new_df = $new_df->select_columns($cindexer); |
| 642 |
0 |
| return $new_df; |
| 643 |
|
| } |
| 644 |
|
| |
| 645 |
|
| |
| 646 |
0 |
▶ | method sample ($n) { |
|
Subroutine
sample: not called CC=4 SCAR=19.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method sample (expected 2, got ' . @_ . ')') |
0 |
0 |
0 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method sample (expected 2, got ' . @_ . ')') |
0 |
0 |
0 |
|
| 647 |
61 |
▶ | if ($n > $self->nrow) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($n > $self->nrow) |
0 |
61 |
61 |
|
| 648 |
61 |
| die "sample size is larger than nrow"; |
| 649 |
|
| } |
| 650 |
|
| |
| 651 |
61 |
| my @indices = (0 .. $self->nrow-1); |
| 652 |
61 |
| my $indices = [ List::AllUtils::sample($n, @indices) ]; |
| 653 |
61 |
| return $self->select_rows($indices); |
| 654 |
|
| } |
| 655 |
|
| |
| 656 |
|
| |
| 657 |
61 |
▶ | method which (:$bad_to_val=undef, :$ignore_both_bad=true) { |
|
Subroutine
which: called CC=6 SCAR=18.4
Pod
documented
Branch: 4 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method which (expected 1, got ' . @_ . ')') |
0 |
61 |
61 |
| @_ > 1 and (@_ - 1) % 2 and Function::Parameters::_croak("Odd number of paired arguments for method which") |
0 |
61 |
61 |
| exists ${__rest}{'ignore_both_bad'} ? : |
0 |
61 |
61 |
| keys %{__rest} and Function::Parameters::_croak('In method which: no such named parameter: ' . join(", ", sort(keys %{__rest}))) |
0 |
189 |
189 |
MC/DC0%0/2
@_ > 1 and (@_ - 1) % 2
@_ > 1
(@_ - 1) % 2
Truth table66%2/3
A and B
A= @_ > 1B= (@_ - 1) % 2
|
| 658 |
189 |
▶ | my $coordinates = [ 0 .. $self->ncol - 1 ]->map( |
Branch: 1 branch
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for fun (anon) (expected 1, got ' . @_ . ')') |
0 |
189 |
189 |
|
| 659 |
189 |
▶ | fun($cidx) |
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
|
| 660 |
109 |
▶ | { |
Branch: 1 branch
| Branch | True | False | Total |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for fun (anon) (expected 1, got ' . @_ . ')') |
189 |
0 |
189 |
|
| 661 |
10 |
| my $column = $self->nth_column( $cidx ); |
| 662 |
1 |
▶ | my $both_bad = |
Branch: 1 branch
| Branch | True | False | Total |
| $self->DOES('Data::Frame::Role::CompareResult') ? : |
109 |
80 |
189 |
|
| 663 |
|
| $self->DOES('Data::Frame::Role::CompareResult') |
| 664 |
|
| ? $self->both_bad->nth_column( $cidx ) |
| 665 |
|
| : undef; |
| 666 |
|
| |
| 667 |
1 |
▶ | if ( defined $bad_to_val and $column->badflag ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (defined $bad_to_val and $column->badflag) |
189 |
0 |
189 |
Condition100%3/3
defined $bad_to_val and $column->badflag
MC/DC100%2/2
defined $bad_to_val and $column->badflag
defined $bad_to_val
$column->badflag
Truth table100%3/3
A and B
A= defined $bad_to_valB= $column->badflag
|
| 668 |
1 |
| $column = $column->setbadtoval($bad_to_val); |
| 669 |
|
| } |
| 670 |
|
| |
| 671 |
1 |
▶ | my $indices_false = PDL::Primitive::which( |
Branch: 1 branch
| Branch | True | False | Total |
| defined $both_bad ? : |
0 |
1 |
1 |
|
| 672 |
|
| defined $both_bad ? ( !$both_bad & $column ) : $column ); |
| 673 |
1 |
▶ | return $indices_false->unpdl->map( sub { [ $_, $cidx ] } )->flatten; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 674 |
189 |
| } |
| 675 |
|
| ); |
| 676 |
189 |
| return pdl($coordinates); |
| 677 |
|
| } |
| 678 |
|
| |
| 679 |
|
| |
| 680 |
1 |
▶ | method merge (DataFrame $df) { |
|
Subroutine
merge: called CC=6 SCAR=18.2
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method merge (expected 2, got ' . @_ . ')') |
0 |
1 |
1 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method merge (expected 2, got ' . @_ . ')') |
1 |
0 |
1 |
| do {
package Type::Tiny;
builtin::blessed($df) and do {
my $method = $df->can("DOES") || $df->can("isa");
$df->$method("Data::Frame")
}
} or Function::Parameters::_croak('In method merge: parameter 1 ($df): ' . ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"compiled_type_constraint" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('Data::Frame') } };},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 20,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "DataFrame","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "DataFrame","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"Data::Frame\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "Data::Frame","uniq" => 76}, 'Type::Tiny::Role' ),"uniq" => 77}, 'Type::Tiny' );$v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"compiled_type_constraint"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"compiled_type_constraint"}; \$v}->get_message($df)) |
0 |
3 |
3 |
|
| 681 |
6 |
| my $class = ref($self); |
| 682 |
|
| my $columns = [ |
| 683 |
6 |
▶ | $self->names->map( sub { $_ => $self->column($_) } )->flatten, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 684 |
6 |
▶ | $df->names->map( sub { $_ => $df->column($_) } )->flatten |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 685 |
|
| ]; |
| 686 |
6 |
| return $class->new( |
| 687 |
|
| columns => $columns, |
| 688 |
|
| row_names => $self->row_names |
| 689 |
|
| ); |
| 690 |
|
| } |
| 691 |
|
| *cbind = \&merge; |
| 692 |
|
| |
| 693 |
6 |
▶ | method append (DataFrame $df) { |
|
Subroutine
append: called CC=8 SCAR=21.1
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method append (expected 2, got ' . @_ . ')') |
0 |
3 |
3 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method append (expected 2, got ' . @_ . ')') |
3 |
0 |
3 |
| do {
package Type::Tiny;
builtin::blessed($df) and do {
my $method = $df->can("DOES") || $df->can("isa");
$df->$method("Data::Frame")
}
} or Function::Parameters::_croak('In method append: parameter 1 ($df): ' . ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"compiled_type_constraint" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('Data::Frame') } };},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 20,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "DataFrame","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "DataFrame","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"Data::Frame\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "Data::Frame","uniq" => 76}, 'Type::Tiny::Role' ),"uniq" => 77}, 'Type::Tiny' );$v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"compiled_type_constraint"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"compiled_type_constraint"}; \$v}->get_message($df)) |
0 |
6 |
6 |
|
| 694 |
6 |
▶ | if ( $df->nrow == 0 ) { # $df is empty |
Branch: 1 branch
| Branch | True | False | Total |
| if ($df->nrow == 0) |
0 |
6 |
6 |
|
| 695 |
1 |
| return $self->clone(); |
| 696 |
|
| } |
| 697 |
5 |
▶ | if ( $self->column_names->length == 0) { # $self has no columns |
Branch: 1 branch
| Branch | True | False | Total |
| if ($self->column_names->length == 0) |
1 |
5 |
6 |
|
| 698 |
5 |
| return $df->clone; |
| 699 |
|
| } |
| 700 |
|
| |
| 701 |
5 |
| my $class = ref($self); |
| 702 |
|
| my $columns = $self->names->map( |
| 703 |
6 |
▶ | sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 704 |
5 |
| my $col = $self->column($_); |
| 705 |
|
| # use glue() as PDL's append() cannot handle bad values |
| 706 |
2 |
| $_ => $col->glue( 0, $df->column($_) ); |
| 707 |
|
| } |
| 708 |
3 |
| ); |
| 709 |
3 |
| return $class->new( columns => $columns ); |
| 710 |
|
| } |
| 711 |
|
| *rbind = \&append; |
| 712 |
|
| |
| 713 |
|
| |
| 714 |
|
| |
| 715 |
2 |
▶ | method transform ($func) { |
|
Subroutine
transform: called CC=5 SCAR=16.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method transform (expected 2, got ' . @_ . ')') |
3 |
2 |
5 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method transform (expected 2, got ' . @_ . ')') |
4 |
51 |
55 |
|
| 716 |
5 |
| state $check = Type::Params::compile( |
| 717 |
|
| ( |
| 718 |
|
| CodeRef | ( HashRef [ Maybe [CodeRef] ] ) | |
| 719 |
|
| ( CycleTuple [ Str, Maybe [CodeRef] ] ) |
| 720 |
|
| ) |
| 721 |
|
| ); |
| 722 |
6 |
| ($func) = $check->($func); |
| 723 |
|
| |
| 724 |
6 |
| my $class = ref($self); |
| 725 |
|
| |
| 726 |
6 |
| my @columns; |
| 727 |
2 |
▶ | if ( Ref::Util::is_coderef($func) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (Ref::Util::XS::is_coderef($func)) { } |
0 |
1 |
1 |
|
| 728 |
|
| @columns = |
| 729 |
2 |
▶ | $self->names->map( sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 730 |
1 |
| $_ => $func->( $self->column($_), $self ); |
| 731 |
55 |
| } )->flatten; |
| 732 |
|
| } |
| 733 |
|
| else { # hashref or arrayref |
| 734 |
55 |
| my $column_names = $self->names; |
| 735 |
55 |
| my $hashref; |
| 736 |
|
| my @new_column_names; |
| 737 |
51 |
▶ | if ( Ref::Util::is_hashref($func) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (Ref::Util::XS::is_hashref($func)) { } |
0 |
1 |
1 |
|
| 738 |
2 |
| $hashref = $func; |
| 739 |
|
| @new_column_names = |
| 740 |
62 |
| grep { !$self->exists($_) } sort( keys %$hashref ); |
| 741 |
|
| } |
| 742 |
|
| else { # arrayref |
| 743 |
1 |
| $hashref = {@$func}; |
| 744 |
1 |
| @new_column_names = grep { !$self->exists($_) } ( pairkeys @$func ); |
| 745 |
|
| } |
| 746 |
|
| |
| 747 |
|
| @columns = $column_names->map( |
| 748 |
55 |
▶ | sub { |
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
|
| 749 |
2 |
▶ | my $f = exists($hashref->{$_}) ? $hashref->{$_} : sub { $_[0] }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| Branch | True | False | Total |
| exists $hashref->{$_} ? : |
1 |
0 |
1 |
|
| 750 |
2 |
▶ | $f //= sub { undef }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
MC/DC0%0/2
$f //= sub {
undef;
}
$f
sub {
undef;
}
Truth table66%2/3
A //= B
A= $fB= sub {
undef;
}
|
| 751 |
1 |
| $_ => $f->( $self->column($_), $self ); |
| 752 |
|
| } |
| 753 |
1 |
| )->flatten; |
| 754 |
|
| push @columns, |
| 755 |
1 |
| map { my $f = $hashref->{$_}; $_ => $f->( undef, $self ) } |
| 756 |
|
| @new_column_names; |
| 757 |
|
| } |
| 758 |
|
| |
| 759 |
0 |
| my %columns_to_drop = @columns; |
| 760 |
1 |
▶ | %columns_to_drop = pairgrep { not defined $b } %columns_to_drop; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 761 |
|
| |
| 762 |
|
| return $class->new( |
| 763 |
1 |
▶ | columns => [ pairgrep { !exists($columns_to_drop{$a}) } @columns ], |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 764 |
|
| row_names => $self->row_names, |
| 765 |
|
| ); |
| 766 |
|
| } |
| 767 |
|
| |
| 768 |
|
| |
| 769 |
6 |
▶ | method split (ColumnLike $factor) { |
|
Subroutine
split: called CC=7 SCAR=19.9
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method split (expected 2, got ' . @_ . ')') |
0 |
1 |
1 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method split (expected 2, got ' . @_ . ')') |
0 |
1 |
1 |
| ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Type::Tiny; use warnings; use strict; local $_ = $_[0]; foreach my $c (@constraints) { return unless &$c(@_); } return !0;},"display_name" => "to_ColumnLike","name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Data::Frame::Types; use warnings; use strict; $_->ndims <= 1;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 24,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "ColumnLike","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "ColumnLike","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('PDL') } };},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"PDL\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "PDL","uniq" => 82}, 'Type::Tiny::Role' ),"uniq" => 83}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"}; \$v}->check($factor) or Function::Parameters::_croak('In method split: parameter 1 ($factor): ' . ${my $v = bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Type::Tiny; use warnings; use strict; local $_ = $_[0]; foreach my $c (@constraints) { return unless &$c(@_); } return !0;},"display_name" => "to_ColumnLike","name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Data::Frame::Types; use warnings; use strict; $_->ndims <= 1;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 24,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "ColumnLike","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "ColumnLike","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('PDL') } };},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"PDL\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "PDL","uniq" => 82}, 'Type::Tiny::Role' ),"uniq" => 83}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"}; \$v}->get_message($factor)) |
0 |
1 |
1 |
|
| 770 |
7 |
▶ | if ($factor->$_DOES('PDL::Factor')) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($factor->$Data::Frame::_DOES("PDL::Factor")) |
0 |
6 |
6 |
|
| 771 |
7 |
| $factor = $factor->{PDL}; |
| 772 |
|
| } |
| 773 |
|
| # avoid // as breaks Devel::Cover |
| 774 |
7 |
| my $uniq_values = $factor->$_call_if_can('uniq'); |
| 775 |
7 |
▶ | $uniq_values = [ List::AllUtils::uniq( $factor->flatten ) ] |
Branch: 1 branch
| Branch | True | False | Total |
| unless defined $uniq_values |
0 |
6 |
6 |
|
| 776 |
|
| if !defined $uniq_values; |
| 777 |
|
| |
| 778 |
|
| my @rslt = map { |
| 779 |
2 |
| my $indices = PDL::Primitive::which( $factor == $_ ); |
| 780 |
7 |
| $_ => $self->select_rows($indices); |
| 781 |
|
| } $uniq_values->flatten; |
| 782 |
|
| |
| 783 |
7 |
▶ | return (wantarray ? @rslt : { @rslt }); |
Branch: 1 branch
| Branch | True | False | Total |
| wantarray ? : |
1 |
5 |
6 |
|
| 784 |
|
| } |
| 785 |
|
| |
| 786 |
|
| |
| 787 |
7 |
▶ | method sort ($by_columns, $ascending=true) { |
|
Subroutine
sort: called CC=5 SCAR=16.4
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method sort (expected 2, got ' . @_ . ')') |
0 |
6 |
6 |
| @_ > 3 and Function::Parameters::_croak('Too many arguments for method sort (expected 3, got ' . @_ . ')') |
0 |
7 |
7 |
| @_ < 2 and $ascending = &true() |
0 |
7 |
7 |
|
| 788 |
27 |
▶ | return $self->clone if $by_columns->length == 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if $by_columns->length == 0 |
1 |
6 |
7 |
|
| 789 |
|
| |
| 790 |
27 |
| my $row_indices = $self->sorti( $by_columns, $ascending ); |
| 791 |
7 |
| return $self->select_rows($row_indices); |
| 792 |
|
| } |
| 793 |
|
| |
| 794 |
14 |
▶ | method sorti ($by_columns, $ascending=true) { |
|
Subroutine
sorti: called CC=6 SCAR=18.0
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method sorti (expected 2, got ' . @_ . ')') |
2 |
5 |
7 |
| @_ > 3 and Function::Parameters::_croak('Too many arguments for method sorti (expected 3, got ' . @_ . ')') |
0 |
7 |
7 |
| @_ < 2 and $ascending = &true() |
45 |
1 |
46 |
|
| 795 |
32 |
▶ | if (Ref::Util::is_plain_arrayref($ascending)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_plain_arrayref($ascending)) |
14 |
32 |
46 |
|
| 796 |
32 |
| $ascending = logical($ascending); |
| 797 |
|
| } |
| 798 |
|
| |
| 799 |
1 |
▶ | return pdl( [ 0 .. $self->nrow - 1 ] ) if $by_columns->length == 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if $by_columns->length == 0 |
17 |
15 |
32 |
|
| 800 |
|
| |
| 801 |
14 |
▶ | my $is_number = $by_columns->map( sub { $self->is_numeric_column($_) } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 802 |
33 |
▶ | my $compare = sub { |
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
|
| 803 |
1 |
| my ( $a, $b ) = @_; |
| 804 |
2 |
| for my $i ( 0 .. $#$is_number ) { |
| 805 |
1 |
▶ | my $rslt = ( |
Branch: 1 branch
| Branch | True | False | Total |
| $is_number->[$i] ? : |
1 |
71 |
72 |
|
| 806 |
|
| $is_number->[$i] |
| 807 |
|
| ? $a->[$i] <=> $b->[$i] |
| 808 |
|
| : $a->[$i] cmp $b->[$i] |
| 809 |
|
| ); |
| 810 |
1 |
▶ | next if $rslt == 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if $rslt == 0 |
0 |
1 |
1 |
|
| 811 |
|
| |
| 812 |
2 |
▶ | my $this_ascending = $ascending->$_call_if_can( 'at', $i ) |
Condition66%2/3
$ascending->$Data::Frame::_call_if_can("at", $i) // $ascending
MC/DC0%0/2
$ascending->$Data::Frame::_call_if_can("at", $i) // $ascending
$ascending->$Data::Frame::_call_if_can("at", $i)
$ascending
Truth table66%2/3
A // B
A= $ascending->$Data::Frame::_call_if_can("at", $i)B= $ascending
|
| 813 |
|
| // $ascending; |
| 814 |
1 |
▶ | return ( $this_ascending ? $rslt : -$rslt ); |
Branch: 1 branch
| Branch | True | False | Total |
| $this_ascending ? : |
0 |
1 |
1 |
|
| 815 |
|
| } |
| 816 |
32 |
| return 0; |
| 817 |
36 |
| }; |
| 818 |
|
| |
| 819 |
|
| my $ea = |
| 820 |
36 |
▶ | each_arrayref( @{ $by_columns->map( sub { $self->at($_)->unpdl } ) } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 821 |
36 |
| my @sorted_row_indices = map { $_->[0] } |
| 822 |
1 |
| sort { $compare->( $a->[1], $b->[1] ) } |
| 823 |
|
| map { |
| 824 |
72 |
| my @row_data = $ea->(); |
| 825 |
1 |
| [ $_, \@row_data ]; |
| 826 |
|
| } ( 0 .. $self->nrow - 1 ); |
| 827 |
|
| |
| 828 |
1 |
| return pdl( \@sorted_row_indices ); |
| 829 |
|
| } |
| 830 |
|
| |
| 831 |
|
| |
| 832 |
|
| my $sereal = Sereal::Encoder->new(); |
| 833 |
|
| |
| 834 |
36 |
▶ | sub _serialize_row { |
|
Subroutine
_serialize_row: called CC=3 SCAR=11.0
|
| 835 |
4 |
| my ($self, $i, $columns, $columns_isbad) = @_; |
| 836 |
|
| |
| 837 |
|
| my @row_data = |
| 838 |
|
| map { |
| 839 |
4 |
| my $isbad = $columns_isbad->[$_]; |
| 840 |
1 |
▶ | ( defined $isbad and $isbad->at($i) ) |
Branch: 1 branch
| Branch | True | False | Total |
| defined $isbad && $isbad->at($i) ? : |
2 |
0 |
2 |
Condition100%3/3
defined $isbad and $isbad->at($i)
MC/DC100%2/2
defined $isbad and $isbad->at($i)
defined $isbad
$isbad->at($i)
Truth table100%3/3
A and B
A= defined $isbadB= $isbad->at($i)
|
| 841 |
|
| ? ( 1, undef ) |
| 842 |
|
| : ( 0, $columns->[$_]->at($i) ); |
| 843 |
|
| } ( 0 .. $#$columns ); |
| 844 |
1 |
| return $sereal->encode( \@row_data ); |
| 845 |
|
| } |
| 846 |
|
| |
| 847 |
1 |
▶ | method uniq () { |
|
Subroutine
uniq: called CC=6 SCAR=18.0
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method uniq (expected 1, got ' . @_ . ')') |
4 |
28 |
32 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method uniq (expected 1, got ' . @_ . ')') |
0 |
1 |
1 |
|
| 848 |
1 |
| my %uniq; |
| 849 |
|
| my @uniq_ridx; |
| 850 |
|
| |
| 851 |
1 |
| my @columns = map { $self->column($_) } @{ $self->column_names }; |
| 852 |
1 |
▶ | my @columns_isbad = map { $_->badflag ? $_->isbad : undef } @columns; |
Branch: 1 branch
| Branch | True | False | Total |
| $_->badflag ? : |
0 |
1 |
1 |
|
| 853 |
|
| |
| 854 |
4 |
| for my $i ( 0 .. $self->nrow - 1 ) { |
| 855 |
3 |
| my $key = $self->_serialize_row($i, \@columns, \@columns_isbad); |
| 856 |
3 |
▶ | unless ( exists $uniq{$key} ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (exists $uniq{$key}) |
1 |
1 |
2 |
|
| 857 |
4 |
| $uniq{$key} = 1; |
| 858 |
4 |
| push @uniq_ridx, $i; |
| 859 |
|
| } |
| 860 |
|
| } |
| 861 |
1 |
| return $self->select_rows( \@uniq_ridx ); |
| 862 |
|
| } |
| 863 |
|
| |
| 864 |
|
| |
| 865 |
1 |
▶ | method id () { |
|
Subroutine
id: called CC=7 SCAR=19.5
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method id (expected 1, got ' . @_ . ')') |
3 |
1 |
4 |
| @_ > 1 and Function::Parameters::_croak('Too many arguments for method id (expected 1, got ' . @_ . ')') |
0 |
3 |
3 |
|
| 866 |
2 |
| my @columns = map { $self->column($_) } @{ $self->column_names }; |
| 867 |
3 |
▶ | my @columns_isbad = map { $_->badflag ? $_->isbad : undef } @columns; |
Branch: 1 branch
| Branch | True | False | Total |
| $_->badflag ? : |
0 |
3 |
3 |
|
| 868 |
|
| |
| 869 |
3 |
| my %uniq_serialized; |
| 870 |
|
| my @uniq_rindices; |
| 871 |
3 |
| for my $ridx ( 0 .. $self->nrow - 1 ) { |
| 872 |
3 |
| my $key = $self->_serialize_row($ridx, \@columns, \@columns_isbad); |
| 873 |
3 |
▶ | if ( not exists $uniq_serialized{$key} ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (exists $uniq_serialized{$key}) |
3 |
0 |
3 |
|
| 874 |
225 |
| $uniq_serialized{$key} = []; |
| 875 |
225 |
| push @uniq_rindices, $ridx; |
| 876 |
|
| } |
| 877 |
225 |
| push @{ $uniq_serialized{$key} }, $ridx; |
| 878 |
|
| } |
| 879 |
|
| |
| 880 |
225 |
▶ | my %rindex_to_serialized = pairmap { $b->[0] => $a } %uniq_serialized; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 881 |
225 |
| my $rindices_sorted = |
| 882 |
|
| $self->select_rows( \@uniq_rindices )->sorti( $self->names ); |
| 883 |
|
| |
| 884 |
225 |
| my $rslt = PDL::Core::zeros( $self->nrow ); |
| 885 |
2859 |
| for my $i ( 1 .. $#uniq_rindices ) { |
| 886 |
|
| my $serialized = |
| 887 |
2859 |
| $rindex_to_serialized{ $uniq_rindices[ $rindices_sorted->at($i) ] }; |
| 888 |
3 |
| my $rindices = $uniq_serialized{$serialized}; |
| 889 |
3 |
| $rslt->slice( pdl($rindices) ) .= $i; |
| 890 |
|
| } |
| 891 |
3 |
| return $rslt; |
| 892 |
|
| } |
| 893 |
|
| |
| 894 |
|
| |
| 895 |
3 |
▶ | method assign ((DataFrame | Piddle) $x) { |
|
Subroutine
assign: called CC=17 SCAR=32.0
Pod
documented
Branch: 3 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method assign (expected 2, got ' . @_ . ')') |
0 |
225 |
225 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method assign (expected 2, got ' . @_ . ')') |
0 |
225 |
225 |
| do {
package Type::Tiny;
builtin::blessed($x) and do {
my $method = $x->can("DOES") || $x->can("isa");
$x->$method("Data::Frame")
}
} or Type::Tiny::XS::AUTO::TC1($x) or Function::Parameters::_croak('In method assign: parameter 1 ($x): ' . ${my $v = bless( {"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame.pm","line" => 895,"package" => "Data::Frame"},"deprecated" => !!0,"name" => "__ANON__","type_constraints" => [bless( {"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"compiled_type_constraint" => sub ($) { package Eval::TypeTiny::Sandbox; use strict; do { package Type::Tiny; builtin::blessed($_[0]) and do { my $method = $_[0]->can('DOES') || $_[0]->can('isa'); $_[0]->$method('Data::Frame') } };},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/home/cpancover/.cpan/build/Data-Frame-0.006005-0/blib/lib/Data/Frame/Types.pm","line" => 20,"package" => "Data::Frame::Types"},"deprecated" => !!0,"display_name" => "DataFrame","exception_class" => "Error::TypeTiny::Assertion","library" => "Data::Frame::Types","name" => "DataFrame","parent" => bless( {"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"frozen" => 1,"name" => "__ANON__","type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 1015,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "ConsumerOf[\"Data::Frame\"]","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Type::Tiny::Role; use warnings; use strict; my $var = $_[1]; my $code = "Scalar::Util::blessed($var) and do { my \$method = $var->can('DOES')||$var->can('isa'); $var->\$method(q[$role]) }"; return "do { use Scalar::Util (); $code }" if $Type::Tiny::AvoidCallbacks; $code;},"name" => "__ANON__","role" => "Data::Frame","uniq" => 76}, 'Type::Tiny::Role' ),"uniq" => 77}, 'Type::Tiny' ),bless( {"_caller_level" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; Type::Tiny::XS::AUTO::TC1($_[0]) or _failed_check(46, 'Piddle', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"class" => "PDL","compiled_type_constraint" => sub ;,"constraint_generator" => sub { package Type::TinyX::Facets; use warnings; use strict; my $base = do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x45\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} $Type::Tiny::parameterize_type }; my(%params) = @_ or return $base; my(@checks) = &$IG(%params)->($base, '$_[0]'); $checks[0] = $base->inline_check('$_[0]'); my $sub = sprintf('sub { %s }', join(' and ', map(("($_)"), @checks))); eval $sub or _croak("could not build sub: $@\n\nCODE: $sub\n");},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/PDL.pm","line" => 138,"package" => "Types::PDL"},"deprecated" => !!0,"display_name" => "Piddle","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Type::TinyX::Facets; use warnings; use strict; my(%p_not_destroyed) = @_; return sub { my(%p) = %p_not_destroyed; my $var = $_[1]; my(@r) = map($_->[1]->(\%p, $var, $_->[0]), @facets); _croak(sprintf('Attempt to parameterize type "%s" with unrecognised parameter%s %s', $_[0]->name, scalar keys %p == 1 ? '' : 's', Type::Utils::english_list(map((qq["$_"]), sort(keys %p))))) if keys %p; return undef, @r; } ;},"inlined" => sub { package Type::Tiny::Class; use warnings; use strict; my $var = $_[1]; return "do { use Scalar::Util (); Scalar::Util::blessed($var) and $var->isa(q[$class]) }" if $Type::Tiny::AvoidCallbacks; return "$xsub($var)" if $xsub; "Scalar::Util::blessed($var) and $var->isa(q[$class])";},"library" => "Types::PDL","name" => "Piddle","name_generator" => sub { package Type::TinyX::Facets; use warnings; use strict; my($s, %a) = @_; sprintf '%s[%s]', $s, join(',', map(sprintf('%s=>%s', $_, B::perlstring($a{$_})), sort(keys %a)));},"parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; Ref::Util::XS::is_blessed_ref($_[0]) or _failed_check(24, 'Object', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Object","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; builtin::blessed($_);},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 578,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Object","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_blessed_ref($_[1])" : &$maybe_load_modules('Scalar::Util', "Scalar::Util::blessed($_[1])");},"is_object" => 1,"library" => "Types::Standard","name" => "Object","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; not ref $_[0] and _failed_check(16, 'Ref', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Ref","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_;},"constraint_generator" => sub { package Types::Standard; no warnings; use strict; return $meta->get_type('Ref') unless @_; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'Ref', \@_, 1); my $reftype = shift(); $reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or _croak "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype"; $reftype = "$reftype"; return sub { ref $_[0] and builtin::reftype($_[0]) eq $reftype; } ;},"deep_explanation" => sub { package Types::Standard; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; return if $type->check($value); my $reftype = builtin::reftype($value); return [sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)), sprintf('reftype(%s) is %s', $varname, defined $reftype ? B::perlstring($reftype) : 'undef')];},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 438,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Ref","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard; no warnings; use strict; my $reftype = shift(); return sub { my $v = $_[1]; &$maybe_load_modules('Scalar::Util', "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"); } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; "!!ref($_[1])";},"library" => "Types::Standard","name" => "Ref","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 16}, 'Type::Tiny' ),"uniq" => 24}, 'Type::Tiny' ),"uniq" => 46}, 'Type::Tiny::Class' )],"uniq" => 94,"xs_sub" => undef}, 'Type::Tiny::Union' );$v->{"type_constraints"}[0]{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"type_constraints"}[0]{"compiled_type_constraint"};$v->{"type_constraints"}[0]{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[0]{"parent"};$v->{"type_constraints"}[0]{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[0]{"compiled_type_constraint"};$v->{"type_constraints"}[1]{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"};$v->{"type_constraints"}[1]{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"} = $v->{"type_constraints"}[0]{"constraint"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"type_constraints"}[0]{"constraint"};$v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"parent"} = $v->{"type_constraints"}[1]{"parent"}{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($x)) |
0 |
3 |
3 |
Condition66%2/3
do {
package Type::Tiny;
builtin::blessed($x) and do {
my $method = $x->can("DOES") || $x->can("isa");
$x->$method("Data::Frame")
}
} or Type::Tiny::XS::AUTO::TC1($x)
MC/DC0%0/2
do {
package Type::Tiny;
builtin::blessed($x) and do {
my $method = $x->can("DOES") || $x->can("isa");
$x->$method("Data::Frame")
}
} or Type::Tiny::XS::AUTO::TC1($x)
do {
package Type::Tiny;
builtin::blessed($x) and do {
my $method = $x->can("DOES") || $x->can("isa");
$x->$method("Data::Frame")
}
}
Type::Tiny::XS::AUTO::TC1($x)
Truth table66%2/3
A or B
A= do {
package Type::Tiny;
builtin::blessed($x) and do {
my $method = $x->can("DOES") || $x->can("isa");
$x->$method("Data::Frame")
}
}B= Type::Tiny::XS::AUTO::TC1($x)
|
| 896 |
3 |
▶ | if ( DataFrame->check($x) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (&DataFrame()->check($x)) { } |
0 |
3 |
3 |
| elsif ($x->$Data::Frame::_DOES('PDL')) { } |
2 |
1 |
3 |
|
| 897 |
3 |
▶ | unless ( ( $self->shape == $x->shape )->all ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (($self->shape == $x->shape)->all) |
0 |
3 |
3 |
|
| 898 |
3 |
| die "Cannot assign a data frame of different shape."; |
| 899 |
|
| } |
| 900 |
3 |
| for my $name ( $self->names->flatten ) { |
| 901 |
18 |
| my $col = $self->column($name); |
| 902 |
18 |
| $col .= $x->column($name); |
| 903 |
|
| } |
| 904 |
|
| } |
| 905 |
|
| elsif ( $x->$_DOES('PDL') ) { |
| 906 |
12 |
| my @dims = $self->dims; |
| 907 |
|
| |
| 908 |
6 |
▶ | unless ( $x->ndims == 1 and $x->dim(0) == $dims[0] * $dims[1] |
Branch: 1 branch
| Branch | True | False | Total |
| unless ($x->ndims == 1 and $x->dim(0) == $dims[0] * $dims[1] or $x->ndims == 2 and $x->dim(0) == $dims[0] and $x->dim(1) == $dims[1]) |
2 |
1 |
3 |
Condition33%4/12
$x->ndims == 1 and $x->dim(0) == $dims[0] * $dims[1] or $x->ndims == 2 and $x->dim(0) == $dims[0] and $x->dim(1) == $dims[1]
$x->ndims == 1 and $x->dim(0) == $dims[0] * $dims[1]
$x->ndims == 2 and $x->dim(0) == $dims[0] and $x->dim(1) == $dims[1]
$x->ndims == 2 and $x->dim(0) == $dims[0]
MC/DC0%0/5
$x->ndims == 1 and $x->dim(0) == $dims[0] * $dims[1] or $x->ndims == 2 and $x->dim(0) == $dims[0] and $x->dim(1) == $dims[1]
$x->ndims == 1
$x->dim(0) == $dims[0] * $dims[1]
$x->ndims == 2
$x->dim(0) == $dims[0]
$x->dim(1) == $dims[1]
Truth table0%0/9
A and B or C and D and E
A= $x->ndims == 1B= $x->dim(0) == $dims[0] * $dims[1]C= $x->ndims == 2D= $x->dim(0) == $dims[0]E= $x->dim(1) == $dims[1]
| A | B | C | D | E | result |
| 1 | 1 | X | X | X | 1 |
| 0 | X | 1 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 1 | 1 |
| 0 | X | 0 | X | X | 0 |
| 0 | X | 1 | 0 | X | 0 |
| 0 | X | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | X | X | 0 |
| 1 | 0 | 1 | 0 | X | 0 |
| 1 | 0 | 1 | 1 | 0 | 0 |
|
| 909 |
|
| or $x->ndims == 2 |
| 910 |
|
| and $x->dim(0) == $dims[0] |
| 911 |
|
| and $x->dim(1) == $dims[1] ) |
| 912 |
|
| { |
| 913 |
70 |
| die; |
| 914 |
|
| } |
| 915 |
|
| |
| 916 |
70 |
| for my $i ( 0 .. $self->length - 1 ) { |
| 917 |
70 |
| $self->_nth_column($i) .= |
| 918 |
|
| $x->flat->slice( pdl( 0 .. $dims[0] - 1 ) + $i * $dims[1] ); |
| 919 |
|
| } |
| 920 |
|
| } |
| 921 |
70 |
| return $self; |
| 922 |
|
| } |
| 923 |
|
| |
| 924 |
|
| |
| 925 |
70 |
▶ | method is_numeric_column ($column_name_or_idx) { |
|
Subroutine
is_numeric_column: called CC=3 SCAR=11.2
Pod
documented
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 2 and Function::Parameters::_croak('Too few arguments for method is_numeric_column (expected 2, got ' . @_ . ')') |
18 |
0 |
18 |
| @_ > 2 and Function::Parameters::_croak('Too many arguments for method is_numeric_column (expected 2, got ' . @_ . ')') |
0 |
70 |
70 |
|
| 926 |
70 |
| my $column = $self->at($column_name_or_idx); |
| 927 |
70 |
| return $self->_is_numeric_column($column); |
| 928 |
|
| } |
| 929 |
|
| |
| 930 |
2859 |
▶ | sub _is_numeric_column { |
|
Subroutine
_is_numeric_column: called CC=1 SCAR=0.0
|
| 931 |
70 |
| my ($self, $piddle) = @_; |
| 932 |
70 |
| return !is_discrete($piddle); |
| 933 |
|
| } |
| 934 |
|
| |
| 935 |
|
| |
| 936 |
0 |
▶ | method drop_bad (:$how='any') { |
|
Subroutine
drop_bad: called CC=7 SCAR=21.8
Pod
documented
Branch: 4 branches
| Branch | True | False | Total |
| @_ < 1 and Function::Parameters::_croak('Too few arguments for method drop_bad (expected 1, got ' . @_ . ')') |
0 |
70 |
70 |
| @_ > 1 and (@_ - 1) % 2 and Function::Parameters::_croak("Odd number of paired arguments for method drop_bad") |
70 |
0 |
70 |
| exists ${__rest}{'how'} ? : |
1 |
69 |
70 |
| keys %{__rest} and Function::Parameters::_croak('In method drop_bad: no such named parameter: ' . join(", ", sort(keys %{__rest}))) |
0 |
69 |
69 |
MC/DC0%0/2
@_ > 1 and (@_ - 1) % 2
@_ > 1
(@_ - 1) % 2
Truth table66%2/3
A and B
A= @_ > 1B= (@_ - 1) % 2
|
| 937 |
0 |
| state $check = Type::Params::compile( Enum [qw(all any)] ); |
| 938 |
0 |
| ($how) = $check->($how); |
| 939 |
|
| |
| 940 |
3 |
▶ | my $f = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 941 |
66 |
| my ($op) = @_; |
| 942 |
18 |
▶ | return reduce { |
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
|
| 943 |
201 |
| my $col = $self->column($b); |
| 944 |
201 |
▶ | $col->badflag ? $op->( $a, $col->isbad ) : $a; |
Branch: 1 branch
| Branch | True | False | Total |
| $col->badflag ? : |
0 |
201 |
201 |
|
| 945 |
201 |
| } PDL::Core::zeros( $self->nrow ), $self->names->flatten; |
| 946 |
69 |
| }; |
| 947 |
|
| |
| 948 |
|
| my $isbad = |
| 949 |
|
| $how eq 'any' |
| 950 |
201 |
▶ | ? $f->( sub { $_[0] | $_[1] } ) |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 951 |
69 |
▶ | : $f->( sub { $_[0] & $_[1] } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Branch: 1 branch
| Branch | True | False | Total |
| $how eq 'any' ? : |
0 |
0 |
0 |
|
| 952 |
66 |
| return $self->select_rows( PDL::Primitive::which( !$isbad ) ); |
| 953 |
|
| } |
| 954 |
|
| |
| 955 |
|
| |
| 956 |
201 |
▶ | method _compare ($other, $mode) { |
|
Subroutine
_compare: called CC=9 SCAR=22.2
Branch: 2 branches
| Branch | True | False | Total |
| @_ < 3 and Function::Parameters::_croak('Too few arguments for method _compare (expected 3, got ' . @_ . ')') |
182 |
0 |
182 |
| @_ > 3 and Function::Parameters::_croak('Too many arguments for method _compare (expected 3, got ' . @_ . ')') |
1 |
138 |
139 |
|
| 957 |
4 |
| my $class = ref($self); |
| 958 |
|
| |
| 959 |
66 |
▶ | state $gen_fcompare = sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 960 |
201 |
| my ($f) = @_; |
| 961 |
|
| |
| 962 |
201 |
▶ | return sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
|
| 963 |
201 |
| my ( $col, $x ) = @_; |
| 964 |
190 |
| my $col_isbad = $col->isbad; |
| 965 |
|
| # avoid // as breaks Devel::Cover |
| 966 |
10 |
| my $x_isbad = $x->$_call_if_can('isbad'); |
| 967 |
1 |
▶ | $x_isbad = 1 if !defined $x_isbad; |
Branch: 1 branch
| Branch | True | False | Total |
| unless defined $x_isbad |
0 |
201 |
201 |
|
| 968 |
201 |
| my $both_bad = ( $col_isbad & $x_isbad ); |
| 969 |
|
| |
| 970 |
0 |
| my $rslt = $f->( $col, $x ); |
| 971 |
201 |
| return ( $rslt, $both_bad ); |
| 972 |
|
| } |
| 973 |
4 |
| }; |
| 974 |
|
| |
| 975 |
|
| state $fcompare_exact = { |
| 976 |
201 |
▶ | pairmap { $a => $gen_fcompare->($b) } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 977 |
|
| ( |
| 978 |
0 |
▶ | eq => sub { $_[0] == $_[1] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=6.9
|
| 979 |
201 |
▶ | ne => sub { $_[0] != $_[1] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 980 |
201 |
▶ | lt => sub { $_[0] < $_[1] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 981 |
3 |
▶ | le => sub { $_[0] <= $_[1] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 982 |
3 |
▶ | gt => sub { $_[0] > $_[1] }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
|
| 983 |
11 |
▶ | ge => sub { $_[0] >= $_[1] }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
|
| 984 |
|
| ) |
| 985 |
0 |
| }; |
| 986 |
|
| |
| 987 |
|
| # Absolute tolerance, calculated from multiplying $TOLERANCE_REL |
| 988 |
|
| # with max abs of the two values. |
| 989 |
182 |
▶ | state $_tolerance = sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
|
| 990 |
11 |
| my ( $col, $x ) = @_; |
| 991 |
11 |
| my $a = $col->abs; |
| 992 |
11 |
| my $b = ref($x) ? $x->abs : abs($x); |
| 993 |
11 |
| return (ifelse( $a > $b, $a, $b ) * abs($TOLERANCE_REL)); |
| 994 |
0 |
| }; |
| 995 |
|
| |
| 996 |
|
| state $fcompare_float = { |
| 997 |
11 |
▶ | pairmap { $a => $gen_fcompare->($b) } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 998 |
|
| ( |
| 999 |
11 |
▶ | eq => sub { ( $_[0] - $_[1] )->abs < $_tolerance->(@_) }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1000 |
11 |
▶ | ne => sub { ( $_[0] - $_[1] )->abs > $_tolerance->(@_) }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1001 |
11 |
▶ | lt => sub { ( $_[0] - $_[1] ) < $_tolerance->(@_) }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1002 |
11 |
▶ | le => sub { ( $_[0] - $_[1] ) < $_tolerance->(@_) }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
|
| 1003 |
11 |
▶ | gt => sub { ( $_[0] - $_[1] ) > $_tolerance->(@_) }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
|
| 1004 |
|
| ) |
| 1005 |
182 |
| }; |
| 1006 |
|
| |
| 1007 |
139 |
▶ | state $same_names = sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
|
| 1008 |
11 |
| my ( $a, $b ) = @_; |
| 1009 |
11 |
| return 0 unless $a->length eq $b->length; |
| 1010 |
|
| return ( |
| 1011 |
11 |
▶ | List::AllUtils::all { $a->at($_) eq $b->at($_) } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1012 |
11 |
| ( 0 .. $a->length - 1 ) |
| 1013 |
|
| ); |
| 1014 |
182 |
| }; |
| 1015 |
|
| |
| 1016 |
201 |
▶ | my $compare_column = sub { |
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
|
| 1017 |
11 |
| my ( $name, $x ) = @_; |
| 1018 |
|
| |
| 1019 |
11 |
| my $col = $self->column($name); |
| 1020 |
|
| |
| 1021 |
11 |
| my $fcompare; |
| 1022 |
11 |
| if ( $self->is_numeric_column($name) ) { |
| 1023 |
|
| $fcompare = |
| 1024 |
|
| ( |
| 1025 |
|
| not defined $TOLERANCE_REL |
| 1026 |
|
| or ( $col->type < PDL::float |
| 1027 |
|
| and ( !ref($x) and $x->type < PDL::float ) ) |
| 1028 |
|
| ) |
| 1029 |
|
| ? $fcompare_exact->{$mode} |
| 1030 |
11 |
| : $fcompare_float->{$mode}; |
| 1031 |
|
| } |
| 1032 |
|
| elsif ( $col->$_DOES('PDL::SV') ) { |
| 1033 |
11 |
| $fcompare = $fcompare_exact->{$mode}; |
| 1034 |
|
| } |
| 1035 |
|
| elsif ( $col->$_DOES('PDL::Factor') ) { |
| 1036 |
11 |
| $fcompare = $fcompare_exact->{$mode}; |
| 1037 |
|
| } |
| 1038 |
|
| |
| 1039 |
11 |
| unless ($fcompare) { |
| 1040 |
11 |
| die qq{Different types found on column "$name"}; |
| 1041 |
|
| } |
| 1042 |
|
| |
| 1043 |
11 |
| return $fcompare->( $col, $x ); |
| 1044 |
182 |
| }; |
| 1045 |
|
| |
| 1046 |
182 |
| my $result_columns; |
| 1047 |
30 |
▶ | if ( $other->$_DOES('Data::Frame') ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ($other->$Data::Frame::_DOES('Data::Frame')) { } |
190 |
11 |
201 |
|
| 1048 |
1 |
▶ | unless ( $same_names->( $self->column_names, $other->column_names ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (&$same_names($self->column_names, $other->column_names)) |
10 |
1 |
11 |
|
| 1049 |
179 |
| failure::columns::mismatch->throw; |
| 1050 |
|
| } |
| 1051 |
2 |
▶ | unless ( $same_names->( $self->row_names, $other->row_names ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| unless (&$same_names($self->row_names, $other->row_names)) |
1 |
0 |
1 |
|
| 1052 |
0 |
| failure::rows::mismatch->throw; |
| 1053 |
|
| } |
| 1054 |
|
| $result_columns = { |
| 1055 |
|
| $self->names->map( |
| 1056 |
11 |
▶ | sub { $_ => [ $compare_column->( $_, $other->column($_) ) ]; } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1057 |
0 |
| )->flatten |
| 1058 |
|
| }; |
| 1059 |
|
| } |
| 1060 |
|
| else { |
| 1061 |
139 |
▶ | unless ( looks_like_number($other) |
Branch: 1 branch
| Branch | True | False | Total |
| unless (&looks_like_number($other) or $other->$Data::Frame::_DOES("PDL") and $other->length == 1) |
8 |
182 |
190 |
Condition33%1/3
&looks_like_number($other) or $other->$Data::Frame::_DOES("PDL") and $other->length == 1
MC/DC0%0/2
&looks_like_number($other) or $other->$Data::Frame::_DOES("PDL") and $other->length == 1
&looks_like_number($other)
$other->$Data::Frame::_DOES("PDL") and $other->length == 1
Truth table33%1/3
A or B
A= &looks_like_number($other)B= $other->$Data::Frame::_DOES("PDL") and $other->length == 1
|
| 1062 |
|
| or ( $other->$_DOES('PDL') and $other->length == 1 ) ) |
| 1063 |
|
| { |
| 1064 |
139 |
| die "Cannot compare data frame with non-number or non-data-frame."; |
| 1065 |
|
| } |
| 1066 |
|
| $result_columns = { |
| 1067 |
|
| $self->names->map( |
| 1068 |
11 |
▶ | sub { $_ => [ $compare_column->( $_, $other ) ]; } |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
|
| 1069 |
138 |
| )->flatten |
| 1070 |
|
| }; |
| 1071 |
|
| } |
| 1072 |
|
| |
| 1073 |
|
| my $both_bad = |
| 1074 |
|
| $class->new( columns => |
| 1075 |
911 |
▶ | $self->names->map( sub { $_ => $result_columns->{$_}->[1] } ) ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1076 |
|
| return $class->with_traits('CompareResult')->new( |
| 1077 |
|
| columns => |
| 1078 |
201 |
▶ | $self->names->map( sub { $_ => $result_columns->{$_}->[0] } ), |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
|
| 1079 |
|
| both_bad => $both_bad, |
| 1080 |
|
| ); |
| 1081 |
|
| } |
| 1082 |
|
| |
| 1083 |
3 |
▶ | sub _column_helper { |
|
Subroutine
_column_helper: called CC=1 SCAR=0.0
|
| 1084 |
11 |
| my ($self) = @_; |
| 1085 |
11 |
| Data::Frame::Column::Helper->new( dataframe => $self ); |
| 1086 |
|
| } |
| 1087 |
|
| |
| 1088 |
|
| |
| 1089 |
|
| 1; |
| 1090 |
|
| |
| 1091 |
|
| __END__ |