Skip to content

Commit dc967d5

Browse files
authored
Merge branch 'pandas-dev:main' into CLN/separate_logic_from_init
2 parents 2f067b7 + ca55d77 commit dc967d5

35 files changed

+334
-195
lines changed

.github/workflows/unit-tests.yml

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ jobs:
314314
timeout-minutes: 90
315315

316316
concurrency:
317-
#https://i.8713187.xyzmunity/t/concurrecy-not-work-for-push/183068/7
317+
# https://i.8713187.xyzmunity/t/concurrecy-not-work-for-push/183068/7
318318
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-${{ matrix.os }}-${{ matrix.pytest_target }}-dev
319319
cancel-in-progress: true
320320

@@ -346,3 +346,62 @@ jobs:
346346
347347
- name: Run Tests
348348
uses: ./.github/actions/run-tests
349+
350+
emscripten:
351+
# Note: the Python version, Emscripten toolchain version are determined
352+
# by the Pyodide version. The appropriate versions can be found in the
353+
# Pyodide repodata.json "info" field, or in the Makefile.envs file:
354+
# https://github.com/pyodide/pyodide/blob/stable/Makefile.envs#L2
355+
# The Node.js version can be determined via Pyodide:
356+
# https://pyodide.org/en/stable/usage/index.html#node-js
357+
name: Pyodide build
358+
runs-on: ubuntu-22.04
359+
concurrency:
360+
# https://i.8713187.xyzmunity/t/concurrecy-not-work-for-push/183068/7
361+
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-wasm
362+
cancel-in-progress: true
363+
steps:
364+
- name: Checkout pandas Repo
365+
uses: actions/checkout@v4
366+
with:
367+
fetch-depth: 0
368+
369+
- name: Set up Python for Pyodide
370+
id: setup-python
371+
uses: actions/setup-python@v5
372+
with:
373+
python-version: '3.11.3'
374+
375+
- name: Set up Emscripten toolchain
376+
uses: mymindstorm/setup-emsdk@v14
377+
with:
378+
version: '3.1.46'
379+
actions-cache-folder: emsdk-cache
380+
381+
- name: Install pyodide-build
382+
run: pip install "pyodide-build==0.25.1"
383+
384+
- name: Build pandas for Pyodide
385+
run: |
386+
pyodide build
387+
388+
- name: Set up Node.js
389+
uses: actions/setup-node@v4
390+
with:
391+
node-version: '18'
392+
393+
- name: Set up Pyodide virtual environment
394+
run: |
395+
pyodide venv .venv-pyodide
396+
source .venv-pyodide/bin/activate
397+
pip install dist/*.whl
398+
399+
- name: Test pandas for Pyodide
400+
env:
401+
PANDAS_CI: 1
402+
run: |
403+
source .venv-pyodide/bin/activate
404+
pip install pytest hypothesis
405+
# do not import pandas from the checked out repo
406+
cd ..
407+
python -c 'import pandas as pd; pd.test(extra_args=["-m not clipboard and not single_cpu and not slow and not network and not db"])'

ci/code_checks.sh

Lines changed: 0 additions & 75 deletions
Large diffs are not rendered by default.

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Removal of prior version deprecations/changes
223223
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
224224
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
225225
- Changed behavior of :meth:`Series.__getitem__` and :meth:`Series.__setitem__` to always treat integer keys as labels, never as positional, consistent with :class:`DataFrame` behavior (:issue:`50617`)
226+
- Disallow a callable argument to :meth:`Series.iloc` to return a ``tuple`` (:issue:`53769`)
226227
- Disallow allowing logical operations (``||``, ``&``, ``^``) between pandas objects and dtype-less sequences (e.g. ``list``, ``tuple``); wrap the objects in :class:`Series`, :class:`Index`, or ``np.array`` first instead (:issue:`52264`)
227228
- Disallow automatic casting to object in :class:`Series` logical operations (``&``, ``^``, ``||``) between series with mismatched indexes and dtypes other than ``object`` or ``bool`` (:issue:`52538`)
228229
- Disallow calling :meth:`Series.replace` or :meth:`DataFrame.replace` without a ``value`` and with non-dict-like ``to_replace`` (:issue:`33302`)
@@ -234,6 +235,7 @@ Removal of prior version deprecations/changes
234235
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
235236
- Removed 'fastpath' keyword in :class:`Categorical` constructor (:issue:`20110`)
236237
- Removed 'kind' keyword in :meth:`Series.resample` and :meth:`DataFrame.resample` (:issue:`58125`)
238+
- Removed ``Block``, ``DatetimeTZBlock``, ``ExtensionBlock``, ``create_block_manager_from_blocks`` from ``pandas.core.internals`` and ``pandas.core.internals.api`` (:issue:`55139`)
237239
- Removed alias :class:`arrays.PandasArray` for :class:`arrays.NumpyExtensionArray` (:issue:`53694`)
238240
- Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
239241
- Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`)

pandas/_libs/tslibs/nattype.pyx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,18 @@ class NaTType(_NaT):
769769
770770
Return a new Timestamp representing UTC day and time.
771771
772+
See Also
773+
--------
774+
Timestamp : Constructs an arbitrary datetime.
775+
Timestamp.now : Return the current local date and time, which
776+
can be timezone-aware.
777+
Timestamp.today : Return the current local date and time with
778+
timezone information set to None.
779+
to_datetime : Convert argument to datetime.
780+
date_range : Return a fixed frequency DatetimeIndex.
781+
Timestamp.utctimetuple : Return UTC time tuple, compatible with
782+
time.localtime().
783+
772784
Examples
773785
--------
774786
>>> pd.Timestamp.utcnow() # doctest: +SKIP
@@ -1383,6 +1395,14 @@ default 'raise'
13831395
-------
13841396
Timestamp
13851397

1398+
See Also
1399+
--------
1400+
Timestamp.asm8 : Return numpy datetime64 format in nanoseconds.
1401+
Timestamp.to_pydatetime : Convert Timestamp object to a native
1402+
Python datetime object.
1403+
to_timedelta : Convert argument into timedelta object,
1404+
which can represent differences in times.
1405+
13861406
Examples
13871407
--------
13881408
>>> ts = pd.Timestamp('2023-01-01 00:00:00.01')

pandas/_libs/tslibs/offsets.pyx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ cdef class BaseOffset:
429429
"""
430430
Return a dict of extra parameters for the offset.
431431

432+
See Also
433+
--------
434+
tseries.offsets.DateOffset : The base class for all pandas date offsets.
435+
tseries.offsets.WeekOfMonth : Represents the week of the month.
436+
tseries.offsets.LastWeekOfMonth : Represents the last week of the month.
437+
432438
Examples
433439
--------
434440
>>> pd.DateOffset(5).kwds
@@ -558,6 +564,14 @@ cdef class BaseOffset:
558564
"""
559565
Return a string representing the base frequency.
560566

567+
See Also
568+
--------
569+
tseries.offsets.Week : Represents a weekly offset.
570+
DateOffset : Base class for all other offset classes.
571+
tseries.offsets.Day : Represents a single day offset.
572+
tseries.offsets.MonthEnd : Represents a monthly offset that
573+
snaps to the end of the month.
574+
561575
Examples
562576
--------
563577
>>> pd.offsets.Hour().name

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,14 @@ cdef class _Timestamp(ABCTimestamp):
11151115
-------
11161116
Timestamp
11171117
1118+
See Also
1119+
--------
1120+
Timestamp.asm8 : Return numpy datetime64 format in nanoseconds.
1121+
Timestamp.to_pydatetime : Convert Timestamp object to a native
1122+
Python datetime object.
1123+
to_timedelta : Convert argument into timedelta object,
1124+
which can represent differences in times.
1125+
11181126
Examples
11191127
--------
11201128
>>> ts = pd.Timestamp('2023-01-01 00:00:00.01')
@@ -1452,6 +1460,18 @@ class Timestamp(_Timestamp):
14521460
14531461
Return a new Timestamp representing UTC day and time.
14541462
1463+
See Also
1464+
--------
1465+
Timestamp : Constructs an arbitrary datetime.
1466+
Timestamp.now : Return the current local date and time, which
1467+
can be timezone-aware.
1468+
Timestamp.today : Return the current local date and time with
1469+
timezone information set to None.
1470+
to_datetime : Convert argument to datetime.
1471+
date_range : Return a fixed frequency DatetimeIndex.
1472+
Timestamp.utctimetuple : Return UTC time tuple, compatible with
1473+
time.localtime().
1474+
14551475
Examples
14561476
--------
14571477
>>> pd.Timestamp.utcnow() # doctest: +SKIP

pandas/compat/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
PY311,
2323
PY312,
2424
PYPY,
25+
WASM,
2526
)
2627
import pandas.compat.compressors
2728
from pandas.compat.numpy import is_numpy_dev
@@ -122,6 +123,18 @@ def is_platform_power() -> bool:
122123
return platform.machine() in ("ppc64", "ppc64le")
123124

124125

126+
def is_platform_riscv64() -> bool:
127+
"""
128+
Checking if the running platform use riscv64 architecture.
129+
130+
Returns
131+
-------
132+
bool
133+
True if the running platform uses riscv64 architecture.
134+
"""
135+
return platform.machine() == "riscv64"
136+
137+
125138
def is_ci_environment() -> bool:
126139
"""
127140
Checking if running in a continuous integration environment by checking
@@ -195,4 +208,5 @@ def get_bz2_file() -> type[pandas.compat.compressors.BZ2File]:
195208
"PY311",
196209
"PY312",
197210
"PYPY",
211+
"WASM",
198212
]

pandas/compat/_constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
PY311 = sys.version_info >= (3, 11)
1818
PY312 = sys.version_info >= (3, 12)
1919
PYPY = platform.python_implementation() == "PyPy"
20+
WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
2021
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
2122
REF_COUNT = 2 if PY311 else 3
2223

@@ -27,4 +28,5 @@
2728
"PY311",
2829
"PY312",
2930
"PYPY",
31+
"WASM",
3032
]

pandas/core/arrays/datetimes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,15 @@ def isocalendar(self) -> DataFrame:
19131913
"""
19141914
The number of days in the month.
19151915
1916+
See Also
1917+
--------
1918+
Series.dt.day : Return the day of the month.
1919+
Series.dt.is_month_end : Return a boolean indicating if the
1920+
date is the last day of the month.
1921+
Series.dt.is_month_start : Return a boolean indicating if the
1922+
date is the first day of the month.
1923+
Series.dt.month : Return the month as January=1 through December=12.
1924+
19161925
Examples
19171926
--------
19181927
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])

pandas/core/base.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@ def empty(self) -> bool:
703703
"""
704704
Indicator whether Index is empty.
705705
706+
An Index is considered empty if it has no elements. This property can be
707+
useful for quickly checking the state of an Index, especially in data
708+
processing and analysis workflows where handling of empty datasets might
709+
be required.
710+
706711
Returns
707712
-------
708713
bool
@@ -714,10 +719,10 @@ def empty(self) -> bool:
714719
715720
Examples
716721
--------
717-
>>> idx_empty = pd.Index([1, 2, 3])
718-
>>> idx_empty
722+
>>> idx = pd.Index([1, 2, 3])
723+
>>> idx
719724
Index([1, 2, 3], dtype='int64')
720-
>>> idx_empty.empty
725+
>>> idx.empty
721726
False
722727
723728
>>> idx_empty = pd.Index([])
@@ -728,10 +733,10 @@ def empty(self) -> bool:
728733
729734
If we only have NaNs in our DataFrame, it is not considered empty!
730735
731-
>>> idx_empty = pd.Index([np.nan, np.nan])
732-
>>> idx_empty
736+
>>> idx = pd.Index([np.nan, np.nan])
737+
>>> idx
733738
Index([nan, nan], dtype='float64')
734-
>>> idx_empty.empty
739+
>>> idx.empty
735740
False
736741
"""
737742
return not self.size

pandas/core/indexes/base.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,13 @@ def ravel(self, order: str_t = "C") -> Self:
10211021

10221022
def view(self, cls=None):
10231023
"""
1024-
Return a view on self.
1024+
Return a view of the Index with the specified dtype or a new Index instance.
1025+
1026+
This method returns a view of the calling Index object if no arguments are
1027+
provided. If a dtype is specified through the `cls` argument, it attempts
1028+
to return a view of the Index with the specified dtype. Note that viewing
1029+
the Index as a different dtype reinterprets the underlying data, which can
1030+
lead to unexpected results for non-numeric or incompatible dtype conversions.
10251031
10261032
Parameters
10271033
----------
@@ -1034,27 +1040,38 @@ def view(self, cls=None):
10341040
10351041
Returns
10361042
-------
1037-
numpy.ndarray
1038-
A new view of the same data in memory.
1043+
Index or ndarray
1044+
A view of the Index. If `cls` is None, the returned object is an Index
1045+
view with the same dtype as the calling object. If a numeric `cls` is
1046+
specified an ndarray view with the new dtype is returned.
1047+
1048+
Raises
1049+
------
1050+
ValueError
1051+
If attempting to change to a dtype in a way that is not compatible with
1052+
the original dtype's memory layout, for example, viewing an 'int64' Index
1053+
as 'str'.
10391054
10401055
See Also
10411056
--------
1057+
Index.copy : Returns a copy of the Index.
10421058
numpy.ndarray.view : Returns a new view of array with the same data.
10431059
10441060
Examples
10451061
--------
1046-
>>> s = pd.Series([1, 2, 3], index=["1", "2", "3"])
1047-
>>> s.index.view("object")
1048-
array(['1', '2', '3'], dtype=object)
1062+
>>> idx = pd.Index([-1, 0, 1])
1063+
>>> idx.view()
1064+
Index([-1, 0, 1], dtype='int64')
10491065
1050-
>>> s = pd.Series([1, 2, 3], index=[-1, 0, 1])
1051-
>>> s.index.view(np.int64)
1052-
array([-1, 0, 1])
1053-
>>> s.index.view(np.float32)
1054-
array([ nan, nan, 0.e+00, 0.e+00, 1.e-45, 0.e+00], dtype=float32)
1055-
>>> s.index.view(np.uint64)
1066+
>>> idx.view(np.uint64)
10561067
array([18446744073709551615, 0, 1],
10571068
dtype=uint64)
1069+
1070+
Viewing as 'int32' or 'float32' reinterprets the memory, which may lead to
1071+
unexpected behavior:
1072+
1073+
>>> idx.view("float32")
1074+
array([ nan, nan, 0.e+00, 0.e+00, 1.e-45, 0.e+00], dtype=float32)
10581075
"""
10591076
# we need to see if we are subclassing an
10601077
# index type here
@@ -1809,19 +1826,34 @@ def _get_names(self) -> FrozenList:
18091826
"""
18101827
Get names on index.
18111828
1829+
This method returns a FrozenList containing the names of the object.
1830+
It's primarily intended for internal use.
1831+
1832+
Returns
1833+
-------
1834+
FrozenList
1835+
A FrozenList containing the object's names, contains None if the object
1836+
does not have a name.
1837+
18121838
See Also
18131839
--------
1814-
Index.name : Return Index or MultiIndex name.
1840+
Index.name : Index name as a string, or None for MultiIndex.
18151841
18161842
Examples
18171843
--------
18181844
>>> idx = pd.Index([1, 2, 3], name="x")
18191845
>>> idx.names
18201846
FrozenList(['x'])
18211847
1822-
>>> idx = s = pd.Index([1, 2, 3], name=("x", "y"))
1848+
>>> idx = pd.Index([1, 2, 3], name=("x", "y"))
18231849
>>> idx.names
18241850
FrozenList([('x', 'y')])
1851+
1852+
If the index does not have a name set:
1853+
1854+
>>> idx = pd.Index([1, 2, 3])
1855+
>>> idx.names
1856+
FrozenList([None])
18251857
"""
18261858
return FrozenList((self.name,))
18271859

0 commit comments

Comments
 (0)