Commit c6def35e authored by Stéphane Adjemian's avatar Stéphane Adjemian

Changed behaviour when two dseries have common variables.

If a variable, say x, is defined both in dseries objects o and p, then
merge(o, p) will select the variable x as defined in the second input, p,
except for NaNs elements in p if corresponding elements in the first
input, o, are numbers.
parent 82343061
......@@ -45,6 +45,8 @@ q = dseries();
[q.name, IBC, ~] = unique([o.name; p.name], 'last');
[list_of_common_variables, iO, iP] = intersect(o.name, p.name);
tex = [o.tex; p.tex];
q.tex = tex(IBC);
......@@ -79,7 +81,7 @@ elseif firstdate(o) >= firstdate(p)
diff = firstdate(o) - firstdate(p);
q_nobs = max(nobs(o) + diff, nobs(p));
q.data = NaN(q_nobs, vobs(q));
Z1 = [NaN(diff, vobs(o));o.data];
Z1 = [NaN(diff, vobs(o)); o.data];
if nobs(q) > nobs(o) + diff
Z1 = [Z1; NaN(nobs(q)-(nobs(o) + diff), vobs(o))];
end
......@@ -89,6 +91,15 @@ elseif firstdate(o) >= firstdate(p)
end
Z = [Z1 Z2];
q.data = Z(:,IBC);
if ~isempty(list_of_common_variables)
for i=1:length(iP)
jO = iO(i);
jP = iP(i);
jQ = find(strcmp(o.name{jO}, q.name));
id = isnan(q.data(:,jQ)) & ~isnan(Z1(:,jO)) & isnan(Z2(:,jP));
q.data(id, jQ) = Z1(id,jO);
end
end
q_init = firstdate(p);
else
diff = firstdate(p) - firstdate(o);
......@@ -104,6 +115,15 @@ else
end
Z = [Z2 Z1];
q.data = Z(:,IBC);
if ~isempty(list_of_common_variables)
for i=1:length(iP)
jO = iO(i);
jP = iP(i);
jQ = find(strcmp(o.name{jO}, q.name));
id = isnan(q.data(:,jQ)) & isnan(Z1(:,jP)) & ~isnan(Z2(:,jO));
q.data(id, jQ) = Z2(id,jO);
end
end
q_init = firstdate(o);
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment