Skip to content

Coverage Plugin causes segfault #2879

@jbrockmendel

Description

@jbrockmendel

Just compiled pandas with cython coverage enabled to test #2871 and got a segfault during the test suite. This occurs in both master and in 0.29.1, so is not unique to #2871.

The test that segfaults is tests/arithmetic/test_datetime64.py TestDatetime64DateOffsetArithmetictest_dt64arr_add_sub_DateOffsets[Index-0-True-BusinessDay]. I'll see if I can track down a smaller piece of code that causes the segfault. I can reproduce it with

import pandas as pd
from pandas._libs.tslibs import period as libperiod

ts = pd.Timestamp('2000-01-05 00:15:00')
vec = pd.DatetimeIndex([ts])
asper = vec.to_period('B')._data
libperiod.periodarr_to_dt64arr(asper.asi8, 5000)

period_to_dt64arr is mostly a for-loop calling period_ordinal_to_dt64, but the latter does not segfault when called on its own:

libperiod.period_ordinal_to_dt64(asper.asi8[0], 5000)

The offending function:

@cython.wraparound(False)
@cython.boundscheck(False)
def periodarr_to_dt64arr(int64_t[:] periodarr, int freq):
    """
    Convert array to datetime64 values from a set of ordinals corresponding to
    periods per period convention.
    """
    cdef:
        int64_t[:] out
        Py_ssize_t i, l

    l = len(periodarr)

    out = np.empty(l, dtype='i8')

    with nogil:
        for i in range(l):
            if periodarr[i] == NPY_NAT:
                out[i] = NPY_NAT
                continue
            out[i] = period_ordinal_to_dt64(periodarr[i], freq)

    return out.base  # .base to access underlying np.ndarray

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions