From: <cde...@us...> - 2010-11-29 14:46:51
|
Revision: 7963 http://octave.svn.sourceforge.net/octave/?rev=7963&view=rev Author: cdemills Date: 2010-11-29 14:46:44 +0000 (Mon, 29 Nov 2010) Log Message: ----------- Horzcat and vertcat must insert the row/column names early through inputname, otherwise it is no more useable in cat Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m trunk/octave-forge/extra/dataframe/inst/@dataframe/vertcat.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m 2010-11-29 14:42:34 UTC (rev 7962) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m 2010-11-29 14:46:44 UTC (rev 7963) @@ -59,24 +59,28 @@ resu._cnt(1) = resu._cnt(1) + B._cnt(1); resu._ridx = [resu._ridx(:); B._ridx(:)]; %# find data with same column names - indr = logical(ones(1, resu._cnt(2))); - indb = logical(ones(1, resu._cnt(2))); - indi = 1; - while indi <= resu._cnt(2), - indj = strmatch(resu._name{2}(indi), B. _name{2}, 'exact'); - if ~isempty(indj), - indj = indj(1); - if ~strcmp(resu._type{indi}, B._type{indj}), - error("Trying to mix columns of different types"); + dummy = A._over{2} & B._over{2}; + indA = logical(ones(1, resu._cnt(2))); + indB = logical(ones(1, resu._cnt(2))); + for indj = 1:resu._cnt(2), + if (dummy(indj)), + indk = strmatch(resu._name{2}(indi), B. _name{2}, 'exact'); + if (~isempty(indk)), + indk = indk(1); + if ~strcmp(resu._type{indi}, B._type{indk}), + error("Trying to mix columns of different types"); + endif endif - resu._data{indi} = [resu._data{indi}; B._data{indj}]; - indr(indi) = false; indb(indj) = false; + else + indk = indj; endif - indi = indi + 1; - endwhile - if any(indr) || any(indb) + resu._data{indj} = [resu._data{indj}; B._data{indk}]; + indA(indj) = false; indB(indk) = false; + endfor + if any(indA) || any(indB) error('Different number/names of columns in dataframe'); endif + endfor case 2 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-11-29 14:42:34 UTC (rev 7962) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-11-29 14:46:44 UTC (rev 7963) @@ -299,8 +299,12 @@ df._over{2}(1, indj) = true; else if !isempty(indj), - if length(df._name{2}) < indj(1) || isempty(df._name{2}(indj)), + if (1 == length(df._name{2}) && length(df._name{2}) < \ + length(indj)), [df._name{2}(indj, 1), df._over{2}(1, indj)] ... + = df_colnames(char(df._name{2}), indj); + elseif (length(df._name{2}) < indj(1) || isempty(df._name{2}(indj))), + [df._name{2}(indj, 1), df._over{2}(1, indj)] ... = df_colnames(inputname(indi), indj); endif endif Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m 2010-11-29 14:42:34 UTC (rev 7962) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m 2010-11-29 14:46:44 UTC (rev 7963) @@ -24,6 +24,10 @@ %# $Id$ %# - resu = cat(1, df, varargin{:}); + for indi = 1:length(varargin), + varargin{indi} = dataframe(varargin{indi}, 'colnames', inputname(1+indi));, + endfor + + resu = cat(2, df, varargin{:}); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/vertcat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/vertcat.m 2010-11-29 14:42:34 UTC (rev 7962) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/vertcat.m 2010-11-29 14:46:44 UTC (rev 7963) @@ -24,6 +24,11 @@ %# $Id$ %# - resu = cat(2, df, varargin{:}); + %# do the conversion now, in order not to loose inputnames + for indi = 1:length(varargin), + varargin{indi} = dataframe(varargin{indi}, 'colnames', inputname(1+indi));, + endfor + resu = cat(1, df, varargin{:}); + endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |