Skip to content

TST: fixed cython doctests #43768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pandas/tseries/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Cython Doctests' ; echo $MSG
python -m pytest --doctest-cython pandas/_libs
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi

### DOCSTRINGS ###
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies:
- flask
- pytest>=6.0
- pytest-cov
- pytest-cython
- pytest-xdist>=1.31
- pytest-asyncio
- pytest-instafail
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ cdef class ObjectFactorizer(Factorizer):
--------
Factorize values with nans replaced by na_sentinel

>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)
>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)# doctest: +SKIP
array([ 0, 1, 20])
"""
cdef:
Expand Down Expand Up @@ -142,7 +142,7 @@ cdef class Int64Factorizer(Factorizer):
--------
Factorize values with nans replaced by na_sentinel

>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)
>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)# doctest: +SKIP
array([ 0, 1, 20])
"""
cdef:
Expand Down
7 changes: 4 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from cpython.tuple cimport (
PyTuple_SET_ITEM,
)
from cython cimport floating
import datetime

PyDateTime_IMPORT

Expand Down Expand Up @@ -188,7 +189,7 @@ def is_scalar(val: object) -> bool:
>>> pd.api.types.is_scalar((0, 2))
False

pandas supports PEP 3141 numbers:
>>> # pandas supports PEP 3141 numbers:

>>> from fractions import Fraction
>>> pd.api.types.is_scalar(Fraction(3, 5))
Expand Down Expand Up @@ -260,7 +261,7 @@ def is_iterator(obj: object) -> bool:
True
>>> is_iterator([1, 2, 3])
False
>>> is_iterator(datetime(2017, 1, 1))
>>> is_iterator(datetime.datetime(2017, 1, 1))
False
>>> is_iterator("foo")
False
Expand Down Expand Up @@ -1075,7 +1076,7 @@ def is_list_like(obj: object, allow_sets: bool = True) -> bool:
True
>>> is_list_like({1, 2, 3})
True
>>> is_list_like(datetime(2017, 1, 1))
>>> is_list_like(datetime.datetime(2017, 1, 1))
False
>>> is_list_like("foo")
False
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Resolution(Enum):

Examples
--------
>>> Resolution.from_attrname('second')
>>> Resolution.from_attrname('second') # doctest: +SKIP
2

>>> Resolution.from_attrname('second') == Resolution.RESO_SEC
Expand All @@ -243,7 +243,7 @@ class Resolution(Enum):

Examples
--------
>>> Resolution.get_reso_from_freq('H')
>>> Resolution.get_reso_from_freq('H') # doctest: +SKIP
4

>>> Resolution.get_reso_from_freq('H') == Resolution.RESO_HR
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class NaTType(_NaT):
Examples
--------
>>> pd.Timestamp.fromtimestamp(1584199972)
Timestamp('2020-03-14 15:32:52')
Timestamp('2020-03-14 21:02:52')
""",
)
fromtimestamp = _make_error_func(
Expand Down Expand Up @@ -581,7 +581,7 @@ class NaTType(_NaT):

Examples
--------
>>> pd.Timestamp.utcnow()
>>> pd.Timestamp.utcnow() # doctest: +SKIP
Timestamp('2020-11-16 22:50:18.092888+0000', tz='UTC')
""",
)
Expand Down Expand Up @@ -705,7 +705,7 @@ class NaTType(_NaT):

Examples
--------
>>> pd.Timestamp.now()
>>> pd.Timestamp.now() # doctest: +SKIP
Timestamp('2020-11-16 22:06:16.378782')

Analogous for ``pd.NaT``:
Expand All @@ -730,7 +730,7 @@ class NaTType(_NaT):

Examples
--------
>>> pd.Timestamp.today()
>>> pd.Timestamp.today() # doctest: +SKIP
Timestamp('2020-11-16 22:37:39.969883')

Analogous for ``pd.NaT``:
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ cdef class _Period(PeriodMixin):
>>>
>>> a = Period(freq='D', year=2001, month=1, day=1)
>>> a.strftime('%d-%b-%Y')
'01-Jan-2006'
'01-Jan-2001'
>>> a.strftime('%b. %d, %Y was a %A')
'Jan. 01, 2001 was a Monday'
"""
Expand Down
22 changes: 13 additions & 9 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -909,16 +909,20 @@ cdef class _Timestamp(ABCTimestamp):
Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.to_period(freq='Y) # Year end frequency
numpy.datetime64('2020-03-14T15:32:52.192548651')
>>> # Year end frequency
>>> ts.to_period(freq='Y')
Period('2020', 'A-DEC')

>>> ts.to_period(freq='M') # Month end frequency
>>> # Month end frequency
>>> ts.to_period(freq='M')
Period('2020-03', 'M')

>>> ts.to_period(freq='W') # Weekly frequency
>>> # Weekly frequency
>>> ts.to_period(freq='W')
Period('2020-03-09/2020-03-15', 'W-SUN')

>>> ts.to_period(freq='Q') # Quarter end frequency
>>> # Quarter end frequency
>>> ts.to_period(freq='Q')
Period('2020Q1', 'Q-DEC')
"""
from pandas import Period
Expand Down Expand Up @@ -1059,7 +1063,7 @@ class Timestamp(_Timestamp):

Examples
--------
>>> pd.Timestamp.now()
>>> pd.Timestamp.now() # doctest: +SKIP
Timestamp('2020-11-16 22:06:16.378782')

Analogous for ``pd.NaT``:
Expand Down Expand Up @@ -1087,7 +1091,7 @@ class Timestamp(_Timestamp):

Examples
--------
>>> pd.Timestamp.today()
>>> pd.Timestamp.today() # doctest: +SKIP
Timestamp('2020-11-16 22:37:39.969883')

Analogous for ``pd.NaT``:
Expand All @@ -1106,7 +1110,7 @@ class Timestamp(_Timestamp):

Examples
--------
>>> pd.Timestamp.utcnow()
>>> pd.Timestamp.utcnow() # doctest: +SKIP
Timestamp('2020-11-16 22:50:18.092888+0000', tz='UTC')
"""
return cls.now(UTC)
Expand All @@ -1121,7 +1125,7 @@ class Timestamp(_Timestamp):
Examples
--------
>>> pd.Timestamp.fromtimestamp(1584199972)
Timestamp('2020-03-14 15:32:52')
Timestamp('2020-03-14 21:02:52')
"""
return cls(datetime.utcfromtimestamp(ts))

Expand Down
14 changes: 7 additions & 7 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,24 @@ def tz_standardize(tz: tzinfo) -> tzinfo:
-------
tzinfo

Examples:
Examples
--------
>>> tz
>>> tz # doctest: +SKIP
<DstTzInfo 'US/Pacific' PST-1 day, 16:00:00 STD>

>>> tz_standardize(tz)
>>> tz_standardize(tz) # doctest: +SKIP
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>

>>> tz
>>> tz # doctest: +SKIP
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>

>>> tz_standardize(tz)
>>> tz_standardize(tz) # doctest: +SKIP
<DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>

>>> tz
>>> tz # doctest: +SKIP
dateutil.tz.tz.tzutc

>>> tz_standardize(tz)
>>> tz_standardize(tz) # doctest: +SKIP
dateutil.tz.tz.tzutc
"""
if treat_tz_as_pytz(tz):
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ moto
flask
pytest>=6.0
pytest-cov
pytest-cython
pytest-xdist>=1.31
pytest-asyncio
pytest-instafail
Expand Down