Skip to content

Commit 741f284

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ea-take
2 parents 5db6624 + 630ef16 commit 741f284

File tree

15 files changed

+76
-20
lines changed

15 files changed

+76
-20
lines changed

doc/source/whatsnew/v0.23.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ Deprecations
886886
- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and will be removed in a future version. The NumPy bug motivating this parameter has been resolved. The default value for this parameter has also changed from ``True`` to ``None`` (:issue:`18160`).
887887
- :func:`Series.rolling().apply() <pandas.core.window.Rolling.apply>`, :func:`DataFrame.rolling().apply() <pandas.core.window.Rolling.apply>`,
888888
:func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` have deprecated passing an ``np.array`` by default. One will need to pass the new ``raw`` parameter to be explicit about what is passed (:issue:`20584`)
889+
- The ``data``, ``base``, ``strides``, ``flags`` and ``itemsize`` properties
890+
of the ``Series`` and ``Index`` classes have been deprecated and will be
891+
removed in a future version (:issue:`20419`).
889892
- ``DatetimeIndex.offset`` is deprecated. Use ``DatetimeIndex.freq`` instead (:issue:`20716`)
890893
- ``Index.get_duplicates()`` is deprecated and will be removed in a future version (:issue:`20239`)
891894

pandas/core/algorithms.py

+2
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,8 @@ def take_nd(arr, indexer, axis=0, out=None, fill_value=np.nan, mask_info=None,
15861586
if is_sparse(arr):
15871587
arr = arr.get_values()
15881588

1589+
arr = np.asarray(arr)
1590+
15891591
if indexer is None:
15901592
indexer = np.arange(arr.shape[axis], dtype=np.int64)
15911593
dtype, fill_value = arr.dtype, arr.dtype.type()

pandas/core/apply.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,14 @@ def get_result(self):
111111

112112
# string dispatch
113113
if isinstance(self.f, compat.string_types):
114-
self.kwds['axis'] = self.axis
115-
return getattr(self.obj, self.f)(*self.args, **self.kwds)
114+
# Support for `frame.transform('method')`
115+
# Some methods (shift, etc.) require the axis argument, others
116+
# don't, so inspect and insert if nescessary.
117+
func = getattr(self.obj, self.f)
118+
sig = compat.signature(func)
119+
if 'axis' in sig.args:
120+
self.kwds['axis'] = self.axis
121+
return func(*self.args, **self.kwds)
116122

117123
# ufunc
118124
elif isinstance(self.f, np.ufunc):

pandas/core/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,17 @@ def item(self):
737737
@property
738738
def data(self):
739739
""" return the data pointer of the underlying data """
740+
warnings.warn("{obj}.data is deprecated and will be removed "
741+
"in a future version".format(obj=type(self).__name__),
742+
FutureWarning, stacklevel=2)
740743
return self.values.data
741744

742745
@property
743746
def itemsize(self):
744747
""" return the size of the dtype of the item of the underlying data """
748+
warnings.warn("{obj}.itemsize is deprecated and will be removed "
749+
"in a future version".format(obj=type(self).__name__),
750+
FutureWarning, stacklevel=2)
745751
return self._ndarray_values.itemsize
746752

747753
@property
@@ -752,6 +758,9 @@ def nbytes(self):
752758
@property
753759
def strides(self):
754760
""" return the strides of the underlying data """
761+
warnings.warn("{obj}.strudes is deprecated and will be removed "
762+
"in a future version".format(obj=type(self).__name__),
763+
FutureWarning, stacklevel=2)
755764
return self._ndarray_values.strides
756765

757766
@property
@@ -762,13 +771,19 @@ def size(self):
762771
@property
763772
def flags(self):
764773
""" return the ndarray.flags for the underlying data """
774+
warnings.warn("{obj}.flags is deprecated and will be removed "
775+
"in a future version".format(obj=type(self).__name__),
776+
FutureWarning, stacklevel=2)
765777
return self.values.flags
766778

767779
@property
768780
def base(self):
769781
""" return the base object if the memory of the underlying data is
770782
shared
771783
"""
784+
warnings.warn("{obj}.base is deprecated and will be removed "
785+
"in a future version".format(obj=type(self).__name__),
786+
FutureWarning, stacklevel=2)
772787
return self.values.base
773788

774789
@property

pandas/core/indexes/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ def _deepcopy_if_needed(self, orig, copy=False):
550550
"""
551551
if copy:
552552
# Retrieve the "base objects", i.e. the original memory allocations
553+
if not isinstance(orig, np.ndarray):
554+
# orig is a DatetimeIndex
555+
orig = orig.values
553556
orig = orig if orig.base is None else orig.base
554557
new = self._data if self._data.base is None else self._data.base
555558
if orig is new:

pandas/core/internals.py

+6
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,12 @@ def _maybe_coerce_values(self, values, dtype=None):
28222822

28232823
return values
28242824

2825+
@property
2826+
def is_view(self):
2827+
""" return a boolean if I am possibly a view """
2828+
# check the ndarray values of the DatetimeIndex values
2829+
return self.values.values.base is not None
2830+
28252831
def copy(self, deep=True, mgr=None):
28262832
""" copy constructor """
28272833
values = self.values

pandas/core/window.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1271,12 +1271,12 @@ def kurt(self, **kwargs):
12711271
check_minp=_require_min_periods(4), **kwargs)
12721272

12731273
_shared_docs['quantile'] = dedent("""
1274-
%(name)s quantile
1274+
%(name)s quantile.
12751275
12761276
Parameters
12771277
----------
12781278
quantile : float
1279-
0 <= quantile <= 1
1279+
Quantile to compute. 0 <= quantile <= 1.
12801280
interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
12811281
.. versionadded:: 0.23.0
12821282
@@ -1289,6 +1289,9 @@ def kurt(self, **kwargs):
12891289
* higher: `j`.
12901290
* nearest: `i` or `j` whichever is nearest.
12911291
* midpoint: (`i` + `j`) / 2.
1292+
**kwargs:
1293+
For compatibility with other %(name)s methods. Has no effect on
1294+
the result.
12921295
12931296
Returns
12941297
-------
@@ -1298,7 +1301,7 @@ def kurt(self, **kwargs):
12981301
12991302
Examples
13001303
--------
1301-
>>> s = Series([1, 2, 3, 4])
1304+
>>> s = pd.Series([1, 2, 3, 4])
13021305
>>> s.rolling(2).quantile(.4, interpolation='lower')
13031306
0 NaN
13041307
1 1.0
@@ -1319,7 +1322,6 @@ def kurt(self, **kwargs):
13191322
in Series.
13201323
pandas.DataFrame.quantile : Computes values at the given quantile over
13211324
requested axis in DataFrame.
1322-
13231325
""")
13241326

13251327
def quantile(self, quantile, interpolation='linear', **kwargs):
@@ -1656,7 +1658,6 @@ def kurt(self, **kwargs):
16561658
return super(Rolling, self).kurt(**kwargs)
16571659

16581660
@Substitution(name='rolling')
1659-
@Appender(_doc_template)
16601661
@Appender(_shared_docs['quantile'])
16611662
def quantile(self, quantile, interpolation='linear', **kwargs):
16621663
return super(Rolling, self).quantile(quantile=quantile,
@@ -1917,7 +1918,6 @@ def kurt(self, **kwargs):
19171918
return super(Expanding, self).kurt(**kwargs)
19181919

19191920
@Substitution(name='expanding')
1920-
@Appender(_doc_template)
19211921
@Appender(_shared_docs['quantile'])
19221922
def quantile(self, quantile, interpolation='linear', **kwargs):
19231923
return super(Expanding, self).quantile(quantile=quantile,

pandas/tests/frame/test_apply.py

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
import operator
78
from datetime import datetime
89

910
import warnings
@@ -880,6 +881,16 @@ def f():
880881
with np.errstate(all='ignore'):
881882
df.agg({'A': ['abs', 'sum'], 'B': ['mean', 'max']})
882883

884+
@pytest.mark.parametrize('method', [
885+
'abs', 'shift', 'pct_change', 'cumsum', 'rank',
886+
])
887+
def test_transform_method_name(self, method):
888+
# https://github.com/pandas-dev/pandas/issues/19760
889+
df = pd.DataFrame({"A": [-1, 2]})
890+
result = df.transform(method)
891+
expected = operator.methodcaller(method)(df)
892+
tm.assert_frame_equal(result, expected)
893+
883894
def test_demo(self):
884895
# demonstration tests
885896
df = pd.DataFrame({'A': range(5), 'B': 5})

pandas/tests/groupby/aggregate/test_other.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_series_agg_multi_pure_python():
328328
'F': np.random.randn(11)})
329329

330330
def bad(x):
331-
assert (len(x.base) > 0)
331+
assert (len(x.values.base) > 0)
332332
return 'foo'
333333

334334
result = data.groupby(['A', 'B']).agg(bad)

pandas/tests/groupby/test_groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ def convert_fast(x):
10661066

10671067
def convert_force_pure(x):
10681068
# base will be length 0
1069-
assert (len(x.base) > 0)
1069+
assert (len(x.values.base) > 0)
10701070
return Decimal(str(x.mean()))
10711071

10721072
grouped = s.groupby(labels)

pandas/tests/indexes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class Base(object):
2525
""" base class for index sub-class tests """
2626
_holder = None
27-
_compat_props = ['shape', 'ndim', 'size', 'itemsize', 'nbytes']
27+
_compat_props = ['shape', 'ndim', 'size', 'nbytes']
2828

2929
def setup_indices(self):
3030
for name, idx in self.indices.items():

pandas/tests/indexes/test_multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class TestMultiIndex(Base):
3232
_holder = MultiIndex
33-
_compat_props = ['shape', 'ndim', 'size', 'itemsize']
33+
_compat_props = ['shape', 'ndim', 'size']
3434

3535
def setup_method(self, method):
3636
major_axis = Index(['foo', 'bar', 'baz', 'qux'])

pandas/tests/indexes/test_range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class TestRangeIndex(Numeric):
2424
_holder = RangeIndex
25-
_compat_props = ['shape', 'ndim', 'size', 'itemsize']
25+
_compat_props = ['shape', 'ndim', 'size']
2626

2727
def setup_method(self, method):
2828
self.indices = dict(index=RangeIndex(0, 20, 2, name='foo'),

pandas/tests/internals/test_internals.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,20 @@ def test_copy(self, mgr):
466466

467467
# view assertion
468468
assert cp_blk.equals(blk)
469-
assert cp_blk.values.base is blk.values.base
469+
if isinstance(blk.values, np.ndarray):
470+
assert cp_blk.values.base is blk.values.base
471+
else:
472+
# DatetimeTZBlock has DatetimeIndex values
473+
assert cp_blk.values.values.base is blk.values.values.base
470474

471475
cp = mgr.copy(deep=True)
472476
for blk, cp_blk in zip(mgr.blocks, cp.blocks):
473477

474478
# copy assertion we either have a None for a base or in case of
475479
# some blocks it is an array (e.g. datetimetz), but was copied
476480
assert cp_blk.equals(blk)
477-
if cp_blk.values.base is not None and blk.values.base is not None:
478-
assert cp_blk.values.base is not blk.values.base
481+
if not isinstance(cp_blk.values, np.ndarray):
482+
assert cp_blk.values.values.base is not blk.values.values.base
479483
else:
480484
assert cp_blk.values.base is None and blk.values.base is None
481485

pandas/tests/test_base.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,22 @@ def test_ndarray_compat_properties(self):
316316

317317
for o in self.objs:
318318
# Check that we work.
319-
for p in ['shape', 'dtype', 'flags', 'T',
320-
'strides', 'itemsize', 'nbytes']:
319+
for p in ['shape', 'dtype', 'T', 'nbytes']:
321320
assert getattr(o, p, None) is not None
322321

323-
assert hasattr(o, 'base')
322+
# deprecated properties
323+
for p in ['flags', 'strides', 'itemsize']:
324+
with tm.assert_produces_warning(FutureWarning):
325+
assert getattr(o, p, None) is not None
326+
327+
with tm.assert_produces_warning(FutureWarning):
328+
assert hasattr(o, 'base')
324329

325330
# If we have a datetime-like dtype then needs a view to work
326331
# but the user is responsible for that
327332
try:
328-
assert o.data is not None
333+
with tm.assert_produces_warning(FutureWarning):
334+
assert o.data is not None
329335
except ValueError:
330336
pass
331337

0 commit comments

Comments
 (0)