Repository: pandas-dev/pandas

Issue:
bug in replace?
I think this is distinct from #5541 though I agree that an API change here might be helpful. AFAICT, I am using replace as 'expected', but all of the keys aren't being matched. Any idea what's going on?

```
d = {u'fname' :
    {'out_augmented_AUG_2011.json' : pd.Period(year=2011, month=8, freq='M'), 
    'out_augmented_JAN_2011.json' : pd.Period(year=2011, month=1, freq='M'),
    'out_augmented_MAY_2012.json' : pd.Period(year=2012, month=5, freq='M'),
    'out_augmented_SUBSIDY_WEEK.json' : pd.Period(year=2011, month=4, freq='M'),
    'out_augmented_AUG_2012.json' : pd.Period(year=2012, month=8, freq='M'),
    'out_augmented_MAY_2011.json' : pd.Period(year=2011, month=5, freq='M'),
    'out_augmented_SEP_2013.json' : pd.Period(year=2013, month=9, freq='M'),
    }}

df = pd.DataFrame(['out_augmented_AUG_2012.json',
                'out_augmented_SEP_2013.json',
                'out_augmented_SUBSIDY_WEEK.json',
                'out_augmented_MAY_2012.json',
                'out_augmented_MAY_2011.json',
                'out_augmented_AUG_2011.json',
                'out_augmented_JAN_2011.json'], columns=['fname'])

df.replace(d)
```

On

```
[31]: pd.version.version
[31]: '0.13.1-753-g4614ac8'
```



Discussion:

Resolving patch:
diff --git a/pandas/tseries/period.py b/pandas/tseries/period.py
--- a/pandas/tseries/period.py
+++ b/pandas/tseries/period.py
@@ -138,12 +138,10 @@ def __eq__(self, other):
                 raise ValueError("Cannot compare non-conforming periods")
             return (self.ordinal == other.ordinal
                     and _gfc(self.freq) == _gfc(other.freq))
-        else:
-            raise TypeError(other)
-        return False
+        return NotImplemented
 
     def __ne__(self, other):
-        return not self.__eq__(other)
+        return not self == other
 
     def __hash__(self):
         return hash((self.ordinal, self.freq))


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -8392,6 +8392,52 @@ def test_replace_swapping_bug(self):
         expect = pd.DataFrame({'a': ['Y', 'N', 'Y']})
         tm.assert_frame_equal(res, expect)
 
+    def test_replace_period(self):
+        d = {'fname':
+             {'out_augmented_AUG_2011.json': pd.Period(year=2011, month=8, freq='M'),
+              'out_augmented_JAN_2011.json': pd.Period(year=2011, month=1, freq='M'),
+              'out_augmented_MAY_2012.json': pd.Period(year=2012, month=5, freq='M'),
+              'out_augmented_SUBSIDY_WEEK.json': pd.Period(year=2011, month=4, freq='M'),
+              'out_augmented_AUG_2012.json': pd.Period(year=2012, month=8, freq='M'),
+              'out_augmented_MAY_2011.json': pd.Period(year=2011, month=5, freq='M'),
+              'out_augmented_SEP_2013.json': pd.Period(year=2013, month=9, freq='M')}}
+
+        df = pd.DataFrame(['out_augmented_AUG_2012.json',
+                           'out_augmented_SEP_2013.json',
+                           'out_augmented_SUBSIDY_WEEK.json',
+                           'out_augmented_MAY_2012.json',
+                           'out_augmented_MAY_2011.json',
+                           'out_augmented_AUG_2011.json',
+                           'out_augmented_JAN_2011.json'], columns=['fname'])
+        tm.assert_equal(set(df.fname.values), set(d['fname'].keys()))
+        expected = DataFrame({'fname': [d['fname'][k]
+                                        for k in df.fname.values]})
+        result = df.replace(d)
+        tm.assert_frame_equal(result, expected)
+
+    def test_replace_datetime(self):
+        d = {'fname':
+             {'out_augmented_AUG_2011.json': pd.Timestamp('2011/08'),
+              'out_augmented_JAN_2011.json': pd.Timestamp('2011/01'),
+              'out_augmented_MAY_2012.json': pd.Timestamp('2012/05'),
+              'out_augmented_SUBSIDY_WEEK.json': pd.Timestamp('2011/04'),
+              'out_augmented_AUG_2012.json': pd.Timestamp('2012/08'),
+              'out_augmented_MAY_2011.json': pd.Timestamp('2011/05'),
+              'out_augmented_SEP_2013.json': pd.Timestamp('2013/09')}}
+
+        df = pd.DataFrame(['out_augmented_AUG_2012.json',
+                           'out_augmented_SEP_2013.json',
+                           'out_augmented_SUBSIDY_WEEK.json',
+                           'out_augmented_MAY_2012.json',
+                           'out_augmented_MAY_2011.json',
+                           'out_augmented_AUG_2011.json',
+                           'out_augmented_JAN_2011.json'], columns=['fname'])
+        tm.assert_equal(set(df.fname.values), set(d['fname'].keys()))
+        expected = DataFrame({'fname': [d['fname'][k]
+                                        for k in df.fname.values]})
+        result = df.replace(d)
+        tm.assert_frame_equal(result, expected)
+
     def test_combine_multiple_frames_dtypes(self):
 
         # GH 2759
@@ -11245,7 +11291,6 @@ def test_rank(self):
         exp = df.astype(float).rank(1)
         assert_frame_equal(result, exp)
 
-
     def test_rank2(self):
         from datetime import datetime
         df = DataFrame([[1, 3, 2], [1, 2, 3]])
@@ -11303,7 +11348,6 @@ def test_rank2(self):
         exp = DataFrame({"a":[ 3.5,  1. ,  3.5,  5. ,  6. ,  7. ,  2. ]})
         assert_frame_equal(df.rank(), exp)
 
-
     def test_rank_na_option(self):
         _skip_if_no_scipy()
         from scipy.stats import rankdata
diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py
--- a/pandas/tseries/tests/test_period.py
+++ b/pandas/tseries/tests/test_period.py
@@ -2455,10 +2455,8 @@ def test_equal(self):
     def test_equal_Raises_Value(self):
         self.assertRaises(ValueError, self.january1.__eq__, self.day)
 
-    def test_equal_Raises_Type(self):
-        self.assertRaises(TypeError, self.january1.__eq__, 1)
-
     def test_notEqual(self):
+        self.assertNotEqual(self.january1, 1)
         self.assertNotEqual(self.january1, self.february)
 
     def test_greater(self):