Skip to content

Commit

Permalink
use super() in take function
Browse files Browse the repository at this point in the history
  • Loading branch information
annika-rudolph committed Apr 30, 2024
1 parent b8d390f commit 211edec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
26 changes: 8 additions & 18 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
from pandas.core.algorithms import (
isin,
map_array,
take,
unique1d,
)
from pandas.core.array_algos import datetimelike_accumulations
Expand Down Expand Up @@ -2365,7 +2364,7 @@ def interpolate(
if not copy:
return self
return type(self)._simple_new(out_data, dtype=self.dtype)

def take(
self,
indices: TakeIndexer,
Expand All @@ -2374,27 +2373,18 @@ def take(
fill_value: Any = None,
axis: AxisInt = 0,
) -> Self:

if allow_fill:
fill_value = self._validate_scalar(fill_value)

new_data = take(
self._ndarray,
indices,
allow_fill=allow_fill,
fill_value=fill_value,
axis=axis,
)
result = self._from_backing_data(new_data)

result = super().take(
indices=indices, allow_fill=allow_fill, fill_value=fill_value, axis=axis
)

indices = np.asarray(indices, dtype=np.intp)
maybe_slice = lib.maybe_indices_to_slice(indices, len(self))

if isinstance(maybe_slice, slice):
freq = self._get_getitem_freq(maybe_slice)
result.freq = freq
return result

return result

# --------------------------------------------------------------
# Unsorted
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/indexes/multi/test_get_level_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def test_values_loses_freq_of_underlying_index():

def test_get_level_values_gets_frequency_correctly():
# GH#57949 GH#58327
datetime_index = pd.date_range(start=pd.to_datetime("1/1/2018"),
periods = 4,
freq = 'YS')
datetime_index = pd.date_range(
start=pd.to_datetime("1/1/2018"), periods=4, freq="YS"
)
other_index = ["A"]
multi_index = pd.MultiIndex.from_product([datetime_index, other_index])
multi_index = MultiIndex.from_product([datetime_index, other_index])

assert multi_index.get_level_values(0).freq is datetime_index.freq
assert multi_index.get_level_values(0).freq == datetime_index.freq

0 comments on commit 211edec

Please sign in to comment.