Skip to content

Commit

Permalink
convert data to type needed - PDLPorters/pdl#511
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 20, 2024
1 parent ecd4c03 commit ada956b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history of Data-Frame

0.006004 TBD
- update assignments etc so types match (https://github.com/PDLPorters/pdl/issues/511)

0.006003 2024-10-24
- allow PDL::{Factor,Logical,SV} "initialize" to be instance methods

Expand Down
7 changes: 5 additions & 2 deletions lib/Data/Frame/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ it returns a piddle of the same length as C<$test>, and is filled with
elements selected from C<$yes> or C<$no> depending on whether the
corresponding element in C<$test> is true or false.
C<$test>, C<$yes>, C<$no> should ideally be piddles or cocere-able to
C<$test>, C<$yes>, C<$no> should ideally be piddles or coerce-able to
piddles.
=cut
Expand All @@ -103,7 +103,10 @@ fun ifelse ($test, $yes, $no) {
}

$no = $no->repeat_to_length($l);
$yes->slice($idx) .= $no->slice($idx);
my $no_sliced = $no->slice($idx);
$no_sliced = $no_sliced->convert($yes->type->enum)
if $yes->type != $no->type;
$yes->slice($idx) .= $no_sliced;

return $yes;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PDL/SV.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ sub new {
my $self = $class->initialize();
my $pdl = $self->{PDL};
$pdl .= PDL::Core::indx($faked_data);
$pdl .= PDL->sequence( $self->dims );
$pdl .= PDL->sequence( PDL::Core::indx(), $self->dims );

if ($self->ndims == 1) { # for speed
$self->_internal($data);
Expand Down Expand Up @@ -245,7 +245,7 @@ sub sever {
my ($self) = @_;

$self->_internal( $self->_effective_internal );
my $p = PDL->sequence( $self->dims );
my $p = PDL->sequence( $self->type, $self->dims );
$p = $p->setbadif( $self->isbad ) if $self->badflag;
$self->{PDL} = $p;
return $self;
Expand Down Expand Up @@ -339,7 +339,7 @@ sub copy {
my ($self) = @_;

my $new = PDL::SV->new( [] );
$new->{PDL} = PDL->sequence( $self->dims );
$new->{PDL} = PDL->sequence( $self->type, $self->dims );
$new->_internal( $self->_effective_internal );
if ( $self->badflag ) {
$new->{PDL} = $new->{PDL}->setbadif( $self->isbad );
Expand Down

0 comments on commit ada956b

Please sign in to comment.