Skip to content
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cd56929
Fix zip function call to include strict parameter
AnonToky Nov 11, 2025
bc08bff
handled the too-long modified
AnonToky Nov 11, 2025
74a09ae
edited
AnonToky Nov 11, 2025
2200f71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2025
04d3293
Merge branch 'pandas-dev:main' into sty
AnonToky Nov 19, 2025
5c9d1be
Refactor datetimelike.py by cleaning up decorators
AnonToky Nov 19, 2025
d91549a
Merge pull request #4 from AnonToky/AnonToky-patch-doc
AnonToky Nov 19, 2025
8fd7c66
Update
AnonToky Nov 19, 2025
3d9ad61
Refactor mean and inferred_freq methods documentation
AnonToky Nov 19, 2025
1ec3cdc
Update datetimelike.py
AnonToky Nov 19, 2025
e1b76d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
08446fa
to fix line too long
AnonToky Nov 19, 2025
4d1e0df
Update datetimelike.py
AnonToky Nov 19, 2025
3dfbdcc
Update datetimelike.py
AnonToky Nov 19, 2025
ba30c49
Merge branch 'main' into sty
AnonToky Nov 20, 2025
31942cf
Merge branch 'main' into sty
AnonToky Nov 25, 2025
167ae36
revoke the changes in @doc
AnonToky Nov 25, 2025
f2ce218
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 25, 2025
ca2abb3
Update datetimelike.py
AnonToky Nov 26, 2025
ae48396
Update datetimelike.py
AnonToky Nov 26, 2025
33a4d34
Update datetimelike.py
AnonToky Nov 26, 2025
c2fd12f
Merge branch 'main' into sty
AnonToky Nov 26, 2025
ac5cc29
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 91 additions & 5 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
NullFrequencyError,
)
from pandas.util._decorators import (
Appender,
cache_readonly,
doc,
)
Expand All @@ -62,7 +61,6 @@
import pandas.core.indexes.base as ibase
from pandas.core.indexes.base import (
Index,
_index_shared_docs,
)
from pandas.core.indexes.extension import NDArrayBackedExtensionIndex
from pandas.core.indexes.range import RangeIndex
Expand Down Expand Up @@ -199,8 +197,41 @@ def equals(self, other: Any) -> bool:

return np.array_equal(self.asi8, other.asi8)

@Appender(Index.__contains__.__doc__)
def __contains__(self, key: Any) -> bool:
"""
Return a boolean indicating whether the provided key is in the index.

Parameters
----------
key : label
The key to check if it is present in the index.

Returns
-------
bool
Whether the key search is in the index.

Raises
------
TypeError
If the key is not hashable.

See Also
--------
Index.isin : Returns an ndarray of boolean dtype indicating whether the
list-like key is in the index.

Examples
--------
>>> idx = pd.Index([1, 2, 3, 4])
>>> idx
Index([1, 2, 3, 4], dtype='int64')

>>> 2 in idx
True
>>> 6 in idx
False
"""
hash(key)
try:
self.get_loc(key)
Expand Down Expand Up @@ -243,8 +274,19 @@ def _format_attrs(self):
attrs.append(("freq", freq))
return attrs

@Appender(Index._summary.__doc__)
def _summary(self, name=None) -> str:
"""
Return a summarized representation.

Parameters
----------
name : str
name to use in the summary representation

Returns
-------
String with a summarized representation of the index
"""
result = super()._summary(name=name)
if self.freq:
result += f"\nFreq: {self.freqstr}"
Expand Down Expand Up @@ -833,7 +875,6 @@ def insert(self, loc: int, item):
# --------------------------------------------------------------------
# NDArray-Like Methods

@Appender(_index_shared_docs["take"] % _index_doc_kwargs)
def take(
self,
indices,
Expand All @@ -842,6 +883,51 @@ def take(
fill_value=None,
**kwargs,
) -> Self:
"""
Return a new %(klass)s of the values selected by the indices.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%(klass)s ends up as just Index in the docs for e.g. DatetimeIndex.take. Can you replace here.


For internal compatibility with numpy arrays.

Parameters
----------
indices : array-like
Indices to be taken.
axis : {0 or 'index'}, optional
The axis over which to select values, always 0 or 'index'.
allow_fill : bool, default True
How to handle negative values in `indices`.

* False: negative values in `indices` indicate positional indices
from the right (the default). This is similar to
:func:`numpy.take`.

* True: negative values in `indices` indicate
missing values. These values are set to `fill_value`. Any other
other negative values raise a ``ValueError``.

fill_value : scalar, default None
If allow_fill=True and fill_value is not None, indices specified by
-1 are regarded as NA. If Index doesn't hold NA, raise ValueError.
**kwargs
Required for compatibility with numpy.

Returns
-------
Index
An index formed of elements at the given indices. Will be the same
type as self, except for RangeIndex.

See Also
--------
numpy.ndarray.take: Return an array formed from the
elements of a at the given indices.

Examples
--------
>>> idx = pd.Index(["a", "b", "c"])
>>> idx.take([2, 2, 1, 2])
Index(['c', 'c', 'b', 'c'], dtype='str')
"""
nv.validate_take((), kwargs)
indices = np.asarray(indices, dtype=np.intp)

Expand Down
Loading