Skip to content

Commit

Permalink
Merge branch 'main' into fix-59242
Browse files Browse the repository at this point in the history
  • Loading branch information
kastkeepitjumpinlikekangaroos authored Feb 9, 2025
2 parents bcb7e3d + e557039 commit fe52a7a
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 26 deletions.
2 changes: 1 addition & 1 deletion doc/source/user_guide/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ You can also include the grouping columns if you want to operate on them.
.. note::

The ``groupby`` operation in Pandas drops the ``name`` field of the columns Index object
The ``groupby`` operation in pandas drops the ``name`` field of the columns Index object
after the operation. This change ensures consistency in syntax between different
column selection methods within groupby operations.

Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ Thousand separators

For large numbers that have been written with a thousands separator, you can
set the ``thousands`` keyword to a string of length 1 so that integers will be parsed
correctly:
correctly.

By default, numbers with a thousands separator will be parsed as strings:

Expand Down
4 changes: 2 additions & 2 deletions doc/source/user_guide/merging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ A string argument to ``indicator`` will use the value as the name for the indica
Overlapping value columns
~~~~~~~~~~~~~~~~~~~~~~~~~

The merge ``suffixes`` argument takes a tuple of list of strings to append to
The merge ``suffixes`` argument takes a tuple or list of strings to append to
overlapping column names in the input :class:`DataFrame` to disambiguate the result
columns:

