Skip to content

Commit cc1aa69

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 d0a281f commit cc1aa69

File tree

8 files changed

+86
-27
lines changed

8 files changed

+86
-27
lines changed

doc/source/whatsnew/v0.20.0.txt

+6
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ Deprecations
534534
- ``Series.sortlevel`` and ``DataFrame.sortlevel`` have been deprecated in favor of ``Series.sort_index`` and ``DataFrame.sort_index`` (:issue:`15099`)
535535
- 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`)
536536
- ``Series/DataFrame/Panel.consolidate()`` been deprecated as a public method. (:issue:`15483`)
537+
- The following top-level pandas functions have been deprecated and will be removed in a future version (:issue:`13790`)
538+
* ``pd.now()``, replaced by a direct import from ``pandas.tseries.period``
539+
* ``pd.Term``, replaced by a direct import from ``pandas.io.pytables``
540+
* ``pd.Expr``, replaced by a direct import from ``pandas.computation.expr``
541+
* ``pd.match()``, replaced by a direct import from ``pandas.core.algorithms``
542+
* ``pd.groupby()``, replaced by using the ``.groupby()`` method directly on a ``Series/DataFrame``
537543

538544
.. _whatsnew_0200.prior_deprecations:
539545

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

+31-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TestPDApi(Base, tm.TestCase):
100100
'to_numeric', 'to_pickle', 'to_timedelta']
101101

102102
# these should be deprecated in the future
103-
deprecated_funcs_in_future = ['pnow', 'groupby', 'info']
103+
deprecated_funcs_in_future = ['pnow', 'groupby']
104104

105105
# these are already deprecated; awaiting removal
106106
deprecated_funcs = ['ewma', 'ewmcorr', 'ewmcov', 'ewmstd', 'ewmvar',
@@ -225,3 +225,33 @@ def test_deprecation_access_obj(self):
225225
with tm.assert_produces_warning(FutureWarning,
226226
check_stacklevel=False):
227227
pd.datetools.monthEnd
228+
229+
230+
class TestTopLevelDeprecations(tm.TestCase):
231+
# top-level API deprecations
232+
# GH 13790
233+
234+
def test_pnow(self):
235+
with tm.assert_produces_warning(FutureWarning,
236+
check_stacklevel=False):
237+
pd.pnow(freq='M')
238+
239+
def test_term(self):
240+
with tm.assert_produces_warning(FutureWarning,
241+
check_stacklevel=False):
242+
pd.Term('index>=date')
243+
244+
def test_expr(self):
245+
with tm.assert_produces_warning(FutureWarning,
246+
check_stacklevel=False):
247+
pd.Expr('2>1')
248+
249+
def test_match(self):
250+
with tm.assert_produces_warning(FutureWarning,
251+
check_stacklevel=False):
252+
pd.match([1, 2, 3], [1])
253+
254+
def test_groupby(self):
255+
with tm.assert_produces_warning(FutureWarning,
256+
check_stacklevel=False):
257+
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)