File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -323,8 +323,8 @@ def _formatter_func(self):
323
323
324
324
@cache_readonly
325
325
def _engine (self ):
326
- # To avoid a reference cycle, pass a weakref of self to _engine_type.
327
- period = weakref .ref (self )
326
+ # To avoid a reference cycle, pass a weakref of self._values to _engine_type.
327
+ period = weakref .ref (self . _values )
328
328
return self ._engine_type (period , len (self ))
329
329
330
330
@doc (Index .__contains__ )
Original file line number Diff line number Diff line change @@ -89,3 +89,17 @@ def test_get_level_values_na():
89
89
result = index .get_level_values (0 )
90
90
expected = pd .Index ([], dtype = object )
91
91
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