Skip to content

Commit 229804f

Browse files
use super() in take function
1 parent 9f83bd0 commit 229804f

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
@@ -117,7 +117,6 @@
117117
from pandas.core.algorithms import (
118118
isin,
119119
map_array,
120-
take,
121120
unique1d,
122121
)
123122
from pandas.core.array_algos import datetimelike_accumulations
@@ -2336,7 +2335,7 @@ def interpolate(
23362335
if not copy:
23372336
return self
23382337
return type(self)._simple_new(out_data, dtype=self.dtype)
2339-
2338+
23402339
def take(
23412340
self,
23422341
indices: TakeIndexer,
@@ -2345,27 +2344,18 @@ def take(
23452344
fill_value: Any = None,
23462345
axis: AxisInt = 0,
23472346
) -> Self:
2348-
2349-
if allow_fill:
2350-
fill_value = self._validate_scalar(fill_value)
2351-
2352-
new_data = take(
2353-
self._ndarray,
2354-
indices,
2355-
allow_fill=allow_fill,
2356-
fill_value=fill_value,
2357-
axis=axis,
2358-
)
2359-
result = self._from_backing_data(new_data)
2360-
2347+
result = super().take(
2348+
indices=indices, allow_fill=allow_fill, fill_value=fill_value, axis=axis
2349+
)
2350+
23612351
indices = np.asarray(indices, dtype=np.intp)
23622352
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))
2363-
2353+
23642354
if isinstance(maybe_slice, slice):
23652355
freq = self._get_getitem_freq(maybe_slice)
23662356
result.freq = freq
2367-
2368-
return result
2357+
2358+
return result
23692359

23702360
# --------------------------------------------------------------
23712361
# 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)