Skip to content

Commit 800a2c3

Browse files
Merge branch 'main' into fix/as_index_false_returns_multiindex
2 parents 03a7833 + bfe5be0 commit 800a2c3

File tree

17 files changed

+173
-93
lines changed

17 files changed

+173
-93
lines changed

ci/code_checks.sh

+4-36
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8080
-i "pandas.CategoricalIndex.codes SA01" \
8181
-i "pandas.CategoricalIndex.ordered SA01" \
8282
-i "pandas.DataFrame.__dataframe__ SA01" \
83-
-i "pandas.DataFrame.__iter__ SA01" \
8483
-i "pandas.DataFrame.at_time PR01" \
85-
-i "pandas.DataFrame.columns SA01" \
86-
-i "pandas.DataFrame.droplevel SA01" \
8784
-i "pandas.DataFrame.hist RT03" \
8885
-i "pandas.DataFrame.infer_objects RT03" \
8986
-i "pandas.DataFrame.kurt RT03,SA01" \
@@ -93,7 +90,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9390
-i "pandas.DataFrame.median RT03,SA01" \
9491
-i "pandas.DataFrame.min RT03" \
9592
-i "pandas.DataFrame.plot PR02,SA01" \
96-
-i "pandas.DataFrame.pop SA01" \
9793
-i "pandas.DataFrame.prod RT03" \
9894
-i "pandas.DataFrame.product RT03" \
9995
-i "pandas.DataFrame.reorder_levels SA01" \
@@ -107,67 +103,49 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
107103
-i "pandas.DataFrame.to_markdown SA01" \
108104
-i "pandas.DataFrame.to_parquet RT03" \
109105
-i "pandas.DataFrame.var PR01,RT03,SA01" \
110-
-i "pandas.DatetimeIndex.ceil SA01" \
111-
-i "pandas.DatetimeIndex.date SA01" \
112106
-i "pandas.DatetimeIndex.day_of_year SA01" \
113107
-i "pandas.DatetimeIndex.dayofyear SA01" \
114-
-i "pandas.DatetimeIndex.floor SA01" \
115108
-i "pandas.DatetimeIndex.freqstr SA01" \
116109
-i "pandas.DatetimeIndex.indexer_at_time PR01,RT03" \
117110
-i "pandas.DatetimeIndex.indexer_between_time RT03" \
118111
-i "pandas.DatetimeIndex.inferred_freq SA01" \
119112
-i "pandas.DatetimeIndex.is_leap_year SA01" \
120-
-i "pandas.DatetimeIndex.quarter SA01" \
121-
-i "pandas.DatetimeIndex.round SA01" \
122-
-i "pandas.DatetimeIndex.snap PR01,RT03,SA01" \
113+
-i "pandas.DatetimeIndex.snap PR01,RT03" \
123114
-i "pandas.DatetimeIndex.std PR01,RT03" \
124-
-i "pandas.DatetimeIndex.time SA01" \
125-
-i "pandas.DatetimeIndex.timetz SA01" \
126115
-i "pandas.DatetimeIndex.to_period RT03" \
127116
-i "pandas.DatetimeIndex.to_pydatetime RT03,SA01" \
128-
-i "pandas.DatetimeIndex.tz SA01" \
129117
-i "pandas.DatetimeIndex.tz_convert RT03" \
130118
-i "pandas.DatetimeTZDtype SA01" \
131119
-i "pandas.DatetimeTZDtype.tz SA01" \
132120
-i "pandas.DatetimeTZDtype.unit SA01" \
133121
-i "pandas.Grouper PR02" \
134-
-i "pandas.HDFStore.info RT03,SA01" \
135-
-i "pandas.HDFStore.keys SA01" \
136122
-i "pandas.HDFStore.put PR01,SA01" \
137-
-i "pandas.HDFStore.select SA01" \
138123
-i "pandas.HDFStore.walk SA01" \
139124
-i "pandas.Index PR07" \
140125
-i "pandas.Index.T SA01" \
141126
-i "pandas.Index.append PR07,RT03,SA01" \
142-
-i "pandas.Index.astype SA01" \
143127
-i "pandas.Index.copy PR07,SA01" \
144128
-i "pandas.Index.difference PR07,RT03,SA01" \
145129
-i "pandas.Index.drop PR07,SA01" \
146130
-i "pandas.Index.drop_duplicates RT03" \
147131
-i "pandas.Index.droplevel RT03,SA01" \
148132
-i "pandas.Index.dropna RT03,SA01" \
149-
-i "pandas.Index.dtype SA01" \
150133
-i "pandas.Index.duplicated RT03" \
151134
-i "pandas.Index.empty GL08" \
152-
-i "pandas.Index.equals SA01" \
153135
-i "pandas.Index.fillna RT03" \
154136
-i "pandas.Index.get_indexer PR07,SA01" \
155137
-i "pandas.Index.get_indexer_for PR01,SA01" \
156138
-i "pandas.Index.get_indexer_non_unique PR07,SA01" \
157139
-i "pandas.Index.get_loc PR07,RT03,SA01" \
158140
-i "pandas.Index.get_slice_bound PR07" \
159-
-i "pandas.Index.hasnans SA01" \
160141
-i "pandas.Index.identical PR01,SA01" \
161142
-i "pandas.Index.inferred_type SA01" \
162143
-i "pandas.Index.insert PR07,RT03,SA01" \
163144
-i "pandas.Index.intersection PR07,RT03,SA01" \
164145
-i "pandas.Index.item SA01" \
165146
-i "pandas.Index.join PR07,RT03,SA01" \
166-
-i "pandas.Index.map SA01" \
167147
-i "pandas.Index.memory_usage RT03" \
168-
-i "pandas.Index.name SA01" \
169148
-i "pandas.Index.names GL08" \
170-
-i "pandas.Index.nbytes SA01" \
171149
-i "pandas.Index.nunique RT03" \
172150
-i "pandas.Index.putmask PR01,RT03" \
173151
-i "pandas.Index.ravel PR01,RT03" \
@@ -287,34 +265,28 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
287265
-i "pandas.Series.cat.reorder_categories PR01,PR02" \
288266
-i "pandas.Series.cat.set_categories PR01,PR02" \
289267
-i "pandas.Series.div PR07" \
290-
-i "pandas.Series.droplevel SA01" \
291268
-i "pandas.Series.dt.as_unit PR01,PR02" \
292-
-i "pandas.Series.dt.ceil PR01,PR02,SA01" \
269+
-i "pandas.Series.dt.ceil PR01,PR02" \
293270
-i "pandas.Series.dt.components SA01" \
294-
-i "pandas.Series.dt.date SA01" \
295271
-i "pandas.Series.dt.day_name PR01,PR02" \
296272
-i "pandas.Series.dt.day_of_year SA01" \
297273
-i "pandas.Series.dt.dayofyear SA01" \
298274
-i "pandas.Series.dt.days SA01" \
299275
-i "pandas.Series.dt.days_in_month SA01" \
300276
-i "pandas.Series.dt.daysinmonth SA01" \
301-
-i "pandas.Series.dt.floor PR01,PR02,SA01" \
277+
-i "pandas.Series.dt.floor PR01,PR02" \
302278
-i "pandas.Series.dt.freq GL08" \
303279
-i "pandas.Series.dt.is_leap_year SA01" \
304280
-i "pandas.Series.dt.microseconds SA01" \
305281
-i "pandas.Series.dt.month_name PR01,PR02" \
306282
-i "pandas.Series.dt.nanoseconds SA01" \
307283
-i "pandas.Series.dt.normalize PR01" \
308-
-i "pandas.Series.dt.quarter SA01" \
309284
-i "pandas.Series.dt.qyear GL08" \
310-
-i "pandas.Series.dt.round PR01,PR02,SA01" \
285+
-i "pandas.Series.dt.round PR01,PR02" \
311286
-i "pandas.Series.dt.seconds SA01" \
312287
-i "pandas.Series.dt.strftime PR01,PR02" \
313-
-i "pandas.Series.dt.time SA01" \
314-
-i "pandas.Series.dt.timetz SA01" \
315288
-i "pandas.Series.dt.to_period PR01,PR02,RT03" \
316289
-i "pandas.Series.dt.total_seconds PR01" \
317-
-i "pandas.Series.dt.tz SA01" \
318290
-i "pandas.Series.dt.tz_convert PR01,PR02,RT03" \
319291
-i "pandas.Series.dt.tz_localize PR01,PR02" \
320292
-i "pandas.Series.dt.unit GL08" \
@@ -344,7 +316,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
344316
-i "pandas.Series.mod PR07" \
345317
-i "pandas.Series.mode SA01" \
346318
-i "pandas.Series.mul PR07" \
347-
-i "pandas.Series.nbytes SA01" \
348319
-i "pandas.Series.ne PR07,SA01" \
349320
-i "pandas.Series.nunique RT03" \
350321
-i "pandas.Series.pad PR01,SA01" \
@@ -432,14 +403,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
432403
-i "pandas.Timedelta.total_seconds SA01" \
433404
-i "pandas.Timedelta.view SA01" \
434405
-i "pandas.TimedeltaIndex.as_unit RT03,SA01" \
435-
-i "pandas.TimedeltaIndex.ceil SA01" \
436406
-i "pandas.TimedeltaIndex.components SA01" \
437407
-i "pandas.TimedeltaIndex.days SA01" \
438-
-i "pandas.TimedeltaIndex.floor SA01" \
439408
-i "pandas.TimedeltaIndex.inferred_freq SA01" \
440409
-i "pandas.TimedeltaIndex.microseconds SA01" \
441410
-i "pandas.TimedeltaIndex.nanoseconds SA01" \
442-
-i "pandas.TimedeltaIndex.round SA01" \
443411
-i "pandas.TimedeltaIndex.seconds SA01" \
444412
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
445413
-i "pandas.Timestamp PR07,SA01" \

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ Other
458458
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
459459
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
460460
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)
461+
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
461462
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
462463
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
463464
- Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)

