Skip to content

Commit 211edec

Browse files
use super() in take function
1 parent b8d390f commit 211edec

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

pandas/core/arrays/datetimelike.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
from pandas.core.algorithms import (
119119
isin,
120120
map_array,
121-
take,
122121
unique1d,
123122
)
124123
from pandas.core.array_algos import datetimelike_accumulations
@@ -2365,7 +2364,7 @@ def interpolate(
23652364
if not copy:
23662365
return self
23672366
return type(self)._simple_new(out_data, dtype=self.dtype)
2368-
2367+
23692368
def take(
23702369
self,
23712370
indices: TakeIndexer,
@@ -2374,27 +2373,18 @@ def take(
23742373
fill_value: Any = None,
23752374
axis: AxisInt = 0,
23762375
) -> Self:
2377-
2378-
if allow_fill:
2379-
fill_value = self._validate_scalar(fill_value)
2380-
2381-
new_data = take(
2382-
self._ndarray,
2383-
indices,
2384-
allow_fill=allow_fill,
2385-
fill_value=fill_value,
2386-
axis=axis,
2387-
)
2388-
result = self._from_backing_data(new_data)
2389-
2376+
result = super().take(
2377+
indices=indices, allow_fill=allow_fill, fill_value=fill_value, axis=axis
2378+
)
2379+
23902380
indices = np.asarray(indices, dtype=np.intp)
23912381
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
2392-
2382+
23932383
if isinstance(maybe_slice, slice):
23942384
freq = self._get_getitem_freq(maybe_slice)
23952385
result.freq = freq
2396-
2397-
return result
2386+
2387+
return result
23982388

23992389
# --------------------------------------------------------------
24002390
# Unsorted

pandas/tests/indexes/multi/test_get_level_values.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ def test_values_loses_freq_of_underlying_index():
126126

127127
def test_get_level_values_gets_frequency_correctly():
128128
# GH#57949 GH#58327
129-
datetime_index = pd.date_range(start=pd.to_datetime("1/1/2018"),
130-
periods = 4,
131-
freq = 'YS')
129+
datetime_index = pd.date_range(
130+
start=pd.to_datetime("1/1/2018"), periods=4, freq="YS"
131+
)
132132
other_index = ["A"]
133-
multi_index = pd.MultiIndex.from_product([datetime_index, other_index])
133+
multi_index = MultiIndex.from_product([datetime_index, other_index])
134134

135-
assert multi_index.get_level_values(0).freq is datetime_index.freq
135+
assert multi_index.get_level_values(0).freq == datetime_index.freq

0 commit comments

Comments
 (0)