BUG: fix replace bug when a nested dict was passed
Merge pull request #4117 from cpcloud/replace-nested-dict-fix

BUG: fix replace bug when a nested dict was passed