Skip to content
Snippets Groups Projects
Commit 04356a89 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Make new behaviour introduced in c6def35e optional.

(cherry picked from commit fd7476e6)
parent b1b4136e
No related branches found
Tags
No related merge requests found
function q = merge(o, p) % --*-- Unitary tests --*-- function q = merge(o, p, rewritewithnans) % --*-- Unitary tests --*--
% Merge method for dseries objects. % Merge method for dseries objects.
% %
% INPUTS % INPUTS
% - o [dseries] % - o [dseries]
% - p [dseries] % - p [dseries]
% - rewritewithnans [logical]
% %
% OUTPUTS % OUTPUTS
% - q [dseries] % - q [dseries]
% %
% REMARKS % REMARKS
% If dseries objects o and p have common variables, the variables in p take precedence. % If dseries objects o and p have common variables, the variables
% in p take precedence except if rewritewithnans is false and p has
% nans.
% Copyright © 2013-2019 Dynare Team % Copyright © 2013-2019 Dynare Team
% %
...@@ -41,6 +44,10 @@ if ~isequal(frequency(o), frequency(p)) ...@@ -41,6 +44,10 @@ if ~isequal(frequency(o), frequency(p))
end end
end end
if nargin<3
rewritewithnans = true;
end
q = dseries(); q = dseries();
[q.name, IBC, ~] = unique([o.name; p.name], 'last'); [q.name, IBC, ~] = unique([o.name; p.name], 'last');
...@@ -91,7 +98,7 @@ elseif firstdate(o) >= firstdate(p) ...@@ -91,7 +98,7 @@ elseif firstdate(o) >= firstdate(p)
end end
Z = [Z1 Z2]; Z = [Z1 Z2];
q.data = Z(:,IBC); q.data = Z(:,IBC);
if ~isempty(list_of_common_variables) if ~rewritewithnans && ~isempty(list_of_common_variables)
for i=1:length(iP) for i=1:length(iP)
jO = iO(i); jO = iO(i);
jP = iP(i); jP = iP(i);
...@@ -115,7 +122,7 @@ else ...@@ -115,7 +122,7 @@ else
end end
Z = [Z2 Z1]; Z = [Z2 Z1];
q.data = Z(:,IBC); q.data = Z(:,IBC);
if ~isempty(list_of_common_variables) if ~rewritewithnans && ~isempty(list_of_common_variables)
for i=1:length(iP) for i=1:length(iP)
jO = iO(i); jO = iO(i);
jP = iP(i); jP = iP(i);
...@@ -208,8 +215,30 @@ q.dates = q_init:q_init+(nobs(q)-1); ...@@ -208,8 +215,30 @@ q.dates = q_init:q_init+(nobs(q)-1);
%$ if t(1) %$ if t(1)
%$ t(2) = dassert(x.vobs,1); %$ t(2) = dassert(x.vobs,1);
%$ t(3) = dassert(x.name{1},'u'); %$ t(3) = dassert(x.name{1},'u');
%$ t(4) = dassert(x.data(5:end), ones(4,1)) && all(isnan(x.data(1:4)));
%$ t(5) = all(x.dates==dates('1989Q1'):dates('1990Q4'));
%$ end
%$ T = all(t);
%@eof:3
%@test:4
%$ % Define two dseries objects.
%$ y = dseries(ones(4,1),'1989Q1', 'u');
%$ z = dseries(ones(4,1),'1990Q1', 'u');
%$
%$ % Merge the two objects.
%$ try
%$ x = merge(y, z, false);
%$ t(1) = true;
%$ catch
%$ t = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(x.vobs,1);
%$ t(3) = dassert(x.name{1},'u');
%$ t(4) = dassert(x.data, ones(8,1)); %$ t(4) = dassert(x.data, ones(8,1));
%$ t(5) = all(x.dates==dates('1989Q1'):dates('1990Q4')); %$ t(5) = all(x.dates==dates('1989Q1'):dates('1990Q4'));
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:3 %@eof:4
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment