Skip to content

Commit 78f3c80

Browse files
committed
Merge pull request #10890 from jreback/depr
DEPR: Bunch o deprecation removals
2 parents ea906db + 5e82396 commit 78f3c80

16 files changed

+135
-84
lines changed

doc/source/whatsnew/v0.17.0.txt

+32
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Highlights include:
3737
- Support for ``Series.dt.strftime`` to generate formatted strings for datetime-likes, see :ref:`here <whatsnew_0170.strftime>`
3838
- Development installed versions of pandas will now have ``PEP440`` compliant version strings (:issue:`9518`)
3939
- Support for reading SAS xport files, see :ref:`here <whatsnew_0170.enhancements.sas_xport>`
40+
- Removal of the automatic TimeSeries broadcasting, deprecated since 0.8.0, see :ref:`here <whatsnew_0170.prior_deprecations>`
4041

4142
Check the :ref:`API Changes <whatsnew_0170.api>` and :ref:`deprecations <whatsnew_0170.deprecations>` before updating.
4243

@@ -663,6 +664,7 @@ Deprecations
663664
can easily be replaced by using the ``add`` and ``mul`` methods:
664665
``DataFrame.add(other, fill_value=0)`` and ``DataFrame.mul(other, fill_value=1.)``
665666
(:issue:`10735`).
667+
- ``TimeSeries`` deprecated in favor of ``Series`` (note that this has been alias since 0.13.0), (:issue:`10890`)
666668

667669
.. _whatsnew_0170.prior_deprecations:
668670

@@ -672,6 +674,36 @@ Removal of prior version deprecations/changes
672674
- Remove use of some deprecated numpy comparison operations, mainly in tests. (:issue:`10569`)
673675
- Removal of ``na_last`` parameters from ``Series.order()`` and ``Series.sort()``, in favor of ``na_position``, xref (:issue:`5231`)
674676
- Remove of ``percentile_width`` from ``.describe()``, in favor of ``percentiles``. (:issue:`7088`)
677+
- Removal of ``colSpace`` parameter from ``DataFrame.to_string()``, in favor of ``col_space``, circa 0.8.0 version.
678+
- Removal of automatic time-series broadcasting (:issue:`2304`)
679+
680+
.. ipython :: python
681+
682+
np.random.seed(1234)
683+
df = DataFrame(np.random.randn(5,2),columns=list('AB'),index=date_range('20130101',periods=5))
684+
df
685+
686+
Previously
687+
688+
.. code-block:: python
689+
690+
In [3]: df + df.A
691+
FutureWarning: TimeSeries broadcasting along DataFrame index by default is deprecated.
692+
Please use DataFrame.<op> to explicitly broadcast arithmetic operations along the index
693+
694+
Out[3]:
695+
A B
696+
2013-01-01 0.942870 -0.719541
697+
2013-01-02 2.865414 1.120055
698+
2013-01-03 -1.441177 0.166574
699+
2013-01-04 1.719177 0.223065
700+
2013-01-05 0.031393 -2.226989
701+
702+
Current
703+
704+
.. ipython :: python
705+
706+
df.add(df.A,axis='index')
675707

676708
.. _whatsnew_0170.performance:
677709

