Skip to content

Commit bdcab11

Browse files
jbrockmendelTomAugspurger
authored andcommitted
BUG: iter with readonly values, closes #28055 (#28074)
* BUG: iter with readonly values, closes #28055 * whatsnew
1 parent becb774 commit bdcab11

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.25.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Datetimelike
2929

3030
- Bug in :func:`to_datetime` where passing a timezone-naive :class:`DatetimeArray` or :class:`DatetimeIndex` and ``utc=True`` would incorrectly return a timezone-naive result (:issue:`27733`)
3131
- Bug in :meth:`Period.to_timestamp` where a :class:`Period` outside the :class:`Timestamp` implementation bounds (roughly 1677-09-21 to 2262-04-11) would return an incorrect :class:`Timestamp` instead of raising ``OutOfBoundsDatetime`` (:issue:`19643`)
32+
- Bug in iterating over :class:`DatetimeIndex` when the underlying data is read-only (:issue:`28055`)
3233

3334
Timezones
3435
^^^^^^^^^

pandas/_libs/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cdef inline object create_time_from_ts(
7171

7272
@cython.wraparound(False)
7373
@cython.boundscheck(False)
74-
def ints_to_pydatetime(int64_t[:] arr, object tz=None, object freq=None,
74+
def ints_to_pydatetime(const int64_t[:] arr, object tz=None, object freq=None,
7575
str box="datetime"):
7676
"""
7777
Convert an i8 repr to an ndarray of datetimes, date, time or Timestamp

pandas/tests/indexes/datetimes/test_misc.py

+8
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,11 @@ def test_nanosecond_field(self):
377377
dti = DatetimeIndex(np.arange(10))
378378

379379
tm.assert_index_equal(dti.nanosecond, pd.Index(np.arange(10, dtype=np.int64)))
380+
381+
382+
def test_iter_readonly():
383+
# GH#28055 ints_to_pydatetime with readonly array
384+
arr = np.array([np.datetime64("2012-02-15T12:00:00.000000000")])
385+
arr.setflags(write=False)
386+
dti = pd.to_datetime(arr)
387+
list(dti)

0 commit comments

Comments
 (0)