Skip to content

Commit 2fece99

Browse files
committed
DEPR: deprecate some top-level non-used functions
closes pandas-dev#13790 pd.pnow pd.groupby pd.match pd.Term pd.Expr remove info.py
1 parent 37fe2c4 commit 2fece99

File tree

8 files changed

+91
-39
lines changed

8 files changed

+91
-39
lines changed

doc/source/whatsnew/v0.20.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ Deprecations
536536
- 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`)
537537
- ``Series/DataFrame/Panel.consolidate()`` been deprecated as a public method. (:issue:`15483`)
538538
- ``FrozenList`` addition (new object and inplace) have been deprecated in favor of the ``.union()`` method. (:issue: `15475`)
539+
- The following top-level pandas functions have been deprecated and will be removed in a future version (:issue:`13790`)
540+
* ``pd.now()``, replaced by a direct import from ``pandas.tseries.period``
541+
* ``pd.Term``, replaced by a direct import from ``pandas.io.pytables``
542+
* ``pd.Expr``, replaced by a direct import from ``pandas.computation.expr``
543+
* ``pd.match()``, replaced by a direct import from ``pandas.core.algorithms``
544+
* ``pd.groupby()``, replaced by using the ``.groupby()`` method directly on a ``Series/DataFrame``
539545

540546
.. _whatsnew_0200.prior_deprecations:
541547

pandas/__init__.py

-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

pandas/computation/api.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
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. Please import from pandas.computation.expr",
11+
FutureWarning, stacklevel=2)
12+
from pandas.computation.expr import Expr
13+
return Expr(*args, **kwargs)

pandas/core/api.py

+19-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,21 @@
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. Please use pandas.core.algorithms.match()",
51+
FutureWarning, stacklevel=2)
52+
from pandas.core.algorithms import match
53+
return match(*args, **kwargs)
54+
55+
56+
def groupby(*args, **kwargs):
57+
import warnings
58+
59+
warnings.warn("pd.groupby() is deprecated. Please use the .groupby() method",
60+
FutureWarning, stacklevel=2)
61+
return args[0].groupby(*args[1:], **kwargs)

pandas/info.py

-20
This file was deleted.

pandas/io/api.py

+10-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,12 @@
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. Please import from pandas.io.pytables",
26+
FutureWarning, stacklevel=2)
27+
from pandas.io.pytables import Term
28+
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/tseries/api.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77
from pandas.tseries.index import DatetimeIndex, date_range, bdate_range
88
from pandas.tseries.frequencies import infer_freq
99
from pandas.tseries.tdi import Timedelta, TimedeltaIndex, timedelta_range
10-
from pandas.tseries.period import Period, PeriodIndex, period_range, pnow
10+
from pandas.tseries.period import Period, PeriodIndex, period_range
1111
from pandas.tseries.resample import TimeGrouper
1212
from pandas.tseries.timedeltas import to_timedelta
1313
from pandas.lib import NaT
1414
import pandas.tseries.offsets as offsets
15+
16+
# deprecation, xref #13790
17+
def pnow(freq=None):
18+
import warnings
19+
20+
warnings.warn("pd.pnow() is deprecated. Please use pandas.tseries.period.pnow()",
21+
FutureWarning, stacklevel=2)
22+
from pandas.tseries.period import pnow
23+
return pnow(freq=freq)

0 commit comments

Comments
 (0)