pandas/core/frame.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def to_stata(
13961396
writer.write_file()
13971397

13981398
@Appender(fmt.docstring_to_string, indents=1)
1399-
def to_string(self, buf=None, columns=None, col_space=None, colSpace=None,
1399+
def to_string(self, buf=None, columns=None, col_space=None,
14001400
header=True, index=True, na_rep='NaN', formatters=None,
14011401
float_format=None, sparsify=None, index_names=True,
14021402
justify=None, line_width=None, max_rows=None, max_cols=None,
@@ -1405,11 +1405,6 @@ def to_string(self, buf=None, columns=None, col_space=None, colSpace=None,
14051405
Render a DataFrame to a console-friendly tabular output.
14061406
"""
14071407

1408-
if colSpace is not None: # pragma: no cover
1409-
warnings.warn("colSpace is deprecated, use col_space",
1410-
FutureWarning)
1411-
col_space = colSpace
1412-
14131408
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
14141409
col_space=col_space, na_rep=na_rep,
14151410
formatters=formatters,
@@ -3359,16 +3354,7 @@ def _combine_series_infer(self, other, func, level=None, fill_value=None):
33593354
return self._constructor(data=self._series, index=self.index,
33603355
columns=self.columns)
33613356

3362-
# teeny hack because one does DataFrame + TimeSeries all the time
3363-
if self.index.is_all_dates and other.index.is_all_dates:
3364-
warnings.warn(("TimeSeries broadcasting along DataFrame index "
3365-
"by default is deprecated. Please use "
3366-
"DataFrame.<op> to explicitly broadcast arithmetic "
3367-
"operations along the index"),
3368-
FutureWarning)
3369-
return self._combine_match_index(other, func, level=level, fill_value=fill_value)
3370-
else:
3371-
return self._combine_match_columns(other, func, level=level, fill_value=fill_value)
3357+
return self._combine_match_columns(other, func, level=level, fill_value=fill_value)
33723358

33733359
def _combine_match_index(self, other, func, level=None, fill_value=None):
33743360
left, right = self.align(other, join='outer', axis=0, level=level, copy=False)

pandas/core/series.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def _set_axis(self, axis, labels, fastpath=False):
261261

262262
is_all_dates = labels.is_all_dates
263263
if is_all_dates:
264+
264265
if not isinstance(labels, (DatetimeIndex, PeriodIndex, TimedeltaIndex)):
265266
labels = DatetimeIndex(labels)
266267

@@ -2779,7 +2780,14 @@ def _try_cast(arr, take_fast_path):
27792780
return subarr
27802781

27812782
# backwards compatiblity
2782-
TimeSeries = Series
2783+
class TimeSeries(Series):
2784+
2785+
def __init__(self, *args, **kwargs):
2786+
# deprecation TimeSeries, #10890
2787+
warnings.warn("TimeSeries is deprecated. Please use Series",
2788+
FutureWarning, stacklevel=2)
2789+
2790+
super(TimeSeries, self).__init__(*args, **kwargs)
27832791

27842792
#----------------------------------------------------------------------
27852793
# Add plotting methods to Series

pandas/io/pytables.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import os
1414

1515
import numpy as np
16-
from pandas import (Series, TimeSeries, DataFrame, Panel, Panel4D, Index,
16+
import pandas as pd
17+
from pandas import (Series, DataFrame, Panel, Panel4D, Index,
1718
MultiIndex, Int64Index, Timestamp)
1819
from pandas.sparse.api import SparseSeries, SparseDataFrame, SparsePanel
1920
from pandas.sparse.array import BlockIndex, IntIndex
@@ -164,7 +165,7 @@ class DuplicateWarning(Warning):
164165

165166
Series: u('series'),
166167
SparseSeries: u('sparse_series'),
167-
TimeSeries: u('series'),
168+
pd.TimeSeries: u('series'),
168169
DataFrame: u('frame'),
169170
SparseDataFrame: u('sparse_frame'),
170171
Panel: u('wide'),

pandas/io/tests/generate_legacy_storage_files.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
""" self-contained to write legacy storage (pickle/msgpack) files """
22
from __future__ import print_function
33
from distutils.version import LooseVersion
4-
from pandas import (Series, TimeSeries, DataFrame, Panel,
5-
SparseSeries, SparseTimeSeries, SparseDataFrame, SparsePanel,
4+
from pandas import (Series, DataFrame, Panel,
5+
SparseSeries, SparseDataFrame, SparsePanel,
66
Index, MultiIndex, PeriodIndex, bdate_range, to_msgpack,
77
date_range, period_range, bdate_range, Timestamp, Categorical,
88
Period)
@@ -36,7 +36,7 @@ def _create_sp_tsseries():
3636
arr[-1:] = nan
3737

3838
date_index = bdate_range('1/1/2011', periods=len(arr))
39-
bseries = SparseTimeSeries(arr, index=date_index, kind='block')
39+
bseries = SparseSeries(arr, index=date_index, kind='block')
4040
bseries.name = 'btsseries'
4141
return bseries
4242

@@ -78,7 +78,7 @@ def create_data():
7878
series = dict(float=Series(data['A']),
7979
int=Series(data['B']),
8080
mixed=Series(data['E']),
81-
ts=TimeSeries(np.arange(10).astype(np.int64), index=date_range('20130101',periods=10)),
81+
ts=Series(np.arange(10).astype(np.int64), index=date_range('20130101',periods=10)),
8282
mi=Series(np.arange(5).astype(np.float64),
8383
index=MultiIndex.from_tuples(tuple(zip(*[[1, 1, 2, 2, 2], [3, 4, 3, 4, 5]])),
8484
names=['one', 'two'])),

pandas/sparse/series.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from numpy import nan, ndarray
99
import numpy as np
10-
10+
import warnings
1111
import operator
1212

1313
from pandas.core.common import isnull, _values_from_object, _maybe_match_name
@@ -770,4 +770,11 @@ def from_coo(cls, A, dense_index=False):
770770
bool_method=None, use_numexpr=False, force=True)
771771

772772
# backwards compatiblity
773-
SparseTimeSeries = SparseSeries
773+
class SparseTimeSeries(SparseSeries):
774+
775+
def __init__(self, *args, **kwargs):
776+
# deprecation TimeSeries, #10890
777+
warnings.warn("SparseTimeSeries is deprecated. Please use SparseSeries",
778+
FutureWarning, stacklevel=2)
779+
780+
super(SparseTimeSeries, self).__init__(*args, **kwargs)

pandas/sparse/tests/test_sparse.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import pandas.sparse.frame as spf
3131

3232
from pandas._sparse import BlockIndex, IntIndex
33-
from pandas.sparse.api import (SparseSeries, SparseTimeSeries,
33+
from pandas.sparse.api import (SparseSeries,
3434
SparseDataFrame, SparsePanel,
3535
SparseArray)
3636
import pandas.tests.test_frame as test_frame
@@ -160,6 +160,12 @@ def test_iteration_and_str(self):
160160
[x for x in self.bseries]
161161
str(self.bseries)
162162

163+
def test_TimeSeries_deprecation(self):
164+
165+
# deprecation TimeSeries, #10890
166+
with tm.assert_produces_warning(FutureWarning):
167+
pd.SparseTimeSeries(1,index=pd.date_range('20130101',periods=3))
168+
163169
def test_construct_DataFrame_with_sp_series(self):
164170
# it works!
165171
df = DataFrame({'col': self.bseries})
@@ -258,7 +264,7 @@ def _check_const(sparse, name):
258264
# Sparse time series works
259265
date_index = bdate_range('1/1/2000', periods=len(self.bseries))
260266
s5 = SparseSeries(self.bseries, index=date_index)
261-
tm.assertIsInstance(s5, SparseTimeSeries)
267+
tm.assertIsInstance(s5, SparseSeries)
262268

263269
# pass Series
264270
bseries2 = SparseSeries(self.bseries.to_dense())
@@ -1189,14 +1195,19 @@ def _compare_to_dense(a, b, da, db, op):
11891195
frame['A'].reindex(fidx[::2]),
11901196
SparseSeries([], index=[])]
11911197

1192-
for op in ops:
1198+
for op in opnames:
11931199
_compare_to_dense(frame, frame[::2], frame.to_dense(),
1194-
frame[::2].to_dense(), op)
1200+
frame[::2].to_dense(), getattr(operator, op))
1201+
1202+
# 2304, no auto-broadcasting
11951203
for i, s in enumerate(series):
1204+
f = lambda a, b: getattr(a,op)(b,axis='index')
11961205
_compare_to_dense(frame, s, frame.to_dense(),
1197-
s.to_dense(), op)
1198-
_compare_to_dense(s, frame, s.to_dense(),
1199-
frame.to_dense(), op)
1206+
s.to_dense(), f)
1207+
1208+
# rops are not implemented
1209+
#_compare_to_dense(s, frame, s.to_dense(),
1210+
# frame.to_dense(), f)
12001211

12011212
# cross-sectional operations
12021213
series = [frame.xs(fidx[0]),

pandas/tests/test_frame.py

+34-33
Original file line numberDiff line numberDiff line change
@@ -6039,46 +6039,47 @@ def test_combineSeries(self):
60396039
#added = self.mixed_int + (100*series).astype('int32')
60406040
#_check_mixed_int(added, dtype = dict(A = 'int32', B = 'float64', C = 'int32', D = 'int64'))
60416041

6042-
# TimeSeries
6043-
buf = StringIO()
6044-
tmp = sys.stderr
6045-
sys.stderr = buf
60466042

6047-
try:
6048-
ts = self.tsframe['A']
6049-
added = self.tsframe + ts
6050-
6051-
for key, col in compat.iteritems(self.tsframe):
6052-
result = col + ts
6053-
assert_series_equal(added[key], result, check_names=False)
6054-
self.assertEqual(added[key].name, key)
6055-
if col.name == ts.name:
6056-
self.assertEqual(result.name, 'A')
6057-
else:
6058-
self.assertTrue(result.name is None)
6043+
# TimeSeries
6044+
ts = self.tsframe['A']
6045+
6046+
# 10890
6047+
# we no longer allow auto timeseries broadcasting
6048+
# and require explict broadcasting
6049+
added = self.tsframe.add(ts, axis='index')
6050+
6051+
for key, col in compat.iteritems(self.tsframe):
6052+
result = col + ts
6053+
assert_series_equal(added[key], result, check_names=False)
6054+
self.assertEqual(added[key].name, key)
6055+
if col.name == ts.name:
6056+
self.assertEqual(result.name, 'A')
6057+
else:
6058+
self.assertTrue(result.name is None)
60596059

6060-
smaller_frame = self.tsframe[:-5]
6061-
smaller_added = smaller_frame + ts
6060+
smaller_frame = self.tsframe[:-5]
6061+
smaller_added = smaller_frame.add(ts, axis='index')
60626062

6063-
self.assertTrue(smaller_added.index.equals(self.tsframe.index))
6063+
self.assertTrue(smaller_added.index.equals(self.tsframe.index))
60646064

6065-
smaller_ts = ts[:-5]
6066-
smaller_added2 = self.tsframe + smaller_ts
6067-
assert_frame_equal(smaller_added, smaller_added2)
6065+
smaller_ts = ts[:-5]
6066+
smaller_added2 = self.tsframe.add(smaller_ts, axis='index')
6067+
assert_frame_equal(smaller_added, smaller_added2)
60686068

6069-
# length 0
6070-
result = self.tsframe + ts[:0]
6069+
# length 0, result is all-nan
6070+
result = self.tsframe.add(ts[:0], axis='index')
6071+
expected = DataFrame(np.nan,index=self.tsframe.index,columns=self.tsframe.columns)
6072+
assert_frame_equal(result, expected)
60716073

6072-
# Frame is length 0
6073-
result = self.tsframe[:0] + ts
6074-
self.assertEqual(len(result), 0)
6074+
# Frame is all-nan
6075+
result = self.tsframe[:0].add(ts, axis='index')
6076+
expected = DataFrame(np.nan,index=self.tsframe.index,columns=self.tsframe.columns)
6077+
assert_frame_equal(result, expected)
60756078

6076-
# empty but with non-empty index
6077-
frame = self.tsframe[:1].reindex(columns=[])
6078-
result = frame * ts
6079-
self.assertEqual(len(result), len(ts))
6080-
finally:
6081-
sys.stderr = tmp
6079+
# empty but with non-empty index
6080+
frame = self.tsframe[:1].reindex(columns=[])
6081+
result = frame.mul(ts,axis='index')
6082+
self.assertEqual(len(result), len(ts))
60826083

60836084
def test_combineFunc(self):
60846085
result = self.frame * 2

pandas/tests/test_groupby.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,8 @@ def test_groupby_bounds_check(self):
502502
self.assertRaises(AssertionError, pd.algos.groupby_object,a, b)
503503

504504
def test_groupby_grouper_f_sanity_checked(self):
505-
import pandas as pd
506505
dates = date_range('01-Jan-2013', periods=12, freq='MS')
507-
ts = pd.TimeSeries(np.random.randn(12), index=dates)
506+
ts = Series(np.random.randn(12), index=dates)
508507

509508
# GH3035
510509
# index.map is used to apply grouper to the index

pandas/tests/test_series.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ def test_astype(self):
666666
self.assertEqual(astyped.dtype, dtype)
667667
self.assertEqual(astyped.name, s.name)
668668

669+
def test_TimeSeries_deprecation(self):
670+
671+
# deprecation TimeSeries, #10890
672+
with tm.assert_produces_warning(FutureWarning):
673+
pd.TimeSeries(1,index=date_range('20130101',periods=3))
674+
669675
def test_constructor(self):
670676
# Recognize TimeSeries
671677
self.assertTrue(self.ts.is_time_series)
@@ -4515,10 +4521,10 @@ def test_operators_frame(self):
45154521
# rpow does not work with DataFrame
45164522
df = DataFrame({'A': self.ts})
45174523

4518-
tm.assert_almost_equal(self.ts + self.ts, (self.ts + df)['A'])
4519-
tm.assert_almost_equal(self.ts ** self.ts, (self.ts ** df)['A'])
4520-
tm.assert_almost_equal(self.ts < self.ts, (self.ts < df)['A'])
4521-
tm.assert_almost_equal(self.ts / self.ts, (self.ts / df)['A'])
4524+
tm.assert_almost_equal(self.ts + self.ts, self.ts + df['A'])
4525+
tm.assert_almost_equal(self.ts ** self.ts, self.ts ** df['A'])
4526+
tm.assert_almost_equal(self.ts < self.ts, self.ts < df['A'])
4527+
tm.assert_almost_equal(self.ts / self.ts, self.ts / df['A'])
45224528

45234529
def test_operators_combine(self):
45244530
def _check_fill(meth, op, a, b, fill_value=0):

pandas/tests/test_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pandas.compat import range, lrange, u, unichr
1717
import pandas.compat as compat
18-
from pandas import (Index, Series, TimeSeries, DataFrame, isnull, notnull,
18+
from pandas import (Index, Series, DataFrame, isnull, notnull,
1919
bdate_range, date_range, MultiIndex)
2020
import pandas.core.common as com
2121

pandas/tseries/tests/test_period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from numpy.random import randn
2525
from pandas.compat import range, lrange, lmap, zip
2626

27-
from pandas import Series, TimeSeries, DataFrame, _np_version_under1p9
27+
from pandas import Series, DataFrame, _np_version_under1p9
2828
from pandas import tslib
2929
from pandas.util.testing import(assert_series_equal, assert_almost_equal,
3030
assertRaisesRegexp)
@@ -1191,7 +1191,7 @@ def test_hash_error(self):
11911191
def test_make_time_series(self):
11921192
index = PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')
11931193
series = Series(1, index=index)
1194-
tm.assertIsInstance(series, TimeSeries)
1194+
tm.assertIsInstance(series, Series)
11951195

11961196
def test_astype(self):
11971197
idx = period_range('1990', '2009', freq='A')

0 commit comments

Comments
 (0)