File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -324,7 +324,7 @@ def _formatter_func(self):
324324 @cache_readonly
325325 def _engine (self ):
326326 # To avoid a reference cycle, pass a weakref of self to _engine_type.
327- period = weakref .ref (self )
327+ period = weakref .ref (self . _values )
328328 return self ._engine_type (period , len (self ))
329329
330330 @doc (Index .__contains__ )
Original file line number Diff line number Diff line change @@ -89,3 +89,17 @@ def test_get_level_values_na():
8989 result = index .get_level_values (0 )
9090 expected = pd .Index ([], dtype = object )
9191 tm .assert_index_equal (result , expected )
92+
93+
94+ def test_get_level_values_when_periods ():
95+ # GH33131. See also discussion in GH32669.
96+ # This test can probably be removed when PeriodIndex._engine is removed.
97+ from pandas import Period , PeriodIndex
98+
99+ idx = MultiIndex .from_arrays (
100+ [PeriodIndex ([Period ("2019Q1" ), Period ("2019Q2" )], name = "b" )]
101+ )
102+ idx2 = MultiIndex .from_arrays (
103+ [idx ._get_level_values (level ) for level in range (idx .nlevels )]
104+ )
105+ assert all (x .is_monotonic for x in idx2 .levels ) is True
You can’t perform that action at this time.
0 commit comments