pandas/_libs/lib.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def has_infs(const floating[:] arr) -> bool:
477477

478478
@cython.boundscheck(False)
479479
@cython.wraparound(False)
480-
def has_only_ints_or_nan(floating[:] arr) -> bool:
480+
def has_only_ints_or_nan(const floating[:] arr) -> bool:
481481
cdef:
482482
floating val
483483
intp_t i
@@ -631,7 +631,7 @@ ctypedef fused int6432_t:
631631

632632
@cython.wraparound(False)
633633
@cython.boundscheck(False)
634-
def is_range_indexer(ndarray[int6432_t, ndim=1] left, Py_ssize_t n) -> bool:
634+
def is_range_indexer(const int6432_t[:] left, Py_ssize_t n) -> bool:
635635
"""
636636
Perform an element by element comparison on 1-d integer arrays, meant for indexer
637637
comparisons
@@ -652,7 +652,7 @@ def is_range_indexer(ndarray[int6432_t, ndim=1] left, Py_ssize_t n) -> bool:
652652

653653
@cython.wraparound(False)
654654
@cython.boundscheck(False)
655-
def is_sequence_range(ndarray[int6432_t, ndim=1] sequence, int64_t step) -> bool:
655+
def is_sequence_range(const int6432_t[:] sequence, int64_t step) -> bool:
656656
"""
657657
Check if sequence is equivalent to a range with the specified step.
658658
"""

pandas/_libs/reshape.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from pandas._libs.lib cimport c_is_list_like
1919

2020
@cython.wraparound(False)
2121
@cython.boundscheck(False)
22-
def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,
22+
def unstack(const numeric_object_t[:, :] values, const uint8_t[:] mask,
2323
Py_ssize_t stride, Py_ssize_t length, Py_ssize_t width,
2424
numeric_object_t[:, :] new_values, uint8_t[:, :] new_mask) -> None:
2525
"""
@@ -80,7 +80,7 @@ def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,
8080

