Skip to content

Commit 9f83bd0

Browse files
[Annika Rudolph]annika-rudolph
[Annika Rudolph]
authored andcommitted
add test for frequency of DatetimeIndex in MultiIndex
1 parent e313e14 commit 9f83bd0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas/core/arrays/datetimelike.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import numpy as np
2121

22-
from pandas.core.algorithms import take
2322
from pandas._config.config import get_option
2423

2524
from pandas._libs import (
@@ -66,9 +65,9 @@
6665
ScalarIndexer,
6766
Self,
6867
SequenceIndexer,
68+
TakeIndexer,
6969
TimeAmbiguous,
7070
TimeNonexistent,
71-
TakeIndexer,
7271
npt,
7372
)
7473
from pandas.compat.numpy import function as nv
@@ -118,6 +117,7 @@
118117
from pandas.core.algorithms import (
119118
isin,
120119
map_array,
120+
take,
121121
unique1d,
122122
)
123123
from pandas.core.array_algos import datetimelike_accumulations
@@ -2357,6 +2357,7 @@ def take(
23572357
axis=axis,
23582358
)
23592359
result = self._from_backing_data(new_data)
2360+
23602361
indices = np.asarray(indices, dtype=np.intp)
23612362
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
23622363

pandas/tests/indexes/multi/test_get_level_values.py

+11
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,14 @@ def test_values_loses_freq_of_underlying_index():
122122
midx.values
123123
assert idx.freq is not None
124124
tm.assert_index_equal(idx, expected)
125+
126+
127+
def test_get_level_values_gets_frequency_correctly():
128+
# GH#57949 GH#58327
129+
datetime_index = pd.date_range(start=pd.to_datetime("1/1/2018"),
130+
periods = 4,
131+
freq = 'YS')
132+
other_index = ["A"]
133+
multi_index = pd.MultiIndex.from_product([datetime_index, other_index])
134+
135+
assert multi_index.get_level_values(0).freq is datetime_index.freq

0 commit comments

Comments
 (0)