Repository: pandas-dev/pandas

Issue:
reindex with Period results in NaN
#### Code Sample, a copy-pastable example if possible

```python

idx1 = pd.MultiIndex.from_tuples(
    [
        ("x", Period("2019Q1", "Q-DEC")),
        ("x", Period("2019Q2", "Q-DEC")),
    ]
)

idx2 = pd.MultiIndex.from_tuples(
    [
        ("x", Period("2019Q1", "Q-DEC")),
        ("x", Period("2019Q2", "Q-DEC")),
        ("x", "All"),
    ]
)

s = pd.Series([1.0, 1.0], index=idx1)

x  2019Q1    1.0
   2019Q2    1.0
dtype: float64

# ACTUAL

s.reindex(idx2)

x  2019Q1   NaN
   2019Q2   NaN
   All      NaN
dtype: float64

# EXPECTED

x  2019Q1   1.0
   2019Q2   1.0
   All      NaN
dtype: float64


```
#### Problem description

This is the underlying problem causing https://github.com/pandas-dev/pandas/issues/28323.  Reindexing with an index that contains a Period results in `NaN` results.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
machine          : AMD64
processor        : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : None.None

pandas           : 0.25.1
numpy            : 1.17.2
pytz             : 2019.2
dateutil         : 2.8.0
pip              : 19.2.2
setuptools       : 41.0.1
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.10.1
IPython          : 7.8.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None

</details>



Discussion:
This may also be related to #28323 - would take a PR for sure if you have one to offer
Sorry just realized you put that in the OP as well

Resolving patch:
diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py
--- a/pandas/core/indexes/period.py
+++ b/pandas/core/indexes/period.py
@@ -651,10 +651,13 @@ def get_indexer(self, target, method=None, limit=None, tolerance=None):
 
         if isinstance(target, PeriodIndex):
             target = target.asi8
+            self_index = self._int64index
+        else:
+            self_index = self
 
         if tolerance is not None:
             tolerance = self._convert_tolerance(tolerance, target)
-        return Index.get_indexer(self._int64index, target, method, limit, tolerance)
+        return Index.get_indexer(self_index, target, method, limit, tolerance)
 
     @Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs)
     def get_indexer_non_unique(self, target):


Test patch:
diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py
--- a/pandas/tests/indexes/period/test_period.py
+++ b/pandas/tests/indexes/period/test_period.py
@@ -354,6 +354,35 @@ def test_period_set_index_reindex(self):
         df = df.set_index(idx2)
         tm.assert_index_equal(df.index, idx2)
 
+    @pytest.mark.parametrize(
+        "p_values, o_values, values, expected_values",
+        [
+            (
+                [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
+                [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC"), "All"],
+                [1.0, 1.0],
+                [1.0, 1.0, np.nan],
+            ),
+            (
+                [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
+                [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
+                [1.0, 1.0],
+                [1.0, 1.0],
+            ),
+        ],
+    )
+    def test_period_reindex_with_object(
+        self, p_values, o_values, values, expected_values
+    ):
+        # GH 28337
+        period_index = PeriodIndex(p_values)
+        object_index = Index(o_values)
+
+        s = pd.Series(values, index=period_index)
+        result = s.reindex(object_index)
+        expected = pd.Series(expected_values, index=object_index)
+        tm.assert_series_equal(result, expected)
+
     def test_factorize(self):
         idx1 = PeriodIndex(
             ["2014-01", "2014-01", "2014-02", "2014-02", "2014-03", "2014-03"], freq="M"
diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py
--- a/pandas/tests/reshape/test_pivot.py
+++ b/pandas/tests/reshape/test_pivot.py
@@ -677,6 +677,32 @@ def test_pivot_periods(self, method):
             pv = pd.pivot(df, index="p1", columns="p2", values="data1")
         tm.assert_frame_equal(pv, expected)
 
+    def test_pivot_periods_with_margins(self):
+        # GH 28323
+        df = DataFrame(
+            {
+                "a": [1, 1, 2, 2],
+                "b": [
+                    pd.Period("2019Q1"),
+                    pd.Period("2019Q2"),
+                    pd.Period("2019Q1"),
+                    pd.Period("2019Q2"),
+                ],
+                "x": 1.0,
+            }
+        )
+
+        expected = DataFrame(
+            data=1.0,
+            index=pd.Index([1, 2, "All"], name="a"),
+            columns=pd.Index(
+                [pd.Period("2019Q1"), pd.Period("2019Q2"), "All"], name="b"
+            ),
+        )
+
+        result = df.pivot_table(index="a", columns="b", values="x", margins=True)
+        tm.assert_frame_equal(expected, result)
+
     @pytest.mark.parametrize(
         "values",
         [