Skip to content

Commit afae797

Browse files
GuessWhoSamFooAnkurDedania
authored andcommitted
DEPR: rename consolidate to _consolidate and create deprecation warning (pandas-dev#15501)
1 parent 36631dc commit afae797

File tree

11 files changed

+37
-23
lines changed

11 files changed

+37
-23
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ Deprecations
493493
- ``DataFrame.astype()`` has deprecated the ``raise_on_error`` parameter in favor of ``errors`` (:issue:`14878`)
494494
- ``Series.sortlevel`` and ``DataFrame.sortlevel`` have been deprecated in favor of ``Series.sort_index`` and ``DataFrame.sort_index`` (:issue:`15099`)
495495
- importing ``concat`` from ``pandas.tools.merge`` has been deprecated in favor of imports from the ``pandas`` namespace. This should only affect explict imports (:issue:`15358`)
496+
- ``Series/DataFrame/Panel.consolidate()`` been deprecated as a public method. (:issue:`15483`)
496497

497498
.. _whatsnew_0200.prior_deprecations:
498499

pandas/core/generic.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -2875,11 +2875,10 @@ def f():
28752875

28762876
self._protect_consolidate(f)
28772877

2878-
def consolidate(self, inplace=False):
2878+
def _consolidate(self, inplace=False):
28792879
"""
28802880
Compute NDFrame with "consolidated" internals (data of each dtype
2881-
grouped together in a single ndarray). Mainly an internal API function,
2882-
but available here to the savvy user
2881+
grouped together in a single ndarray).
28832882
28842883
Parameters
28852884
----------
@@ -2898,6 +2897,15 @@ def consolidate(self, inplace=False):
28982897
cons_data = self._protect_consolidate(f)
28992898
return self._constructor(cons_data).__finalize__(self)
29002899

2900+
def consolidate(self, inplace=False):
2901+
"""
2902+
DEPRECATED: consolidate will be an internal implementation only.
2903+
"""
2904+
# 15483
2905+
warnings.warn("consolidate is deprecated and will be removed in a "
2906+
"future release.", FutureWarning, stacklevel=2)
2907+
return self._consolidate(inplace)
2908+
29012909
@property
29022910
def _is_mixed_type(self):
29032911
f = lambda: self._data.is_mixed_type

pandas/core/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3904,7 +3904,7 @@ def _wrap_aggregated_output(self, output, names=None):
39043904
if not self.as_index:
39053905
result = DataFrame(output, columns=output_keys)
39063906
self._insert_inaxis_grouper_inplace(result)
3907-
result = result.consolidate()
3907+
result = result._consolidate()
39083908
else:
39093909
index = self.grouper.result_index
39103910
result = DataFrame(output, index=index, columns=output_keys)
@@ -3924,7 +3924,7 @@ def _wrap_agged_blocks(self, items, blocks):
39243924
result = DataFrame(mgr)
39253925

39263926
self._insert_inaxis_grouper_inplace(result)
3927-
result = result.consolidate()
3927+
result = result._consolidate()
39283928
else:
39293929
index = self.grouper.result_index
39303930
mgr = BlockManager(blocks, [items, index])

pandas/io/pytables.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def func(_start, _stop, _where):
838838

839839
# concat and return
840840
return concat(objs, axis=axis,
841-
verify_integrity=False).consolidate()
841+
verify_integrity=False)._consolidate()
842842

843843
# create the iterator
844844
it = TableIterator(self, s, func, where=where, nrows=nrows,
@@ -3445,7 +3445,7 @@ def get_blk_items(mgr, blocks):
34453445
return [mgr.items.take(blk.mgr_locs) for blk in blocks]
34463446

34473447
# figure out data_columns and get out blocks
3448-
block_obj = self.get_object(obj).consolidate()
3448+
block_obj = self.get_object(obj)._consolidate()
34493449
blocks = block_obj._data.blocks
34503450
blk_items = get_blk_items(block_obj._data, blocks)
34513451
if len(self.non_index_axes):
@@ -3812,7 +3812,7 @@ def read(self, where=None, columns=None, **kwargs):
38123812
if len(objs) == 1:
38133813
wp = objs[0]
38143814
else:
3815-
wp = concat(objs, axis=0, verify_integrity=False).consolidate()
3815+
wp = concat(objs, axis=0, verify_integrity=False)._consolidate()
38163816

38173817
# apply the selection filters & axis orderings
38183818
wp = self.process_axes(wp, columns=columns)

pandas/tests/frame/test_block_internals.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@ def test_cast_internals(self):
4040

4141
def test_consolidate(self):
4242
self.frame['E'] = 7.
43-
consolidated = self.frame.consolidate()
43+
consolidated = self.frame._consolidate()
4444
self.assertEqual(len(consolidated._data.blocks), 1)
4545

4646
# Ensure copy, do I want this?
47-
recons = consolidated.consolidate()
47+
recons = consolidated._consolidate()
4848
self.assertIsNot(recons, consolidated)
4949
assert_frame_equal(recons, consolidated)
5050

5151
self.frame['F'] = 8.
5252
self.assertEqual(len(self.frame._data.blocks), 3)
53-
self.frame.consolidate(inplace=True)
53+
self.frame._consolidate(inplace=True)
5454
self.assertEqual(len(self.frame._data.blocks), 1)
5555

56+
def test_consolidate_deprecation(self):
57+
self.frame['E'] = 7
58+
with tm.assert_produces_warning(FutureWarning):
59+
self.frame.consolidate()
60+
5661
def test_consolidate_inplace(self):
5762
frame = self.frame.copy() # noqa
5863

pandas/tests/frame/test_nonunique_indexes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def check(result, expected=None):
8787
check(df, expected)
8888

8989
# consolidate
90-
df = df.consolidate()
90+
df = df._consolidate()
9191
expected = DataFrame([[1, 1, 'bah', 3], [1, 2, 'bah', 3],
9292
[2, 3, 'bah', 3]],
9393
columns=['foo', 'foo', 'string', 'foo2'])

pandas/tests/io/test_pytables.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_repr(self):
418418
df['datetime1'] = datetime.datetime(2001, 1, 2, 0, 0)
419419
df['datetime2'] = datetime.datetime(2001, 1, 3, 0, 0)
420420
df.loc[3:6, ['obj1']] = np.nan
421-
df = df.consolidate()._convert(datetime=True)
421+
df = df._consolidate()._convert(datetime=True)
422422

423423
warnings.filterwarnings('ignore', category=PerformanceWarning)
424424
store['df'] = df
@@ -762,7 +762,7 @@ def test_put_mixed_type(self):
762762
df['datetime1'] = datetime.datetime(2001, 1, 2, 0, 0)
763763
df['datetime2'] = datetime.datetime(2001, 1, 3, 0, 0)
764764
df.loc[3:6, ['obj1']] = np.nan
765-
df = df.consolidate()._convert(datetime=True)
765+
df = df._consolidate()._convert(datetime=True)
766766

767767
with ensure_clean_store(self.path) as store:
768768
_maybe_remove(store, 'df')
@@ -2077,7 +2077,7 @@ def test_table_mixed_dtypes(self):
20772077
df['datetime1'] = datetime.datetime(2001, 1, 2, 0, 0)
20782078
df['datetime2'] = datetime.datetime(2001, 1, 3, 0, 0)
20792079
df.loc[3:6, ['obj1']] = np.nan
2080-
df = df.consolidate()._convert(datetime=True)
2080+
df = df._consolidate()._convert(datetime=True)
20812081

20822082
with ensure_clean_store(self.path) as store:
20832083
store.append('df1_mixed', df)
@@ -2091,7 +2091,7 @@ def test_table_mixed_dtypes(self):
20912091
wp['bool2'] = wp['ItemB'] > 0
20922092
wp['int1'] = 1
20932093
wp['int2'] = 2
2094-
wp = wp.consolidate()
2094+
wp = wp._consolidate()
20952095

20962096
with ensure_clean_store(self.path) as store:
20972097
store.append('p1_mixed', wp)
@@ -2106,7 +2106,7 @@ def test_table_mixed_dtypes(self):
21062106
wp['bool2'] = wp['l2'] > 0
21072107
wp['int1'] = 1
21082108
wp['int2'] = 2
2109-
wp = wp.consolidate()
2109+
wp = wp._consolidate()
21102110

21112111
with ensure_clean_store(self.path) as store:
21122112
store.append('p4d_mixed', wp)
@@ -2134,7 +2134,7 @@ def test_unimplemented_dtypes_table_columns(self):
21342134
df['obj1'] = 'foo'
21352135
df['obj2'] = 'bar'
21362136
df['datetime1'] = datetime.date(2001, 1, 2)
2137-
df = df.consolidate()._convert(datetime=True)
2137+
df = df._consolidate()._convert(datetime=True)
21382138

21392139
with ensure_clean_store(self.path) as store:
21402140
# this fails because we have a date in the object block......
@@ -2949,7 +2949,7 @@ def _make_one():
29492949
df['bool2'] = df['B'] > 0
29502950
df['int1'] = 1
29512951
df['int2'] = 2
2952-
return df.consolidate()
2952+
return df._consolidate()
29532953

29542954
df1 = _make_one()
29552955
df2 = _make_one()

pandas/tests/test_generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def test_validate_bool_args(self):
658658
super(DataFrame, df).sort_index(inplace=value)
659659

660660
with self.assertRaises(ValueError):
661-
super(DataFrame, df).consolidate(inplace=value)
661+
super(DataFrame, df)._consolidate(inplace=value)
662662

663663
with self.assertRaises(ValueError):
664664
super(DataFrame, df).fillna(value=0, inplace=value)

pandas/tests/test_panel4d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def test_consolidate(self):
677677
self.panel4d['foo'] = 1.
678678
self.assertFalse(self.panel4d._data.is_consolidated())
679679

680-
panel4d = self.panel4d.consolidate()
680+
panel4d = self.panel4d._consolidate()
681681
self.assertTrue(panel4d._data.is_consolidated())
682682

683683
def test_ctor_dict(self):

pandas/tools/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
263263
raise TypeError("cannot concatenate a non-NDFrame object")
264264

265265
# consolidate
266-
obj.consolidate(inplace=True)
266+
obj._consolidate(inplace=True)
267267
ndims.add(obj.ndim)
268268

269269
# get the sample

pandas/tseries/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _convert_obj(self, obj):
221221
-------
222222
obj : converted object
223223
"""
224-
obj = obj.consolidate()
224+
obj = obj._consolidate()
225225
return obj
226226

227227
def _get_binner_for_time(self):

0 commit comments

Comments
 (0)