Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y libegl1 libopengl0

- name: Run doctests
run: cd ci && ./code_checks.sh doctests
run: cd ci && PANDAS_FUTURE_PYTHON_SCALARS="1" ./code_checks.sh doctests
if: ${{ steps.build.outcome == 'success' && always() }}

- name: Install pandas in editable mode
Expand Down
19 changes: 17 additions & 2 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ def pytest_addoption(parser) -> None:
)


def pytest_sessionstart(session):
import doctest
import inspect

orig = doctest.DocTestFinder._from_module # type: ignore[attr-defined]

def _from_module(self, module, object):
if inspect.isfunction(object) and "." in object.__qualname__:
return True
return orig(self, module, object)

doctest.DocTestFinder._from_module = _from_module # type: ignore[attr-defined]


def ignore_doctest_warning(item: pytest.Item, path: str, message: str) -> None:
"""Ignore doctest warning.

Expand All @@ -135,14 +149,15 @@ def pytest_collection_modifyitems(items, config) -> None:
# Warnings from doctests that can be ignored; place reason in comment above.
# Each entry specifies (path, message) - see the ignore_doctest_warning function
ignored_doctest_warnings = [
("api.interchange.from_dataframe", ".*Interchange Protocol is deprecated"),
("api.interchange.from_dataframe", "The DataFrame Interchange Protocol"),
("is_int64_dtype", "is_int64_dtype is deprecated"),
("is_interval_dtype", "is_interval_dtype is deprecated"),
("is_period_dtype", "is_period_dtype is deprecated"),
("is_datetime64tz_dtype", "is_datetime64tz_dtype is deprecated"),
("is_categorical_dtype", "is_categorical_dtype is deprecated"),
("is_sparse", "is_sparse is deprecated"),
("DataFrame.__dataframe__", "Interchange Protocol is deprecated"),
("CategoricalDtype._from_values_or_dtype", "Constructing a Categorical"),
("DataFrame.__dataframe__", "The DataFrame Interchange Protocol"),
("DataFrameGroupBy.fillna", "DataFrameGroupBy.fillna is deprecated"),
("DataFrameGroupBy.corrwith", "DataFrameGroupBy.corrwith is deprecated"),
("NDFrame.replace", "Series.replace without 'value'"),
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
AttributeError: The series must contain integer data only.
>>> df = pd.Series([1, 2, 3])
>>> df.int_accessor.sum()
np.int64(6)"""
6"""


@set_module("pandas.api.extensions")
Expand Down Expand Up @@ -481,7 +481,7 @@ def register_series_accessor(name: str) -> Callable[[TypeT], TypeT]:
AttributeError: The series must contain integer data only.
>>> df = pd.Series([1, 2, 3])
>>> df.int_accessor.sum()
np.int64(6)
6
"""
from pandas import Series

Expand Down
8 changes: 4 additions & 4 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,13 +894,13 @@ def tz_convert(self, tz) -> Self:
DatetimeIndex(['2014-08-01 09:00:00+02:00',
'2014-08-01 10:00:00+02:00',
'2014-08-01 11:00:00+02:00'],
dtype='datetime64[ns, Europe/Berlin]', freq='h')
dtype='datetime64[us, Europe/Berlin]', freq='h')

>>> dti.tz_convert("US/Central")
DatetimeIndex(['2014-08-01 02:00:00-05:00',
'2014-08-01 03:00:00-05:00',
'2014-08-01 04:00:00-05:00'],
dtype='datetime64[ns, US/Central]', freq='h')
dtype='datetime64[us, US/Central]', freq='h')

With the ``tz=None``, we can remove the timezone (after converting
to UTC if necessary):
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def tz_localize(
4 2018-10-28 02:30:00+01:00
5 2018-10-28 03:00:00+01:00
6 2018-10-28 03:30:00+01:00
dtype: datetime64[s, CET]
dtype: datetime64[us, CET]

In some cases, inferring the DST is impossible. In such cases, you can
pass an ndarray to the ambiguous parameter to set the DST explicitly
Expand All @@ -1059,7 +1059,7 @@ def tz_localize(
0 2018-10-28 01:20:00+02:00
1 2018-10-28 02:36:00+02:00
2 2018-10-28 03:46:00+01:00
dtype: datetime64[s, CET]
dtype: datetime64[us, CET]

If the DST transition causes nonexistent times, you can shift these
dates forward or backwards with a timedelta object or `'shift_forward'`
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
IntIndex
Indices: array([2, 3], dtype=int32)
>>> arr.astype(SparseDtype(np.dtype("int32")))
>>> arr.astype(pd.SparseDtype(np.dtype("int32")))
[0, 0, 1, 2]
Fill: 0
IntIndex
Expand All @@ -1297,7 +1297,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
Using a NumPy dtype with a different kind (e.g. float) will coerce
just ``self.sp_values``.
>>> arr.astype(SparseDtype(np.dtype("float64")))
>>> arr.astype(pd.SparseDtype(np.dtype("float64")))
... # doctest: +NORMALIZE_WHITESPACE
[nan, nan, 1.0, 2.0]
Fill: nan
Expand All @@ -1306,7 +1306,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
Using a SparseDtype, you can also change the fill value as well.
>>> arr.astype(SparseDtype("float64", fill_value=0.0))
>>> arr.astype(pd.SparseDtype("float64", fill_value=0.0))
... # doctest: +NORMALIZE_WHITESPACE
[0.0, 0.0, 1.0, 2.0]
Fill: 0.0
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def total_seconds(self) -> npt.NDArray[np.float64]:
>>> idx = pd.to_timedelta(np.arange(5), unit="D")
>>> idx
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
dtype='timedelta64[us]', freq=None)
dtype='timedelta64[ns]', freq=None)
>>> idx.total_seconds()
Index([0.0, 86400.0, 172800.0, 259200.0, 345600.0], dtype='float64')
Expand Down Expand Up @@ -855,7 +855,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
>>> tidx = pd.TimedeltaIndex(data=["1 days 02:30:45", "3 days 04:15:10"])
>>> tidx
TimedeltaIndex(['1 days 02:30:45', '3 days 04:15:10'],
dtype='timedelta64[ns]', freq=None)
dtype='timedelta64[us]', freq=None)
>>> tidx.to_pytimedelta()
array([datetime.timedelta(days=1, seconds=9045),
datetime.timedelta(days=3, seconds=15310)], dtype=object)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ def update_dtype(self, dtype) -> SparseDtype:
Examples
--------
>>> SparseDtype(int, 0).update_dtype(float)
Sparse[float64, 0.0]
Sparse[float64, np.float64(0.0)]
>>> SparseDtype(int, 1).update_dtype(SparseDtype(float, np.nan))
Sparse[float64, nan]
Expand Down
Loading
Loading