Skip to content

Commit

Permalink
Merge branch 'main' into fix/as_index_false_returns_multiindex
Browse files Browse the repository at this point in the history
  • Loading branch information
undermyumbrella1 authored Apr 23, 2024
2 parents 52fb291 + 23dd1f1 commit f386f6a
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 121 deletions.
42 changes: 4 additions & 38 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.CategoricalIndex.codes SA01" \
-i "pandas.CategoricalIndex.ordered SA01" \
-i "pandas.DataFrame.__dataframe__ SA01" \
-i "pandas.DataFrame.__iter__ SA01" \
-i "pandas.DataFrame.at_time PR01" \
-i "pandas.DataFrame.columns SA01" \
-i "pandas.DataFrame.droplevel SA01" \
-i "pandas.DataFrame.hist RT03" \
-i "pandas.DataFrame.infer_objects RT03" \
-i "pandas.DataFrame.kurt RT03,SA01" \
Expand All @@ -93,7 +90,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.DataFrame.median RT03,SA01" \
-i "pandas.DataFrame.min RT03" \
-i "pandas.DataFrame.plot PR02,SA01" \
-i "pandas.DataFrame.pop SA01" \
-i "pandas.DataFrame.prod RT03" \
-i "pandas.DataFrame.product RT03" \
-i "pandas.DataFrame.reorder_levels SA01" \
Expand All @@ -103,71 +99,51 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.DataFrame.std PR01,RT03,SA01" \
-i "pandas.DataFrame.sum RT03" \
-i "pandas.DataFrame.swaplevel SA01" \
-i "pandas.DataFrame.to_feather SA01" \
-i "pandas.DataFrame.to_markdown SA01" \
-i "pandas.DataFrame.to_parquet RT03" \
-i "pandas.DataFrame.var PR01,RT03,SA01" \
-i "pandas.DatetimeIndex.ceil SA01" \
-i "pandas.DatetimeIndex.date SA01" \
-i "pandas.DatetimeIndex.day_of_year SA01" \
-i "pandas.DatetimeIndex.dayofyear SA01" \
-i "pandas.DatetimeIndex.floor SA01" \
-i "pandas.DatetimeIndex.freqstr SA01" \
-i "pandas.DatetimeIndex.indexer_at_time PR01,RT03" \
-i "pandas.DatetimeIndex.indexer_between_time RT03" \
-i "pandas.DatetimeIndex.inferred_freq SA01" \
-i "pandas.DatetimeIndex.is_leap_year SA01" \
-i "pandas.DatetimeIndex.quarter SA01" \
-i "pandas.DatetimeIndex.round SA01" \
-i "pandas.DatetimeIndex.snap PR01,RT03,SA01" \
-i "pandas.DatetimeIndex.snap PR01,RT03" \
-i "pandas.DatetimeIndex.std PR01,RT03" \
-i "pandas.DatetimeIndex.time SA01" \
-i "pandas.DatetimeIndex.timetz SA01" \
-i "pandas.DatetimeIndex.to_period RT03" \
-i "pandas.DatetimeIndex.to_pydatetime RT03,SA01" \
-i "pandas.DatetimeIndex.tz SA01" \
-i "pandas.DatetimeIndex.tz_convert RT03" \
-i "pandas.DatetimeTZDtype SA01" \
-i "pandas.DatetimeTZDtype.tz SA01" \
-i "pandas.DatetimeTZDtype.unit SA01" \
-i "pandas.Grouper PR02" \
-i "pandas.HDFStore.info RT03,SA01" \
-i "pandas.HDFStore.keys SA01" \
-i "pandas.HDFStore.put PR01,SA01" \
-i "pandas.HDFStore.select SA01" \
-i "pandas.HDFStore.walk SA01" \
-i "pandas.Index PR07" \
-i "pandas.Index.T SA01" \
-i "pandas.Index.append PR07,RT03,SA01" \
-i "pandas.Index.astype SA01" \
-i "pandas.Index.copy PR07,SA01" \
-i "pandas.Index.difference PR07,RT03,SA01" \
-i "pandas.Index.drop PR07,SA01" \
-i "pandas.Index.drop_duplicates RT03" \
-i "pandas.Index.droplevel RT03,SA01" \
-i "pandas.Index.dropna RT03,SA01" \
-i "pandas.Index.dtype SA01" \
-i "pandas.Index.duplicated RT03" \
-i "pandas.Index.empty GL08" \
-i "pandas.Index.equals SA01" \
-i "pandas.Index.fillna RT03" \
-i "pandas.Index.get_indexer PR07,SA01" \
-i "pandas.Index.get_indexer_for PR01,SA01" \
-i "pandas.Index.get_indexer_non_unique PR07,SA01" \
-i "pandas.Index.get_loc PR07,RT03,SA01" \
-i "pandas.Index.get_slice_bound PR07" \
-i "pandas.Index.hasnans SA01" \
-i "pandas.Index.identical PR01,SA01" \
-i "pandas.Index.inferred_type SA01" \
-i "pandas.Index.insert PR07,RT03,SA01" \
-i "pandas.Index.intersection PR07,RT03,SA01" \
-i "pandas.Index.item SA01" \
-i "pandas.Index.join PR07,RT03,SA01" \
-i "pandas.Index.map SA01" \
-i "pandas.Index.memory_usage RT03" \
-i "pandas.Index.name SA01" \
-i "pandas.Index.names GL08" \
-i "pandas.Index.nbytes SA01" \
-i "pandas.Index.nunique RT03" \
-i "pandas.Index.putmask PR01,RT03" \
-i "pandas.Index.ravel PR01,RT03" \
Expand Down Expand Up @@ -287,34 +263,28 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.cat.reorder_categories PR01,PR02" \
-i "pandas.Series.cat.set_categories PR01,PR02" \
-i "pandas.Series.div PR07" \
-i "pandas.Series.droplevel SA01" \
-i "pandas.Series.dt.as_unit PR01,PR02" \
-i "pandas.Series.dt.ceil PR01,PR02,SA01" \
-i "pandas.Series.dt.ceil PR01,PR02" \
-i "pandas.Series.dt.components SA01" \
-i "pandas.Series.dt.date SA01" \
-i "pandas.Series.dt.day_name PR01,PR02" \
-i "pandas.Series.dt.day_of_year SA01" \
-i "pandas.Series.dt.dayofyear SA01" \
-i "pandas.Series.dt.days SA01" \
-i "pandas.Series.dt.days_in_month SA01" \
-i "pandas.Series.dt.daysinmonth SA01" \
-i "pandas.Series.dt.floor PR01,PR02,SA01" \
-i "pandas.Series.dt.floor PR01,PR02" \
-i "pandas.Series.dt.freq GL08" \
-i "pandas.Series.dt.is_leap_year SA01" \
-i "pandas.Series.dt.microseconds SA01" \
-i "pandas.Series.dt.month_name PR01,PR02" \
-i "pandas.Series.dt.nanoseconds SA01" \
-i "pandas.Series.dt.normalize PR01" \
-i "pandas.Series.dt.quarter SA01" \
-i "pandas.Series.dt.qyear GL08" \
-i "pandas.Series.dt.round PR01,PR02,SA01" \
-i "pandas.Series.dt.round PR01,PR02" \
-i "pandas.Series.dt.seconds SA01" \
-i "pandas.Series.dt.strftime PR01,PR02" \
-i "pandas.Series.dt.time SA01" \
-i "pandas.Series.dt.timetz SA01" \
-i "pandas.Series.dt.to_period PR01,PR02,RT03" \
-i "pandas.Series.dt.total_seconds PR01" \
-i "pandas.Series.dt.tz SA01" \
-i "pandas.Series.dt.tz_convert PR01,PR02,RT03" \
-i "pandas.Series.dt.tz_localize PR01,PR02" \
-i "pandas.Series.dt.unit GL08" \
Expand Down Expand Up @@ -344,7 +314,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.mod PR07" \
-i "pandas.Series.mode SA01" \
-i "pandas.Series.mul PR07" \
-i "pandas.Series.nbytes SA01" \
-i "pandas.Series.ne PR07,SA01" \
-i "pandas.Series.nunique RT03" \
-i "pandas.Series.pad PR01,SA01" \
Expand Down Expand Up @@ -432,14 +401,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Timedelta.total_seconds SA01" \
-i "pandas.Timedelta.view SA01" \
-i "pandas.TimedeltaIndex.as_unit RT03,SA01" \
-i "pandas.TimedeltaIndex.ceil SA01" \
-i "pandas.TimedeltaIndex.components SA01" \
-i "pandas.TimedeltaIndex.days SA01" \
-i "pandas.TimedeltaIndex.floor SA01" \
-i "pandas.TimedeltaIndex.inferred_freq SA01" \
-i "pandas.TimedeltaIndex.microseconds SA01" \
-i "pandas.TimedeltaIndex.nanoseconds SA01" \
-i "pandas.TimedeltaIndex.round SA01" \
-i "pandas.TimedeltaIndex.seconds SA01" \
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
-i "pandas.Timestamp PR07,SA01" \
Expand Down
2 changes: 2 additions & 0 deletions doc/source/development/community.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ The pandas mailing list `[email protected] <mailto://pandas-dev@python
conversations and to engage people in the wider community who might not
be active on the issue tracker but we would like to include in discussions.

Join the mailing list and view the archives `here <https://mail.python.org/mailman/listinfo/pandas-dev>`_.