8181
@cython.wraparound(False)
8282
@cython.boundscheck(False)
83-
def explode(ndarray[object] values):
83+
def explode(object[:] values):
8484
"""
8585
transform array list-likes to long form
8686
preserve non-list entries

pandas/core/arrays/datetimelike.py

+5
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,11 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
18251825
------
18261826
ValueError if the `freq` cannot be converted.
18271827
1828+
See Also
1829+
--------
1830+
DatetimeIndex.floor : Perform floor operation on the data to the specified `freq`.
1831+
DatetimeIndex.snap : Snap time stamps to nearest occurring frequency.
1832+
18281833
Notes
18291834
-----
18301835
If the timestamps have a timezone, {op}ing will take place relative to the

pandas/core/arrays/datetimes.py

+35
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ def tz(self) -> tzinfo | None:
593593
datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
594594
Returns None when the array is tz-naive.
595595
596+
See Also
597+
--------
598+
DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a
599+
given time zone, or remove timezone from a tz-aware DatetimeIndex.
600+
DatetimeIndex.tz_convert : Convert tz-aware DatetimeIndex from
601+
one time zone to another.
602+
596603
Examples
597604
--------
598605
For Series:
@@ -1391,6 +1398,14 @@ def time(self) -> npt.NDArray[np.object_]:
13911398
13921399
The time part of the Timestamps.
13931400
1401+
See Also
1402+
--------
1403+
DatetimeIndex.timetz : Returns numpy array of :class:`datetime.time`
1404+
objects with timezones. The time part of the Timestamps.
1405+
DatetimeIndex.date : Returns numpy array of python :class:`datetime.date`
1406+
objects. Namely, the date part of Timestamps without time and timezone
1407+
information.
1408+
13941409
Examples
13951410
--------
13961411
For Series:
@@ -1428,6 +1443,12 @@ def timetz(self) -> npt.NDArray[np.object_]:
14281443
14291444
The time part of the Timestamps.
14301445
1446+
See Also
1447+
--------
1448+
DatetimeIndex.time : Returns numpy array of :class:`datetime.time` objects.
1449+
The time part of the Timestamps.
1450+
DatetimeIndex.tz : Return the timezone.
1451+
14311452
Examples
14321453
--------
14331454
For Series:
@@ -1462,6 +1483,14 @@ def date(self) -> npt.NDArray[np.object_]:
14621483
Namely, the date part of Timestamps without time and
14631484
timezone information.
14641485
1486+
See Also
1487+
--------
1488+
DatetimeIndex.time : Returns numpy array of :class:`datetime.time` objects.
1489+
The time part of the Timestamps.
1490+
DatetimeIndex.year : The year of the datetime.
1491+
DatetimeIndex.month : The month as January=1, December=12.
1492+
DatetimeIndex.day : The day of the datetime.
1493+
14651494
Examples
14661495
--------
14671496
For Series:
@@ -1836,6 +1865,12 @@ def isocalendar(self) -> DataFrame:
18361865
"""
18371866
The quarter of the date.
18381867
1868+
See Also
1869+
--------
1870+
DatetimeIndex.snap : Snap time stamps to nearest occurring frequency.
1871+
DatetimeIndex.time : Returns numpy array of datetime.time objects.
1872+
The time part of the Timestamps.
1873+
18391874
Examples
18401875
--------
18411876
For Series:

