Skip to content

BUG: Handle readonly arrays in period_array #25556

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
TomAugspurger committed Mar 5, 2019
commit 60657ce3b0de4a35c796cf17f7b98cc8e8f43d77
8 changes: 6 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,9 @@ cdef accessor _get_accessor_func(int code):

@cython.wraparound(False)
@cython.boundscheck(False)
def extract_ordinals(object[:] values, freq):
def extract_ordinals(ndarray[object] values, freq):
# TODO: Change type to const object[:] when Cython supports that.

cdef:
Py_ssize_t i, n = len(values)
int64_t[:] ordinals = np.empty(n, dtype=np.int64)
Expand Down Expand Up @@ -1472,7 +1474,9 @@ def extract_ordinals(object[:] values, freq):
return ordinals.base # .base to access underlying np.ndarray


def extract_freq(object[:] values):
def extract_freq(ndarray[object] values):
# TODO: Change type to const object[:] when Cython supports that.

cdef:
Py_ssize_t i, n = len(values)
object p
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,8 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
if copy:
periods = periods.copy()

# Support readonly `scalars`.
# TODO: remove flag unsetting / setting once Cython supports
# const object.
writeable = periods.flags.writeable
periods.setflags(write=True)
freq = freq or libperiod.extract_freq(periods)
ordinals = libperiod.extract_ordinals(periods, freq)
periods.setflags(write=writeable)
return cls(ordinals, freq=freq)

@classmethod
Expand Down