.. _community.slack:

Community slack
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@
"- Provide an API that is pleasing to use interactively and is \"good enough\" for many tasks\n",
"- Provide the foundations for dedicated libraries to build on\n",
"\n",
"If you build a great library on top of this, let us know and we'll [link](https://pandas.pydata.org/pandas-docs/stable/ecosystem.html) to it.\n",
"If you build a great library on top of this, let us know and we'll [link](https://pandas.pydata.org/community/ecosystem.html) to it.\n",
"\n",
"### Subclassing\n",
"\n",
Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Other Deprecations
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.all`, :meth:`DataFrame.min`, :meth:`DataFrame.max`, :meth:`DataFrame.sum`, :meth:`DataFrame.prod`, :meth:`DataFrame.mean`, :meth:`DataFrame.median`, :meth:`DataFrame.sem`, :meth:`DataFrame.var`, :meth:`DataFrame.std`, :meth:`DataFrame.skew`, :meth:`DataFrame.kurt`, :meth:`Series.all`, :meth:`Series.min`, :meth:`Series.max`, :meth:`Series.sum`, :meth:`Series.prod`, :meth:`Series.mean`, :meth:`Series.median`, :meth:`Series.sem`, :meth:`Series.var`, :meth:`Series.std`, :meth:`Series.skew`, and :meth:`Series.kurt`. (:issue:`57087`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
- Deprecated behavior of :meth:`Series.dt.to_pytimedelta`, in a future version this will return a :class:`Series` containing python ``datetime.timedelta`` objects instead of an ``ndarray`` of timedelta; this matches the behavior of other :meth:`Series.dt` properties. (:issue:`57463`)
- Deprecated using ``epoch`` date format in :meth:`DataFrame.to_json` and :meth:`Series.to_json`, use ``iso`` instead. (:issue:`57063`)
-

Expand Down Expand Up @@ -360,6 +361,7 @@ Datetimelike
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or :class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)

Timedelta
^^^^^^^^^
Expand Down Expand Up @@ -458,6 +460,7 @@ Other
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
- 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`)
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
- 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`)
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
- 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`)
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def has_infs(const floating[:] arr) -> bool:

@cython.boundscheck(False)
@cython.wraparound(False)
def has_only_ints_or_nan(floating[:] arr) -> bool:
def has_only_ints_or_nan(const floating[:] arr) -> bool:
cdef:
floating val
intp_t i
Expand Down Expand Up @@ -631,7 +631,7 @@ ctypedef fused int6432_t:

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

@cython.wraparound(False)
@cython.boundscheck(False)
def is_sequence_range(ndarray[int6432_t, ndim=1] sequence, int64_t step) -> bool:
def is_sequence_range(const int6432_t[:] sequence, int64_t step) -> bool:
"""
Check if sequence is equivalent to a range with the specified step.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/reshape.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ from pandas._libs.lib cimport c_is_list_like

@cython.wraparound(False)
@cython.boundscheck(False)
def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,
def unstack(const numeric_object_t[:, :] values, const uint8_t[:] mask,
Py_ssize_t stride, Py_ssize_t length, Py_ssize_t width,
numeric_object_t[:, :] new_values, uint8_t[:, :] new_mask) -> None:
"""
Expand Down Expand Up @@ -80,7 +80,7 @@ def unstack(numeric_object_t[:, :] values, const uint8_t[:] mask,

@cython.wraparound(False)
@cython.boundscheck(False)
def explode(ndarray[object] values):
def explode(object[:] values):
"""
transform array list-likes to long form
preserve non-list entries
Expand Down
1 change: 1 addition & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def pytest_collection_modifyitems(items, config) -> None:
("SeriesGroupBy.fillna", "SeriesGroupBy.fillna is deprecated"),
("SeriesGroupBy.idxmin", "The behavior of Series.idxmin"),
("SeriesGroupBy.idxmax", "The behavior of Series.idxmax"),
("to_pytimedelta", "The behavior of TimedeltaProperties.to_pytimedelta"),
# Docstring divides by zero to show behavior difference
("missing.mask_zero_div_zero", "divide by zero encountered"),
(
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,11 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
------
ValueError if the `freq` cannot be converted.
See Also
--------
DatetimeIndex.floor : Perform floor operation on the data to the specified `freq`.
DatetimeIndex.snap : Snap time stamps to nearest occurring frequency.
Notes
-----
If the timestamps have a timezone, {op}ing will take place relative to the
Expand Down
37 changes: 36 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def _unbox_scalar(self, value) -> np.datetime64:
if value is NaT:
return np.datetime64(value._value, self.unit)
else:
return value.as_unit(self.unit).asm8
return value.as_unit(self.unit, round_ok=False).asm8

def _scalar_from_string(self, value) -> Timestamp | NaTType:
return Timestamp(value, tz=self.tz)
Expand Down Expand Up @@ -593,6 +593,13 @@ def tz(self) -> tzinfo | None:
datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
Returns None when the array is tz-naive.
See Also
--------
DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a
given time zone, or remove timezone from a tz-aware DatetimeIndex.
DatetimeIndex.tz_convert : Convert tz-aware DatetimeIndex from
one time zone to another.
Examples
--------
For Series:
Expand Down Expand Up @@ -1391,6 +1398,14 @@ def time(self) -> npt.NDArray[np.object_]:
The time part of the Timestamps.
See Also
--------
DatetimeIndex.timetz : Returns numpy array of :class:`datetime.time`
objects with timezones. The time part of the Timestamps.
DatetimeIndex.date : Returns numpy array of python :class:`datetime.date`
objects. Namely, the date part of Timestamps without time and timezone
information.
Examples
--------
For Series:
Expand Down Expand Up @@ -1428,6 +1443,12 @@ def timetz(self) -> npt.NDArray[np.object_]:
The time part of the Timestamps.
See Also
--------
DatetimeIndex.time : Returns numpy array of :class:`datetime.time` objects.
The time part of the Timestamps.
DatetimeIndex.tz : Return the timezone.
Examples
--------
For Series:
Expand Down Expand Up @@ -1462,6 +1483,14 @@ def date(self) -> npt.NDArray[np.object_]:
Namely, the date part of Timestamps without time and
timezone information.
See Also
--------
DatetimeIndex.time : Returns numpy array of :class:`datetime.time` objects.
The time part of the Timestamps.
DatetimeIndex.year : The year of the datetime.
DatetimeIndex.month : The month as January=1, December=12.
DatetimeIndex.day : The day of the datetime.
Examples
--------
For Series:
Expand Down Expand Up @@ -1836,6 +1865,12 @@ def isocalendar(self) -> DataFrame:
"""
The quarter of the date.
See Also
--------
DatetimeIndex.snap : Snap time stamps to nearest occurring frequency.
DatetimeIndex.time : Returns numpy array of datetime.time objects.
The time part of the Timestamps.
Examples
--------
For Series:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _unbox_scalar(self, value) -> np.timedelta64:
if value is NaT:
return np.timedelta64(value._value, self.unit)
else:
return value.as_unit(self.unit).asm8
return value.as_unit(self.unit, round_ok=False).asm8

def _scalar_from_string(self, value) -> Timedelta | NaTType:
return Timedelta(value)
Expand Down
5 changes: 5 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ def nbytes(self) -> int:
"""
Return the number of bytes in the underlying data.
See Also
--------
Series.ndim : Number of dimensions of the underlying data.
Series.size : Return the number of elements in the underlying data.
Examples
--------
For Series:
Expand Down
1 change: 1 addition & 0 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
_unary_math_ops = (
"sin",
"cos",
"tan",
"exp",
"log",
"expm1",
Expand Down
Loading

0 comments on commit f386f6a

Please sign in to comment.