BUG: fix replace bug when a nested dict was passed

closes #4115.