Skip to content

Commit 3e26a62

Browse files
authored
Merge branch 'main' into add-warning-timestamp-blank-string
2 parents 6d81c60 + 5736b96 commit 3e26a62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+392
-436
lines changed

Diff for: .github/CODEOWNERS

-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ doc/source/development @noatamir
1010

1111
# pandas
1212
pandas/_libs/ @WillAyd
13-
pandas/_libs/tslibs/* @MarcoGorelli
1413
pandas/_typing.py @Dr-Irv
1514
pandas/core/groupby/* @rhshadrach
16-
pandas/core/tools/datetimes.py @MarcoGorelli
1715
pandas/io/excel/* @rhshadrach
1816
pandas/io/formats/style.py @attack68
1917
pandas/io/formats/style_render.py @attack68

Diff for: .github/workflows/wheels.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
run: echo "sdist_name=$(cd ./dist && ls -d */)" >> "$GITHUB_ENV"
154154

155155
- name: Build wheels
156-
uses: pypa/[email protected].1
156+
uses: pypa/[email protected].2
157157
with:
158158
package-dir: ./dist/${{ startsWith(matrix.buildplat[1], 'macosx') && env.sdist_name || needs.build_sdist.outputs.sdist_file }}
159159
env:

Diff for: asv_bench/benchmarks/indexing_engines.py

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class NumericEngineIndexing:
6767
def setup(self, engine_and_dtype, index_type, unique, N):
6868
engine, dtype = engine_and_dtype
6969

70+
if (
71+
index_type == "non_monotonic"
72+
and dtype in [np.int16, np.int8, np.uint8]
73+
and unique
74+
):
75+
# Values overflow
76+
raise NotImplementedError
77+
7078
if index_type == "monotonic_incr":
7179
if unique:
7280
arr = np.arange(N * 3, dtype=dtype)
@@ -115,6 +123,14 @@ def setup(self, engine_and_dtype, index_type, unique, N):
115123
engine, dtype = engine_and_dtype
116124
dtype = dtype.lower()
117125

126+
if (
127+
index_type == "non_monotonic"
128+
and dtype in ["int16", "int8", "uint8"]
129+
and unique
130+
):
131+
# Values overflow
132+
raise NotImplementedError
133+
118134
if index_type == "monotonic_incr":
119135
if unique:
120136
arr = np.arange(N * 3, dtype=dtype)

Diff for: ci/meta.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,3 @@ extra:
8989
- datapythonista
9090
- phofl
9191
- lithomas1
92-
- marcogorelli

Diff for: doc/source/development/debugging_extensions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ By default building pandas from source will generate a release build. To generat
2323

2424
.. note::
2525

26-
conda environments update CFLAGS/CPPFLAGS with flags that are geared towards generating releases. If using conda, you may need to set ``CFLAGS="$CFLAGS -O0"`` and ``CPPFLAGS="$CPPFLAGS -O0"`` to ensure optimizations are turned off for debugging
26+
conda environments update CFLAGS/CPPFLAGS with flags that are geared towards generating releases, and may work counter towards usage in a development environment. If using conda, you should unset these environment variables via ``export CFLAGS=`` and ``export CPPFLAGS=``
2727

2828
By specifying ``builddir="debug"`` all of the targets will be built and placed in the debug directory relative to the project root. This helps to keep your debug and release artifacts separate; you are of course able to choose a different directory name or omit altogether if you do not care to separate build types.
2929

Diff for: doc/source/getting_started/comparison/comparison_with_r.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ In Python, since ``a`` is a list, you can simply use list comprehension.
383383

384384
.. ipython:: python
385385
386-
a = np.array(list(range(1, 24)) + [np.NAN]).reshape(2, 3, 4)
386+
a = np.array(list(range(1, 24)) + [np.nan]).reshape(2, 3, 4)
387387
pd.DataFrame([tuple(list(x) + [val]) for x, val in np.ndenumerate(a)])
388388
389389
meltlist
@@ -402,7 +402,7 @@ In Python, this list would be a list of tuples, so
402402

