Skip to content

Commit 5d8cbb2

Browse files
Joris Vankerschaverjreback
Joris Vankerschaver
authored andcommitted
MAINT: Make take_1d accept readonly buffers., #11052
This is a straightforward port of GH#10070 to 1d arrays.
1 parent 4625d4d commit 5d8cbb2

File tree

4 files changed

+683
-62
lines changed

4 files changed

+683
-62
lines changed

doc/source/whatsnew/v0.18.0.txt

+10-23
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,7 @@ Bug Fixes
440440
- Bug in ``date_range`` when the boundaries fell on the frequency (:issue:`11804`)
441441
- Bug in consistency of passing nested dicts to ``.groupby(...).agg(...)`` (:issue:`9052`)
442442
- Accept unicode in ``Timedelta`` constructor (:issue:`11995`)
443-
444443
- Bug in value label reading for ``StataReader`` when reading incrementally (:issue:`12014`)
445-
446-
447444
- Bug in vectorized ``DateOffset`` when ``n`` parameter is ``0`` (:issue:`11370`)
448445

449446

@@ -456,7 +453,6 @@ Bug Fixes
456453
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)
457454
- Bug in ``DataFrame.info`` when duplicated column names exist (:issue:`11761`)
458455
- Bug in ``.copy`` of datetime tz-aware objects (:issue:`11794`)
459-
460456
- Bug in ``Series.apply`` and ``Series.map`` where ``timedelta64`` was not boxed (:issue:`11349`)
461457

462458

@@ -465,48 +461,39 @@ Bug Fixes
465461
- Bug in subclasses of ``DataFrame`` where ``AttributeError`` did not propagate (:issue:`11808`)
466462
- Bug groupby on tz-aware data where selection not returning ``Timestamp`` (:issue:`11616`)
467463
- Bug in ``pd.read_clipboard`` and ``pd.to_clipboard`` functions not supporting Unicode; upgrade included ``pyperclip`` to v1.5.15 (:issue:`9263`)
468-
469-
470464
- Bug in ``DataFrame.query`` containing an assignment (:issue:`8664`)
471465

472466

473467

474468
- Bug in timezone info lost when broadcasting scalar datetime to ``DataFrame`` (:issue:`11682`)
475-
476469
- Bug in ``Index`` creation from ``Timestamp`` with mixed tz coerces to UTC (:issue:`11488`)
477470
- Bug in ``to_numeric`` where it does not raise if input is more than one dimension (:issue:`11776`)
478-
479471
- Bug in parsing timezone offset strings with non-zero minutes (:issue:`11708`)
480-
481472
- Bug in ``df.plot`` using incorrect colors for bar plots under matplotlib 1.5+ (:issue:`11614`)
482473
- Bug in the ``groupby`` ``plot`` method when using keyword arguments (:issue:`11805`).
483-
484474
- Bug in ``DataFrame.duplicated`` and ``drop_duplicates`` causing spurious matches when setting ``keep=False`` (:issue:`11864`)
485-
486475
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
487476
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)
488-
489477
- Bug in ``.style.bar`` may not rendered properly using specific browser (:issue:`11678`)
490-
491478
- Bug in rich comparison of ``Timedelta`` with a ``numpy.array`` of ``Timedelta`` that caused an infinite recursion (:issue:`11835`)
492-
493479
- Bug in ``DataFrame.round`` dropping column index name (:issue:`11986`)
494-
495480
- Bug in ``df.replace`` while replacing value in mixed dtype ``Dataframe`` (:issue:`11698`)
496-
497481
- Bug in ``Index`` prevents copying name of passed ``Index``, when a new name is not provided (:issue:`11193`)
498-
499482
- Bug in ``read_excel`` failing to read any non-empty sheets when empty sheets exist and ``sheetname=None`` (:issue:`11711`)
500-
501483
- Bug in ``read_excel`` failing to raise ``NotImplemented`` error when keywords ``parse_dates`` and ``date_parser`` are provided (:issue:`11544`)
502-
503484
- Bug in ``read_sql`` with pymysql connections failing to return chunked data (:issue:`11522`)
504-
505485
- Bug in ``.to_csv`` ignoring formatting parameters ``decimal``, ``na_rep``, ``float_format`` for float indexes (:issue:`11553`)
506-
507486
- Bug in ``Int64Index`` and ``Float64Index`` preventing the use of the modulo operator (:issue:`9244`)
508487

488+
509489
- Bug in ``DataFrame`` when masking an empty ``DataFrame`` (:issue:`11859`)
510490

511-
- Removed ``millisecond`` property of ``DatetimeIndex``. This would always raise
512-
a ``ValueError`` (:issue:`12019`).
491+
492+
493+
494+
495+
496+
497+
498+
- Removed ``millisecond`` property of ``DatetimeIndex``. This would always raise a ``ValueError`` (:issue:`12019`).
499+
- Bug in ``Series`` constructor with read-only data (:issue:`11502`)

pandas/src/generate_code.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@
8888
"""
8989

9090

91-
take_1d_template = """
92-
@cython.wraparound(False)
93-
@cython.boundscheck(False)
94-
def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
95-
int64_t[:] indexer,
96-
%(c_type_out)s[:] out,
97-
fill_value=np.nan):
91+
inner_take_1d_template = """\
9892
cdef:
9993
Py_ssize_t i, n, idx
10094
%(c_type_out)s fv
@@ -112,6 +106,33 @@ def take_1d_%(name)s_%(dest)s(%(c_type_in)s[:] values,
112106
%(tab)s out[i] = %(preval)svalues[idx]%(postval)s
113107
"""
114108

109+
take_1d_template = """\
110+
@cython.wraparound(False)
111+
@cython.boundscheck(False)
112+
cdef inline take_1d_%(name)s_%(dest)s_memview(%(c_type_in)s[:] values,
113+
int64_t[:] indexer,
114+
%(c_type_out)s[:] out,
115+
fill_value=np.nan):
116+
""" + inner_take_1d_template + """
117+
118+
@cython.wraparound(False)
119+
@cython.boundscheck(False)
120+
def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=1] values,
121+
int64_t[:] indexer,
122+
%(c_type_out)s[:] out,
123+
fill_value=np.nan):
124+
125+
if values.flags.writeable:
126+
# We can call the memoryview version of the code
127+
take_1d_%(name)s_%(dest)s_memview(values, indexer, out,
128+
fill_value=fill_value)
129+
return
130+
131+
# We cannot use the memoryview version on readonly-buffers due to
132+
# a limitation of Cython's typed memoryviews. Instead we can use
133+
# the slightly slower Cython ndarray type directly.
134+
""" + inner_take_1d_template
135+
115136
inner_take_2d_axis0_template = """\
116137
cdef:
117138
Py_ssize_t i, j, k, n, idx

0 commit comments

Comments
 (0)