Expand Down Expand Up @@ -979,7 +979,7 @@ nearest key rather than equal keys. For each row in the ``left`` :class:`DataFra
the last row in the ``right`` :class:`DataFrame` are selected where the ``on`` key is less
than the left's key. Both :class:`DataFrame` must be sorted by the key.

Optionally an :func:`merge_asof` can perform a group-wise merge by matching the
Optionally :func:`merge_asof` can perform a group-wise merge by matching the
``by`` key in addition to the nearest match on the ``on`` key.

.. ipython:: python
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/scale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Scaling to large datasets
*************************

pandas provides data structures for in-memory analytics, which makes using pandas
to analyze datasets that are larger than memory datasets somewhat tricky. Even datasets
to analyze datasets that are larger than memory somewhat tricky. Even datasets
that are a sizable fraction of memory become unwieldy, as some pandas operations need
to make intermediate copies.

Expand Down
4 changes: 2 additions & 2 deletions doc/source/user_guide/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ the pandas objects.
ts = ts[:5]
ts.shift(1)
The ``shift`` method accepts an ``freq`` argument which can accept a
The ``shift`` method accepts a ``freq`` argument which can accept a
``DateOffset`` class or other ``timedelta``-like object or also an
:ref:`offset alias <timeseries.offset_aliases>`.

Expand Down Expand Up @@ -2570,7 +2570,7 @@ because daylight savings time (DST) in a local time zone causes some times to oc
twice within one day ("clocks fall back"). The following options are available:

* ``'raise'``: Raises a ``ValueError`` (the default behavior)
* ``'infer'``: Attempt to determine the correct offset base on the monotonicity of the timestamps
* ``'infer'``: Attempt to determine the correct offset based on the monotonicity of the timestamps
* ``'NaT'``: Replaces ambiguous times with ``NaT``
* ``bool``: ``True`` represents a DST time, ``False`` represents non-DST time. An array-like of ``bool`` values is supported for a sequence of times.

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ Styler
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 :class:`Series` ignoring errors when trying to convert :class:`Series` input data to the given ``dtype`` (:issue:`60728`)
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
Expand Down
5 changes: 5 additions & 0 deletions pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def option_context(*args) -> Generator[None]:
"""
Context manager to temporarily set options in a ``with`` statement.
This method allows users to set one or more pandas options temporarily
within a controlled block. The previous options' values are restored
once the block is exited. This is useful when making temporary adjustments
to pandas' behavior without affecting the global state.
Parameters
----------
*args : str | object
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,11 @@ class Period(_Period):
"""
Represents a period of time.
A `Period` represents a specific time span rather than a point in time.
Unlike `Timestamp`, which represents a single instant, a `Period` defines a
duration, such as a month, quarter, or year. The exact representation is
determined by the `freq` parameter.
Parameters
----------
value : Period, str, datetime, date or pandas.Timestamp, default None
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def array(
"""
Create an array.
This method constructs an array using pandas extension types when possible.
If `dtype` is specified, it determines the type of array returned. Otherwise,
pandas attempts to infer the appropriate dtype based on `data`.
Parameters
----------
data : Sequence of objects
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ def shape(self) -> tuple[int, int]:
"""
Return a tuple representing the dimensionality of the DataFrame.
Unlike the `len()` method, which only returns the number of rows, `shape`
provides both row and column counts, making it a more informative method for
understanding dataset size.
See Also
--------
numpy.ndarray.shape : Tuple of array dimensions.
Expand Down
19 changes: 10 additions & 9 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3659,10 +3659,10 @@ def rolling(
Parameters
----------
window : int, timedelta, str, offset, or BaseIndexer subclass
Size of the moving window.
Interval of the moving window.
If an integer, the fixed number of observations used for
each window.
If an integer, the delta between the start and end of each window.
The number of points in the window depends on the ``closed`` argument.
If a timedelta, str, or offset, the time period of each window. Each
window will be a variable sized based on the observations included in
Expand Down Expand Up @@ -3709,17 +3709,18 @@ def rolling(
closed : str, default None
Determines the inclusivity of points in the window
If ``'right'``, (First, Last] the last point in the window
If ``'right'``, uses the window (first, last] meaning the last point
is included in the calculations.
If ``'left'``, [First, Last) the first point in the window
If ``'left'``, uses the window [first, last) meaning the first point
is included in the calculations.
If ``'both'``, [First, Last] all points in the window
are included in the calculations.
If ``'both'``, uses the window [first, last] meaning all points in
the window are included in the calculations.
If ``'neither'``, (First, Last) the first and last points
in the window are excludedfrom calculations.
If ``'neither'``, uses the window (first, last) meaning the first
and last points in the window are excluded from calculations.
() and [] are referencing open and closed set
notation respetively.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def __init__(
# create/copy the manager
if isinstance(data, SingleBlockManager):
if dtype is not None:
data = data.astype(dtype=dtype, errors="ignore")
data = data.astype(dtype=dtype)
elif copy:
data = data.copy()
else:
Expand Down
19 changes: 10 additions & 9 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,10 @@ class Window(BaseWindow):
Parameters
----------
window : int, timedelta, str, offset, or BaseIndexer subclass
Size of the moving window.
Interval of the moving window.
If an integer, the fixed number of observations used for
each window.
If an integer, the delta between the start and end of each window.
The number of points in the window depends on the ``closed`` argument.
If a timedelta, str, or offset, the time period of each window. Each
window will be a variable sized based on the observations included in
Expand Down Expand Up @@ -930,17 +930,18 @@ class Window(BaseWindow):
closed : str, default None
Determines the inclusivity of points in the window
If ``'right'``, (First, Last] the last point in the window
If ``'right'``, uses the window (first, last] meaning the last point
is included in the calculations.
If ``'left'``, [First, Last) the first point in the window
If ``'left'``, uses the window [first, last) meaning the first point
is included in the calculations.
If ``'both'``, [First, Last] all points in the window
are included in the calculations.
If ``'both'``, uses the window [first, last] meaning all points in
the window are included in the calculations.
If ``'neither'``, (First, Last) the first and last points
in the window are excludedfrom calculations.
If ``'neither'``, uses the window (first, last) meaning the first
and last points in the window are excluded from calculations.
() and [] are referencing open and closed set
notation respetively.
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def test_unparsable_strings_with_dt64_dtype(self):
with pytest.raises(ValueError, match=msg):
Series(np.array(vals, dtype=object), dtype="datetime64[ns]")

def test_invalid_dtype_conversion_datetime_to_timedelta(self):
# GH#60728
vals = Series([NaT, Timestamp(2025, 1, 1)], dtype="datetime64[ns]")
msg = r"^Cannot cast DatetimeArray to dtype timedelta64\[ns\]$"
with pytest.raises(TypeError, match=msg):
Series(vals, dtype="timedelta64[ns]")

@pytest.mark.parametrize(
"constructor",
[
Expand Down

0 comments on commit fe52a7a

Please sign in to comment.