Skip to content

Commit b8d390f

Browse files
[Annika Rudolph]annika-rudolph
[Annika Rudolph]
authored andcommitted
add test for frequency of DatetimeIndex in MultiIndex
1 parent 7c2573c commit b8d390f

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
@@ -20,7 +20,6 @@
2020

2121
import numpy as np
2222

23-
from pandas.core.algorithms import take
2423
from pandas._config.config import get_option
2524

2625
from pandas._libs import (
@@ -67,9 +66,9 @@
6766
ScalarIndexer,
6867
Self,
6968
SequenceIndexer,
69+
TakeIndexer,
7070
TimeAmbiguous,
7171
TimeNonexistent,
72-
TakeIndexer,
7372
npt,
7473
)
7574
from pandas.compat.numpy import function as nv
@@ -119,6 +118,7 @@
119118
from pandas.core.algorithms import (
120119
isin,
121120
map_array,
121+
take,
122122
unique1d,
123123
)
124124
from pandas.core.array_algos import datetimelike_accumulations
@@ -2386,6 +2386,7 @@ def take(
23862386
axis=axis,
23872387
)
23882388
result = self._from_backing_data(new_data)
2389+
23892390
indices = np.asarray(indices, dtype=np.intp)
23902391
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
23912392

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)