403403
.. ipython:: python
404404
405-
a = list(enumerate(list(range(1, 5)) + [np.NAN]))
405+
a = list(enumerate(list(range(1, 5)) + [np.nan]))
406406
pd.DataFrame(a)
407407
408408
For more details and examples see :ref:`the Intro to Data Structures

Diff for: doc/source/user_guide/basics.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ of elements to display is five, but you may pass a custom number.
3636
Attributes and underlying data
3737
------------------------------
3838

39-
pandas objects have a number of attributes enabling you to access the metadata
39+
pandas objects have a number of attributes enabling you to access the metadata.
4040

4141
* **shape**: gives the axis dimensions of the object, consistent with ndarray
4242
* Axis labels
@@ -59,7 +59,7 @@ NumPy's type system to add support for custom arrays
5959
(see :ref:`basics.dtypes`).
6060

6161
To get the actual data inside a :class:`Index` or :class:`Series`, use
62-
the ``.array`` property
62+
the ``.array`` property.
6363

6464
.. ipython:: python
6565
@@ -88,18 +88,18 @@ NumPy doesn't have a dtype to represent timezone-aware datetimes, so there
8888
are two possibly useful representations:
8989

9090
1. An object-dtype :class:`numpy.ndarray` with :class:`Timestamp` objects, each
91-
with the correct ``tz``
91+
with the correct ``tz``.
9292
2. A ``datetime64[ns]`` -dtype :class:`numpy.ndarray`, where the values have
93-
been converted to UTC and the timezone discarded
93+
been converted to UTC and the timezone discarded.
9494

95-
Timezones may be preserved with ``dtype=object``
95+
Timezones may be preserved with ``dtype=object``:
9696

9797
.. ipython:: python
9898
9999
ser = pd.Series(pd.date_range("2000", periods=2, tz="CET"))
100100
ser.to_numpy(dtype=object)
101101
102-
Or thrown away with ``dtype='datetime64[ns]'``
102+
Or thrown away with ``dtype='datetime64[ns]'``:
103103

104104
.. ipython:: python
105105
@@ -2064,12 +2064,12 @@ different numeric dtypes will **NOT** be combined. The following example will gi
20642064

20652065
.. ipython:: python
20662066
2067-
df1 = pd.DataFrame(np.random.randn(8, 1), columns=["A"], dtype="float32")
2067+
df1 = pd.DataFrame(np.random.randn(8, 1), columns=["A"], dtype="float64")
20682068
df1
20692069
df1.dtypes
20702070
df2 = pd.DataFrame(
20712071
{
2072-
"A": pd.Series(np.random.randn(8), dtype="float16"),
2072+
"A": pd.Series(np.random.randn(8), dtype="float32"),
20732073
"B": pd.Series(np.random.randn(8)),
20742074
"C": pd.Series(np.random.randint(0, 255, size=8), dtype="uint8"), # [0,255] (range of uint8)
20752075
}

Diff for: doc/source/user_guide/enhancingperf.rst

+2
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ can be improved by passing an ``np.ndarray``.
171171
In [4]: %%cython
172172
...: cimport numpy as np
173173
...: import numpy as np
174+
...: np.import_array()
174175
...: cdef double f_typed(double x) except? -2:
175176
...: return x * (x - 1)
176177
...: cpdef double integrate_f_typed(double a, double b, int N):
@@ -225,6 +226,7 @@ and ``wraparound`` checks can yield more performance.
225226
...: cimport cython
226227
...: cimport numpy as np
227228
...: import numpy as np
229+
...: np.import_array()
228230
...: cdef np.float64_t f_typed(np.float64_t x) except? -2:
229231
...: return x * (x - 1)
230232
...: cpdef np.float64_t integrate_f_typed(np.float64_t a, np.float64_t b, np.int64_t N):

Diff for: doc/source/whatsnew/v0.11.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ Numeric dtypes will propagate and can coexist in DataFrames. If a dtype is passe
7474

7575
.. ipython:: python
7676
77-
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float32')
77+
df1 = pd.DataFrame(np.random.randn(8, 1), columns=['A'], dtype='float64')
7878
df1
7979
df1.dtypes
80-
df2 = pd.DataFrame({'A': pd.Series(np.random.randn(8), dtype='float16'),
80+
df2 = pd.DataFrame({'A': pd.Series(np.random.randn(8), dtype='float32'),
8181
'B': pd.Series(np.random.randn(8)),
8282
'C': pd.Series(range(8), dtype='uint8')})
8383
df2

Diff for: doc/source/whatsnew/v3.0.0.rst

+5
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ Timezones
674674

675675
Numeric
676676
^^^^^^^
677+
- Bug in :meth:`DataFrame.corr` where numerical precision errors resulted in correlations above ``1.0`` (:issue:`61120`)
677678
- Bug in :meth:`DataFrame.quantile` where the column type was not preserved when ``numeric_only=True`` with a list-like ``q`` produced an empty result (:issue:`59035`)
678679
- Bug in ``np.matmul`` with :class:`Index` inputs raising a ``TypeError`` (:issue:`57079`)
679680

@@ -773,6 +774,7 @@ Groupby/resample/rolling
773774
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
774775
- Bug in :meth:`.Resampler.interpolate` on a :class:`DataFrame` with non-uniform sampling and/or indices not aligning with the resulting resampled index would result in wrong interpolation (:issue:`21351`)
775776
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
777+
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
776778
- Bug in :meth:`DataFrameGroupBy.agg` that raises ``AttributeError`` when there is dictionary input and duplicated columns, instead of returning a DataFrame with the aggregation of all duplicate columns. (:issue:`55041`)
777779
- Bug in :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` for empty data frame with ``group_keys=False`` still creating output index using group keys. (:issue:`60471`)
778780
- Bug in :meth:`DataFrameGroupBy.apply` that was returning a completely empty DataFrame when all return values of ``func`` were ``None`` instead of returning an empty DataFrame with the original columns and dtypes. (:issue:`57775`)
@@ -824,6 +826,7 @@ Other
824826
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
825827
- Bug in :class:`Series` ignoring errors when trying to convert :class:`Series` input data to the given ``dtype`` (:issue:`60728`)
826828
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
829+
- Bug in :func:`eval` where method calls on binary operations like ``(x + y).dropna()`` would raise ``AttributeError: 'BinOp' object has no attribute 'value'`` (:issue:`61175`)
827830
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
828831
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
829832
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
@@ -833,12 +836,14 @@ Other
833836
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
834837
- Bug in :meth:`DataFrame.query` where using duplicate column names led to a ``TypeError``. (:issue:`59950`)
835838
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
839+
- Bug in :meth:`DataFrame.query` which raised an exception when querying integer column names using backticks. (:issue:`60494`)
836840
- Bug in :meth:`DataFrame.shift` where passing a ``freq`` on a DataFrame with no columns did not shift the index correctly. (:issue:`60102`)
837841
- 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`)
838842
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
839843
- 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`)
840844
- Bug in :meth:`Index.sort_values` when passing a key function that turns values into tuples, e.g. ``key=natsort.natsort_key``, would raise ``TypeError`` (:issue:`56081`)
841845
- Bug in :meth:`MultiIndex.fillna` error message was referring to ``isna`` instead of ``fillna`` (:issue:`60974`)
846+
- Bug in :meth:`Series.describe` where median percentile was always included when the ``percentiles`` argument was passed (:issue:`60550`).
842847
- Bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`)
843848
- Bug in :meth:`Series.dt` methods in :class:`ArrowDtype` that were returning incorrect values. (:issue:`57355`)
844849
- Bug in :meth:`Series.isin` raising ``TypeError`` when series is large (>10**6) and ``values`` contains NA (:issue:`60678`)

Diff for: environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323

2424
# required dependencies
2525
- python-dateutil
26-
- numpy<2
26+
- numpy<3
2727

2828
# optional dependencies
2929
- beautifulsoup4>=4.11.2

Diff for: pandas/_libs/algos.pyx

+9-3
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,9 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
353353
float64_t[:, ::1] result
354354
uint8_t[:, :] mask
355355
int64_t nobs = 0
356-
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy
356+
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy, val
357357

358358
N, K = (<object>mat).shape
359-
360359
if minp is None:
361360
minpv = 1
362361
else:
@@ -389,8 +388,15 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
389388
else:
390389
divisor = (nobs - 1.0) if cov else sqrt(ssqdmx * ssqdmy)
391390

391+
# clip `covxy / divisor` to ensure coeff is within bounds
392392
if divisor != 0:
393-
result[xi, yi] = result[yi, xi] = covxy / divisor
393+
val = covxy / divisor
394+
if not cov:
395+
if val > 1.0:
396+
val = 1.0
397+
elif val < -1.0:
398+
val = -1.0
399+
result[xi, yi] = result[yi, xi] = val
394400
else:
395401
result[xi, yi] = result[yi, xi] = NaN
396402

Diff for: pandas/_libs/tslibs/period.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1752,9 +1752,6 @@ cdef class _Period(PeriodMixin):
17521752
def __cinit__(self, int64_t ordinal, BaseOffset freq):
17531753
self.ordinal = ordinal
17541754
self.freq = freq
1755-
# Note: this is more performant than PeriodDtype.from_date_offset(freq)
1756-
# because from_date_offset cannot be made a cdef method (until cython
1757-
# supported cdef classmethods)
17581755
self._dtype = PeriodDtypeBase(freq._period_dtype_code, freq.n)
17591756

17601757
@classmethod
@@ -1913,7 +1910,7 @@ cdef class _Period(PeriodMixin):
19131910

19141911
Parameters
19151912
----------
1916-
freq : str, BaseOffset
1913+
freq : str, DateOffset
19171914
The target frequency to convert the Period object to.
19181915
If a string is provided,
19191916
it must be a valid :ref:`period alias <timeseries.period_aliases>`.
@@ -2599,7 +2596,7 @@ cdef class _Period(PeriodMixin):
25992596
26002597
Parameters
26012598
----------
2602-
freq : str, BaseOffset
2599+
freq : str, DateOffset
26032600
Frequency to use for the returned period.
26042601
26052602
See Also

Diff for: pandas/compat/numpy/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
r".*In the future `np\.long` will be defined as.*",
3737
FutureWarning,
3838
)
39-
np_long = np.long # type: ignore[attr-defined]
40-
np_ulong = np.ulong # type: ignore[attr-defined]
39+
np_long = np.long
40+
np_ulong = np.ulong
4141
except AttributeError:
4242
np_long = np.int_
4343
np_ulong = np.uint

Diff for: pandas/core/accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
351351
AttributeError: The series must contain integer data only.
352352
>>> df = pd.Series([1, 2, 3])
353353
>>> df.int_accessor.sum()
354-
6"""
354+
np.int64(6)"""
355355

356356

357357
@doc(_register_accessor, klass="Series", examples=_register_series_examples)

Diff for: pandas/core/arrays/base.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def argmin(self, skipna: bool = True) -> int:
941941
--------
942942
>>> arr = pd.array([3, 1, 2, 5, 4])
943943
>>> arr.argmin()
944-
1
944+
np.int64(1)
945945
"""
946946
# Implementer note: You have two places to override the behavior of
947947
# argmin.
@@ -975,7 +975,7 @@ def argmax(self, skipna: bool = True) -> int:
975975
--------
976976
>>> arr = pd.array([3, 1, 2, 5, 4])
977977
>>> arr.argmax()
978-
3
978+
np.int64(3)
979979
"""
980980
# Implementer note: You have two places to override the behavior of
981981
# argmax.
@@ -1959,10 +1959,10 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
19591959
--------
19601960
>>> class MyExtensionArray(pd.arrays.NumpyExtensionArray):
19611961
... def _formatter(self, boxed=False):
1962-
... return lambda x: "*" + str(x) + "*" if boxed else repr(x) + "*"
1962+
... return lambda x: "*" + str(x) + "*"
19631963
>>> MyExtensionArray(np.array([1, 2, 3, 4]))
19641964
<MyExtensionArray>
1965-
[1*, 2*, 3*, 4*]
1965+
[*1*, *2*, *3*, *4*]
19661966
Length: 4, dtype: int64
19671967
"""
19681968
if boxed:
@@ -2176,15 +2176,15 @@ def _reduce(
21762176
Examples
21772177
--------
21782178
>>> pd.array([1, 2, 3])._reduce("min")
2179-
1
2179+
np.int64(1)
21802180
>>> pd.array([1, 2, 3])._reduce("max")
2181-
3
2181+
np.int64(3)
21822182
>>> pd.array([1, 2, 3])._reduce("sum")
2183-
6
2183+
np.int64(6)
21842184
>>> pd.array([1, 2, 3])._reduce("mean")
2185-
2.0
2185+
np.float64(2.0)
21862186
>>> pd.array([1, 2, 3])._reduce("median")
2187-
2.0
2187+
np.float64(2.0)
21882188
"""
21892189
meth = getattr(self, name, None)
21902190
if meth is None:

Diff for: pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _unbox_scalar(
275275
--------
276276
>>> arr = pd.array(np.array(["1970-01-01"], "datetime64[ns]"))
277277
>>> arr._unbox_scalar(arr[0])
278-
numpy.datetime64('1970-01-01T00:00:00.000000000')
278+
np.datetime64('1970-01-01T00:00:00.000000000')
279279
"""
280280
raise AbstractMethodError(self)
281281

Diff for: pandas/core/arrays/interval.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
17751775
[(0, 1], (1, 2]]
17761776
Length: 2, dtype: interval[int64, right]
17771777
>>> idx.to_tuples()
1778-
array([(0, 1), (1, 2)], dtype=object)
1778+
array([(np.int64(0), np.int64(1)), (np.int64(1), np.int64(2))],
1779+
dtype=object)
17791780
17801781
For :class:`pandas.IntervalIndex`:
17811782

0 commit comments

Comments
 (0)