Skip to content

Commit 524a9a0

Browse files
jrebackjorisvandenbossche
authored andcommitted
DEPR: deprecate some top-level non-used functions (pandas-dev#15538)
closes pandas-dev#13790 pd.pnow pd.groupby pd.match pd.Term pd.Expr remove info.py
1 parent 24a2155 commit 524a9a0

File tree

10 files changed

+141
-57
lines changed

10 files changed

+141
-57
lines changed

doc/source/comparison_with_r.rst

-8
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,6 @@ of its first argument in its second:
206206
s <- 0:4
207207
match(s, c(2,4))
208208
209-
The :meth:`~pandas.core.groupby.GroupBy.apply` method can be used to replicate
210-
this:
211-
212-
.. ipython:: python
213-
214-
s = pd.Series(np.arange(5),dtype=np.float32)
215-
pd.Series(pd.match(s,[2,4],np.nan))
216-
217209
For more details and examples see :ref:`the reshaping documentation
218210
<indexing.basics.indexing_isin>`.
219211

doc/source/whatsnew/v0.20.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ Deprecations
537537
- 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`)
538538
- ``Series/DataFrame/Panel.consolidate()`` been deprecated as a public method. (:issue:`15483`)
539539
- ``FrozenList`` addition (new object and inplace) have been deprecated in favor of the ``.union()`` method. (:issue: `15475`)
540+
- The following top-level pandas functions have been deprecated and will be removed in a future version (:issue:`13790`)
541+
* ``pd.pnow()``, replaced by ``Period.now()``
542+
* ``pd.Term``, is removed, as it is not applicable to user code. Instead use in-line string expressions in the where clause when searching in HDFStore
543+
* ``pd.Expr``, is removed, as it is not applicable to user code.
544+
* ``pd.match()``, is removed.
545+
* ``pd.groupby()``, replaced by using the ``.groupby()`` method directly on a ``Series/DataFrame``
540546

541547
.. _whatsnew_0200.prior_deprecations:
542548

pandas/__init__.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"the C extensions first.".format(module))
3434

3535
from datetime import datetime
36-
from pandas.info import __doc__
3736

3837
# let init-time option registration happen
3938
import pandas.core.config_init
@@ -63,3 +62,45 @@
6362
v = get_versions()
6463
__version__ = v.get('closest-tag', v['version'])
6564
del get_versions, v
65+
66+
# module level doc-string
67+
__doc__ = """
68+
pandas - a powerful data analysis and manipulation library for Python
69+
=====================================================================
70+
71+
**pandas** is a Python package providing fast, flexible, and expressive data
72+
structures designed to make working with "relational" or "labeled" data both
73+
easy and intuitive. It aims to be the fundamental high-level building block for
74+
doing practical, **real world** data analysis in Python. Additionally, it has
75+
the broader goal of becoming **the most powerful and flexible open source data
76+
analysis / manipulation tool available in any language**. It is already well on
77+
its way toward this goal.
78+
79+
Main Features
80+
-------------
81+
Here are just a few of the things that pandas does well:
82+
83+
- Easy handling of missing data in floating point as well as non-floating
84+
point data
85+
- Size mutability: columns can be inserted and deleted from DataFrame and
86+
higher dimensional objects
87+
- Automatic and explicit data alignment: objects can be explicitly aligned
88+
to a set of labels, or the user can simply ignore the labels and let
89+
`Series`, `DataFrame`, etc. automatically align the data for you in
90+
computations
91+
- Powerful, flexible group by functionality to perform split-apply-combine
92+
operations on data sets, for both aggregating and transforming data
93+
- Make it easy to convert ragged, differently-indexed data in other Python
94+
and NumPy data structures into DataFrame objects
95+
- Intelligent label-based slicing, fancy indexing, and subsetting of large
96+
data sets
97+
- Intuitive merging and joining data sets
98+
- Flexible reshaping and pivoting of data sets
99+
- Hierarchical labeling of axes (possible to have multiple labels per tick)
100+
- Robust IO tools for loading data from flat files (CSV and delimited),
101+
Excel files, databases, and saving/loading data from the ultrafast HDF5
102+
format
103+
- Time series-specific functionality: date range generation and frequency
104+
conversion, moving window statistics, moving window linear regressions,
105+
date shifting and lagging, etc.
106+
"""

pandas/computation/api.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# flake8: noqa
22

33
from pandas.computation.eval import eval
4-
from pandas.computation.expr import Expr
4+
5+
6+
# deprecation, xref #13790
7+
def Expr(*args, **kwargs):
8+
import warnings
9+
10+
warnings.warn("pd.Expr is deprecated as it is not "
11+
"applicable to user code",
12+
FutureWarning, stacklevel=2)
13+
from pandas.computation.expr import Expr
14+
return Expr(*args, **kwargs)

pandas/core/api.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66

7-
from pandas.core.algorithms import factorize, match, unique, value_counts
7+
from pandas.core.algorithms import factorize, unique, value_counts
88
from pandas.types.missing import isnull, notnull
99
from pandas.core.categorical import Categorical
1010
from pandas.core.groupby import Grouper
@@ -17,7 +17,6 @@
1717
from pandas.core.frame import DataFrame
1818
from pandas.core.panel import Panel, WidePanel
1919
from pandas.core.panel4d import Panel4D
20-
from pandas.core.groupby import groupby
2120
from pandas.core.reshape import (pivot_simple as pivot, get_dummies,
2221
lreshape, wide_to_long)
2322

@@ -42,3 +41,24 @@
4241

4342
from pandas.core.config import (get_option, set_option, reset_option,
4443
describe_option, option_context, options)
44+
45+
46+
# deprecation, xref #13790
47+
def match(*args, **kwargs):
48+
import warnings
49+
50+
warnings.warn("pd.match() is deprecated and will be removed "
51+
"in a future version",
52+
FutureWarning, stacklevel=2)
53+
from pandas.core.algorithms import match
54+
return match(*args, **kwargs)
55+
56+
57+
def groupby(*args, **kwargs):
58+
import warnings
59+
60+
warnings.warn("pd.groupby() is deprecated and will be removed "
61+
"Please use the Series.groupby() or "
62+
"DataFrame.groupby() methods",
63+
FutureWarning, stacklevel=2)
64+
return args[0].groupby(*args[1:], **kwargs)

pandas/info.py

-20
This file was deleted.

pandas/io/api.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pandas.io.parsers import read_csv, read_table, read_fwf
88
from pandas.io.clipboard import read_clipboard
99
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
10-
from pandas.io.pytables import HDFStore, Term, get_store, read_hdf
10+
from pandas.io.pytables import HDFStore, get_store, read_hdf
1111
from pandas.io.json import read_json
1212
from pandas.io.html import read_html
1313
from pandas.io.sql import read_sql, read_sql_table, read_sql_query
@@ -17,3 +17,15 @@
1717
from pandas.io.pickle import read_pickle, to_pickle
1818
from pandas.io.packers import read_msgpack, to_msgpack
1919
from pandas.io.gbq import read_gbq
20+
21+
# deprecation, xref #13790
22+
def Term(*args, **kwargs):
23+
import warnings
24+
25+
warnings.warn("pd.Term is deprecated as it is not "
26+
"applicable to user code. Instead use in-line "
27+
"string expressions in the where clause when "
28+
"searching in HDFStore",
29+
FutureWarning, stacklevel=2)
30+
from pandas.io.pytables import Term
31+
return Term(*args, **kwargs)

pandas/tests/api/test_api.py

+36-13
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ class TestPDApi(Base, tm.TestCase):
5959
# these are already deprecated; awaiting removal
6060
deprecated_classes = ['WidePanel',
6161
'SparseTimeSeries', 'Panel4D',
62-
'SparseList']
62+
'SparseList', 'Expr', 'Term']
6363

6464
# these should be deprecated in the future
65-
deprecated_classes_in_future = ['Term', 'Panel']
66-
67-
# these should be removed from top-level namespace
68-
remove_classes_from_top_level_namespace = ['Expr']
65+
deprecated_classes_in_future = ['Panel']
6966

7067
# external modules exposed in pandas namespace
7168
modules = ['np', 'datetime']
@@ -75,7 +72,7 @@ class TestPDApi(Base, tm.TestCase):
7572
'date_range', 'eval',
7673
'factorize', 'get_dummies', 'get_store',
7774
'infer_freq', 'isnull', 'lreshape',
78-
'match', 'melt', 'notnull', 'offsets',
75+
'melt', 'notnull', 'offsets',
7976
'merge', 'merge_ordered', 'merge_asof',
8077
'period_range',
8178
'pivot', 'pivot_table', 'plot_params', 'qcut',
@@ -99,9 +96,6 @@ class TestPDApi(Base, tm.TestCase):
9996
funcs_to = ['to_datetime', 'to_msgpack',
10097
'to_numeric', 'to_pickle', 'to_timedelta']
10198

102-
# these should be deprecated in the future
103-
deprecated_funcs_in_future = ['pnow', 'groupby', 'info']
104-
10599
# these are already deprecated; awaiting removal
106100
deprecated_funcs = ['ewma', 'ewmcorr', 'ewmcov', 'ewmstd', 'ewmvar',
107101
'ewmvol', 'expanding_apply', 'expanding_corr',
@@ -114,7 +108,8 @@ class TestPDApi(Base, tm.TestCase):
114108
'rolling_kurt', 'rolling_max', 'rolling_mean',
115109
'rolling_median', 'rolling_min', 'rolling_quantile',
116110
'rolling_skew', 'rolling_std', 'rolling_sum',
117-
'rolling_var', 'rolling_window', 'ordered_merge']
111+
'rolling_var', 'rolling_window', 'ordered_merge',
112+
'pnow', 'match', 'groupby']
118113

119114
def test_api(self):
120115

@@ -123,11 +118,9 @@ def test_api(self):
123118
self.modules + self.deprecated_modules +
124119
self.classes + self.deprecated_classes +
125120
self.deprecated_classes_in_future +
126-
self.remove_classes_from_top_level_namespace +
127121
self.funcs + self.funcs_option +
128122
self.funcs_read + self.funcs_to +
129-
self.deprecated_funcs +
130-
self.deprecated_funcs_in_future,
123+
self.deprecated_funcs,
131124
self.ignored)
132125

133126

@@ -225,3 +218,33 @@ def test_deprecation_access_obj(self):
225218
with tm.assert_produces_warning(FutureWarning,
226219
check_stacklevel=False):
227220
pd.datetools.monthEnd
221+
222+
223+
class TestTopLevelDeprecations(tm.TestCase):
224+
# top-level API deprecations
225+
# GH 13790
226+
227+
def test_pnow(self):
228+
with tm.assert_produces_warning(FutureWarning,
229+
check_stacklevel=False):
230+
pd.pnow(freq='M')
231+
232+
def test_term(self):
233+
with tm.assert_produces_warning(FutureWarning,
234+
check_stacklevel=False):
235+
pd.Term('index>=date')
236+
237+
def test_expr(self):
238+
with tm.assert_produces_warning(FutureWarning,
239+
check_stacklevel=False):
240+
pd.Expr('2>1')
241+
242+
def test_match(self):
243+
with tm.assert_produces_warning(FutureWarning,
244+
check_stacklevel=False):
245+
pd.match([1, 2, 3], [1])
246+
247+
def test_groupby(self):
248+
with tm.assert_produces_warning(FutureWarning,
249+
check_stacklevel=False):
250+
pd.groupby(pd.Series([1, 2, 3]), [1, 1, 1])

pandas/tests/scalar/test_period.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -864,17 +864,11 @@ def test_properties_nat(self):
864864
self.assertTrue(np.isnan(getattr(t_nat, f)))
865865

866866
def test_pnow(self):
867-
dt = datetime.now()
868867

869-
val = period.pnow('D')
870-
exp = Period(dt, freq='D')
871-
self.assertEqual(val, exp)
872-
873-
val2 = period.pnow('2D')
874-
exp2 = Period(dt, freq='2D')
875-
self.assertEqual(val2, exp2)
876-
self.assertEqual(val.ordinal, val2.ordinal)
877-
self.assertEqual(val.ordinal, exp2.ordinal)
868+
# deprecation, xref #13790
869+
with tm.assert_produces_warning(FutureWarning,
870+
check_stacklevel=False):
871+
period.pnow('D')
878872

879873
def test_constructor_corner(self):
880874
expected = Period('2007-01', freq='2M')

pandas/tseries/period.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,13 @@ def _make_field_arrays(*fields):
11441144

11451145

11461146
def pnow(freq=None):
1147-
return Period(datetime.now(), freq=freq)
1147+
# deprecation, xref #13790
1148+
import warnings
1149+
1150+
warnings.warn("pd.pnow() and pandas.tseries.period.pnow() "
1151+
"are deprecated. Please use Period.now()",
1152+
FutureWarning, stacklevel=2)
1153+
return Period.now(freq=freq)
11481154

11491155

11501156
def period_range(start=None, end=None, periods=None, freq='D', name=None):

0 commit comments

Comments
 (0)