Skip to content

Commit ada956b

Browse files
committed
convert data to type needed - PDLPorters/pdl#511
1 parent ecd4c03 commit ada956b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Changes

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Revision history of Data-Frame
22

3+
0.006004 TBD
4+
- update assignments etc so types match (https://github.com/PDLPorters/pdl/issues/511)
5+
36
0.006003 2024-10-24
47
- allow PDL::{Factor,Logical,SV} "initialize" to be instance methods
58

lib/Data/Frame/Util.pm

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ it returns a piddle of the same length as C<$test>, and is filled with
8282
elements selected from C<$yes> or C<$no> depending on whether the
8383
corresponding element in C<$test> is true or false.
8484
85-
C<$test>, C<$yes>, C<$no> should ideally be piddles or cocere-able to
85+
C<$test>, C<$yes>, C<$no> should ideally be piddles or coerce-able to
8686
piddles.
8787
8888
=cut
@@ -103,7 +103,10 @@ fun ifelse ($test, $yes, $no) {
103103
}
104104

105105
$no = $no->repeat_to_length($l);
106-
$yes->slice($idx) .= $no->slice($idx);
106+
my $no_sliced = $no->slice($idx);
107+
$no_sliced = $no_sliced->convert($yes->type->enum)
108+
if $yes->type != $no->type;
109+
$yes->slice($idx) .= $no_sliced;
107110

108111
return $yes;
109112
}

lib/PDL/SV.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sub new {
105105
my $self = $class->initialize();
106106
my $pdl = $self->{PDL};
107107
$pdl .= PDL::Core::indx($faked_data);
108-
$pdl .= PDL->sequence( $self->dims );
108+
$pdl .= PDL->sequence( PDL::Core::indx(), $self->dims );
109109

110110
if ($self->ndims == 1) { # for speed
111111
$self->_internal($data);
@@ -245,7 +245,7 @@ sub sever {
245245
my ($self) = @_;
246246

247247
$self->_internal( $self->_effective_internal );
248-
my $p = PDL->sequence( $self->dims );
248+
my $p = PDL->sequence( $self->type, $self->dims );
249249
$p = $p->setbadif( $self->isbad ) if $self->badflag;
250250
$self->{PDL} = $p;
251251
return $self;
@@ -339,7 +339,7 @@ sub copy {
339339
my ($self) = @_;
340340

341341
my $new = PDL::SV->new( [] );
342-
$new->{PDL} = PDL->sequence( $self->dims );
342+
$new->{PDL} = PDL->sequence( $self->type, $self->dims );
343343
$new->_internal( $self->_effective_internal );
344344
if ( $self->badflag ) {
345345
$new->{PDL} = $new->{PDL}->setbadif( $self->isbad );

0 commit comments

Comments
 (0)