Skip to content

Commit e73c54d

Browse files
committed
DOC/ENH: Deprecate iterkv + add docs
1 parent e957fbc commit e73c54d

File tree

7 files changed

+51
-25
lines changed

7 files changed

+51
-25
lines changed

doc/source/release.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ pandas 0.13
4747

4848
**API Changes**
4949

50+
- ``pandas`` now is Python 2/3 compatible without the need for 2to3 thanks to
51+
@jtratner. As a result, pandas now uses iterators more extensively. This
52+
also led to the introduction of substantive parts of the Benjamin
53+
Peterson's ``six`` library into compat. (:issue:`4384`, :issue:`4375`,
54+
:issue:`4372`)
55+
- ``pandas.util.py3compat`` has been merged into ``pandas.util.compat`` and
56+
removed from pandas. It contains both list and iterator versions of range,
57+
filter, map and zip, plus other necessary elements for Python 3
58+
compatibility. ``lmap``, ``lzip``, ``lrange`` and ``lfilter`` all produce
59+
lists instead of iterators, for compatibility with ``numpy``, subscripting
60+
and ``pandas`` constructors.(:issue:`4384`, :issue:`4375`, :issue:`4372`)
61+
- deprecated ``iterkv``, which will be removed in a future release (was just
62+
an alias of iteritems used to get around ``2to3``'s changes).
63+
(:issue:`4384`, :issue:`4375`, :issue:`4372`)
64+
5065
**Experimental Features**
5166

5267
**Bug Fixes**

doc/source/v0.13.0.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ API changes
1212
- ``read_excel`` now supports an integer in its ``sheetname`` argument giving
1313
the index of the sheet to read in (:issue:`4301`).
1414
- Text parser now treats anything that reads like inf ("inf", "Inf", "-Inf",
15-
"iNf", etc.) to infinity. (:issue:`4220`, :issue:`4219`), affecting
15+
"iNf", etc.) as infinity. (:issue:`4220`, :issue:`4219`), affecting
1616
``read_table``, ``read_csv``, etc.
17+
- ``pandas`` now is Python 2/3 compatible without the need for 2to3 thanks to
18+
@jtratner. As a result, pandas now uses iterators more extensively. This
19+
also led to the introduction of substantive parts of the Benjamin
20+
Peterson's ``six`` library into compat. (:issue:`4384`, :issue:`4375`,
21+
:issue:`4372`)
22+
- ``pandas.util.py3compat`` has been merged into ``pandas.util.compat`` and
23+
removed from pandas. It contains both list and iterator versions of range,
24+
filter, map and zip, plus other necessary elements for Python 3
25+
compatibility. ``lmap``, ``lzip``, ``lrange`` and ``lfilter`` all produce
26+
lists instead of iterators, for compatibility with ``numpy``, subscripting
27+
and ``pandas`` constructors.(:issue:`4384`, :issue:`4375`, :issue:`4372`)
28+
- deprecated ``iterkv``, which will be removed in a future release (was just
29+
an alias of iteritems used to get around ``2to3``'s changes).
30+
(:issue:`4384`, :issue:`4375`, :issue:`4372`)
1731

1832
Enhancements
1933
~~~~~~~~~~~~

pandas/core/frame.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import operator
1818
import sys
1919
import collections
20+
import warnings
2021

2122
from numpy import nan as NA
2223
import numpy as np
@@ -564,14 +565,12 @@ def _wrap_array(self, arr, axes, copy=False):
564565

565566
@property
566567
def _verbose_info(self):
567-
import warnings
568568
warnings.warn('The _verbose_info property will be removed in version '
569569
'0.13. please use "max_info_rows"', FutureWarning)
570570
return get_option('display.max_info_rows') is None
571571

572572
@_verbose_info.setter
573573
def _verbose_info(self, value):
574-
import warnings
575574
warnings.warn('The _verbose_info property will be removed in version '
576575
'0.13. please use "max_info_rows"', FutureWarning)
577576

@@ -786,7 +785,6 @@ def itertuples(self, index=True):
786785
arrays.extend(self.iloc[:, k] for k in range(len(self.columns)))
787786
return zip(*arrays)
788787

789-
iterkv = iteritems
790788
if compat.PY3: # pragma: no cover
791789
items = iteritems
792790

@@ -976,7 +974,6 @@ def to_dict(self, outtype='dict'):
976974
-------
977975
result : dict like {column -> {index -> value}}
978976
"""
979-
import warnings
980977
if not self.columns.is_unique:
981978
warnings.warn("DataFrame columns are not unique, some "
982979
"columns will be omitted.", UserWarning)
@@ -1391,7 +1388,6 @@ def to_csv(self, path_or_buf, sep=",", na_rep='', float_format=None,
13911388
or new (expanded format) if False)
13921389
"""
13931390
if nanRep is not None: # pragma: no cover
1394-
import warnings
13951391
warnings.warn("nanRep is deprecated, use na_rep",
13961392
FutureWarning)
13971393
na_rep = nanRep
@@ -1527,7 +1523,6 @@ def to_string(self, buf=None, columns=None, col_space=None, colSpace=None,
15271523
"""
15281524
Render a DataFrame to a console-friendly tabular output.
15291525
"""
1530-
import warnings
15311526
if force_unicode is not None: # pragma: no cover
15321527
warnings.warn("force_unicode is deprecated, it will have no "
15331528
"effect", FutureWarning)
@@ -1576,7 +1571,6 @@ def to_html(self, buf=None, columns=None, col_space=None, colSpace=None,
15761571
Render a DataFrame as an HTML table.
15771572
"""
15781573

1579-
import warnings
15801574
if force_unicode is not None: # pragma: no cover
15811575
warnings.warn("force_unicode is deprecated, it will have no "
15821576
"effect", FutureWarning)
@@ -1615,7 +1609,6 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None,
16151609
You can splice this into a LaTeX document.
16161610
"""
16171611

1618-
import warnings
16191612
if force_unicode is not None: # pragma: no cover
16201613
warnings.warn("force_unicode is deprecated, it will have no "
16211614
"effect", FutureWarning)
@@ -2014,7 +2007,6 @@ def _getitem_array(self, key):
20142007
# go with the __setitem__ behavior since that is more consistent
20152008
# with all other indexing behavior
20162009
if isinstance(key, Series) and not key.index.equals(self.index):
2017-
import warnings
20182010
warnings.warn("Boolean Series key will be reindexed to match "
20192011
"DataFrame index.", UserWarning)
20202012
elif len(key) != len(self.index):
@@ -3194,7 +3186,6 @@ def sort(self, columns=None, column=None, axis=0, ascending=True,
31943186
sorted : DataFrame
31953187
"""
31963188
if column is not None: # pragma: no cover
3197-
import warnings
31983189
warnings.warn("column is deprecated, use columns", FutureWarning)
31993190
columns = column
32003191
return self.sort_index(by=columns, axis=axis, ascending=ascending,
@@ -3576,13 +3567,11 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
35763567
raise AssertionError("'to_replace' must be 'None' if 'regex' is "
35773568
"not a bool")
35783569
if method is not None:
3579-
from warnings import warn
3580-
warn('the "method" argument is deprecated and will be removed in'
3570+
warnings.warn('the "method" argument is deprecated and will be removed in'
35813571
'v0.13; this argument has no effect')
35823572

35833573
if axis is not None:
3584-
from warnings import warn
3585-
warn('the "axis" argument is deprecated and will be removed in'
3574+
warnings.warn('the "axis" argument is deprecated and will be removed in'
35863575
'v0.13; this argument has no effect')
35873576

35883577
self._consolidate_inplace()
@@ -3717,7 +3706,6 @@ def interpolate(self, to_replace, method='pad', axis=0, inplace=False,
37173706
--------
37183707
reindex, replace, fillna
37193708
"""
3720-
from warnings import warn
37213709
warn('DataFrame.interpolate will be removed in v0.13, please use '
37223710
'either DataFrame.fillna or DataFrame.replace instead',
37233711
FutureWarning)
@@ -3867,7 +3855,6 @@ def _combine_series_infer(self, other, func, fill_value=None):
38673855

38683856
# teeny hack because one does DataFrame + TimeSeries all the time
38693857
if self.index.is_all_dates and other.index.is_all_dates:
3870-
import warnings
38713858
warnings.warn(("TimeSeries broadcasting along DataFrame index "
38723859
"by default is deprecated. Please use "
38733860
"DataFrame.<op> to explicitly broadcast arithmetic "

pandas/core/generic.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pylint: disable=W0231,E1101
2-
2+
import warnings
33
from pandas.util import compat
44
import numpy as np
55
import pandas.lib as lib
@@ -40,13 +40,11 @@ def to_pickle(self, path):
4040
return to_pickle(self, path)
4141

4242
def save(self, path): # TODO remove in 0.13
43-
import warnings
4443
from pandas.io.pickle import to_pickle
4544
warnings.warn("save is deprecated, use to_pickle", FutureWarning)
4645
return to_pickle(self, path)
4746

4847
def load(self, path): # TODO remove in 0.13
49-
import warnings
5048
from pandas.io.pickle import read_pickle
5149
warnings.warn("load is deprecated, use pd.read_pickle", FutureWarning)
5250
return read_pickle(path)
@@ -717,6 +715,13 @@ def __delitem__(self, key):
717715
except KeyError:
718716
pass
719717

718+
# originally used to get around 2to3's changes to iteritems.
719+
# Now unnecessary.
720+
def iterkv(self, *args, **kwargs):
721+
warnings.warn("iterkv is deprecated and will be removed in a future "
722+
"release, use ``iteritems`` instead.", DeprecationWarning)
723+
return self.iteritems(*args, **kwargs)
724+
720725
def get_dtype_counts(self):
721726
""" return the counts of dtypes in this frame """
722727
from pandas import Series

pandas/core/panel.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,6 @@ def iteritems(self):
496496
for h in getattr(self, self._info_axis):
497497
yield h, self[h]
498498

499-
# Name that won't get automatically converted to items by 2to3. items is
500-
# already in use for the first axis.
501-
iterkv = iteritems
502-
503499
def _get_plane_axes(self, axis):
504500
"""
505501
Get my plane axes: these are already

pandas/core/series.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import operator
1010
from distutils.version import LooseVersion
1111
import types
12+
import warnings
1213

1314
from numpy import nan, ndarray
1415
import numpy as np
@@ -1219,7 +1220,11 @@ def iteritems(self):
12191220
"""
12201221
return lzip(iter(self.index), iter(self))
12211222

1222-
iterkv = iteritems
1223+
def iterkv(self):
1224+
warnings.warn("iterkv is deprecated and will be removed in a future "
1225+
"release. Use ``iteritems`` instead", DeprecationWarning)
1226+
return self.iteritems()
1227+
12231228
if compat.PY3: # pragma: no cover
12241229
items = iteritems
12251230

pandas/tests/test_frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10305,6 +10305,10 @@ def test_take(self):
1030510305
expected = df.ix[:, ['B', 'C', 'A', 'D']]
1030610306
assert_frame_equal(result, expected)
1030710307

10308+
def test_iterkv_deprecation(self):
10309+
with tm.assert_produces_warning(DeprecationWarning):
10310+
self.mixed_float.iterkv()
10311+
1030810312
def test_iterkv_names(self):
1030910313
for k, v in compat.iteritems(self.mixed_frame):
1031010314
self.assertEqual(v.name, k)

0 commit comments

Comments
 (0)