BUG: replace with a dict misbehaving (GH 3064), due to incorrect filtering

rolled #3064 changes in here