pandas/core/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ def nbytes(self) -> int:
419419
"""
420420
Return the number of bytes in the underlying data.
421421
422+
See Also
423+
--------
424+
Series.ndim : Number of dimensions of the underlying data.
425+
Series.size : Return the number of elements in the underlying data.
426+
422427
Examples
423428
--------
424429
For Series:

pandas/core/computation/ops.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
_unary_math_ops = (
4646
"sin",
4747
"cos",
48+
"tan",
4849
"exp",
4950
"log",
5051
"expm1",

pandas/core/frame.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -4012,7 +4012,6 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
40124012
return series._values[index]
40134013

40144014
series = self._get_item(col)
4015-
engine = self.index._engine
40164015

40174016
if not isinstance(self.index, MultiIndex):
40184017
# CategoricalIndex: Trying to use the engine fastpath may give incorrect
@@ -4023,7 +4022,7 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
40234022

40244023
# For MultiIndex going through engine effectively restricts us to
40254024
# same-length tuples; see test_get_set_value_no_partial_indexing
4026-
loc = engine.get_loc(index)
4025+
loc = self.index._engine.get_loc(index)
40274026
return series._values[loc]
40284027

40294028
def isetitem(self, loc, value) -> None:
@@ -5535,6 +5534,11 @@ def pop(self, item: Hashable) -> Series:
55355534
Series
55365535
Series representing the item that is dropped.
55375536
5537+
See Also
5538+
--------
5539+
DataFrame.drop: Drop specified labels from rows or columns.
5540+
DataFrame.drop_duplicates: Return DataFrame with duplicate rows removed.
5541+
55385542
Examples
55395543
--------
55405544
>>> df = pd.DataFrame(
@@ -12893,6 +12897,11 @@ def isin_(x):
1289312897
"""
1289412898
The column labels of the DataFrame.
1289512899
12900+
See Also
12901+
--------
12902+
DataFrame.index: The index (row labels) of the DataFrame.
12903+
DataFrame.axes: Return a list representing the axes of the DataFrame.
12904+
1289612905
Examples
1289712906
--------
1289812907
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
@@ -12921,12 +12930,12 @@ def _to_dict_of_blocks(self):
1292112930
Return a dict of dtype -> Constructor Types that
1292212931
each is a homogeneous dtype.
1292312932
12924-
Internal ONLY - only works for BlockManager
12933+
Internal ONLY.
1292512934
"""
1292612935
mgr = self._mgr
1292712936
return {
1292812937
k: self._constructor_from_mgr(v, axes=v.axes).__finalize__(self)
12929-
for k, v in mgr.to_dict().items()
12938+
for k, v in mgr.to_iter_dict()
1293012939
}
1293112940

1293212941
@property

pandas/core/generic.py

+11
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ def droplevel(self, level: IndexLabel, axis: Axis = 0) -> Self:
783783
{klass}
784784
{klass} with requested index / column level(s) removed.
785785
786+
See Also
787+
--------
788+
DataFrame.replace : Replace values given in `to_replace` with `value`.
789+
DataFrame.pivot : Return reshaped DataFrame organized by given
790+
index / column values.
791+
786792
Examples
787793
--------
788794
>>> df = (
@@ -1862,6 +1868,11 @@ def __iter__(self) -> Iterator:
18621868
iterator
18631869
Info axis as iterator.
18641870
1871+
See Also
1872+
--------
1873+
DataFrame.items : Iterate over (column name, Series) pairs.
1874+
DataFrame.itertuples : Iterate over DataFrame rows as namedtuples.
1875+
18651876
Examples
18661877
--------
18671878
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

pandas/core/indexers/objects.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ class BaseIndexer:
5353
>>> from pandas.api.indexers import BaseIndexer
5454
>>> class CustomIndexer(BaseIndexer):
5555
... def get_window_bounds(self, num_values, min_periods, center, closed, step):
56-
... start = np.empty(num_values, dtype=np.int64)
57-
... end = np.empty(num_values, dtype=np.int64)
58-
... for i in range(num_values):
59-
... start[i] = i
60-
... end[i] = i + self.window_size
56+
... start = np.arange(num_values, dtype=np.int64)
57+
... end = np.arange(num_values, dtype=np.int64) + self.window_size
6158
... return start, end
6259
>>> df = pd.DataFrame({"values": range(5)})
6360
>>> indexer = CustomIndexer(window_size=2)

0 commit comments

Comments
 (0)