Skip to content

Commit 6bbfe46

Browse files
committed
Merge pull request #4450 from jtratner/change-range-zip-in-docs
DOC: lrange, lzip --> list(range and list(zip
2 parents f18378d + fb4f6a1 commit 6bbfe46

9 files changed

+26
-26
lines changed

doc/source/basics.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ By default integer types are ``int64`` and float types are ``float64``,
10931093
10941094
DataFrame([1, 2], columns=['a']).dtypes
10951095
DataFrame({'a': [1, 2]}).dtypes
1096-
DataFrame({'a': 1 }, index=lrange(2)).dtypes
1096+
DataFrame({'a': 1 }, index=list(range(2))).dtypes
10971097
10981098
Numpy, however will choose *platform-dependent* types when creating arrays.
10991099
The following **WILL** result in ``int32`` on 32-bit platform.

doc/source/faq.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ life easier is missing. In that case you have several options:
8686
return [x for x in self.columns if 'foo' in x]
8787
8888
pd.DataFrame.just_foo_cols = just_foo_cols # monkey-patch the DataFrame class
89-
df = pd.DataFrame([lrange(4)],columns= ["A","foo","foozball","bar"])
89+
df = pd.DataFrame([list(range(4))], columns=["A","foo","foozball","bar"])
9090
df.just_foo_cols()
9191
del pd.DataFrame.just_foo_cols # you can also remove the new method
9292
@@ -259,7 +259,7 @@ using something similar to the following:
259259

260260
.. ipython:: python
261261
262-
x = np.array(lrange(10), '>i4') # big endian
262+
x = np.array(list(range(10)), '>i4') # big endian
263263
newx = x.byteswap().newbyteorder() # force native byteorder
264264
s = Series(newx)
265265

doc/source/gotchas.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ using something similar to the following:
467467

468468
.. ipython:: python
469469
470-
x = np.array(lrange(10), '>i4') # big endian
470+
x = np.array(list(range(10)), '>i4') # big endian
471471
newx = x.byteswap().newbyteorder() # force native byteorder
472472
s = Series(newx)
473473

doc/source/groupby.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import matplotlib.pyplot as plt
1313
plt.close('all')
1414
options.display.mpl_style='default'
15-
from pandas.compat import lzip
15+
from pandas.compat import zip
1616
1717
*****************************
1818
Group By: split-apply-combine
@@ -202,7 +202,7 @@ natural to group by one of the levels of the hierarchy.
202202
203203
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
204204
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
205-
tuples = lzip(*arrays)
205+
tuples = list(zip(*arrays))
206206
tuples
207207
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
208208
s = Series(randn(8), index=index)
@@ -236,7 +236,7 @@ Also as of v0.6, grouping with multiple levels is supported.
236236
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
237237
['doo', 'doo', 'bee', 'bee', 'bop', 'bop', 'bop', 'bop'],
238238
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
239-
tuples = lzip(*arrays)
239+
tuples = list(zip(*arrays))
240240
index = MultiIndex.from_tuples(tuples, names=['first', 'second', 'third'])
241241
s = Series(randn(8), index=index)
242242

doc/source/indexing.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
randn = np.random.randn
1414
randint = np.random.randint
1515
np.set_printoptions(precision=4, suppress=True)
16-
from pandas.compat import lrange, lzip
16+
from pandas.compat import range, zip
1717
1818
***************************
1919
Indexing and Selecting Data
@@ -294,7 +294,7 @@ The ``.iloc`` attribute is the primary access method. The following are valid in
294294

295295
.. ipython:: python
296296
297-
s1 = Series(np.random.randn(5),index=lrange(0,10,2))
297+
s1 = Series(np.random.randn(5),index=list(range(0,10,2)))
298298
s1
299299
s1.iloc[:3]
300300
s1.iloc[3]
@@ -311,8 +311,8 @@ With a DataFrame
311311
.. ipython:: python
312312
313313
df1 = DataFrame(np.random.randn(6,4),
314-
index=lrange(0,12,2),
315-
columns=lrange(0,8,2))
314+
index=list(range(0,12,2)),
315+
columns=list(range(0,8,2)))
316316
df1
317317
318318
Select via integer slicing
@@ -787,7 +787,7 @@ numpy array. For instance,
787787
.. ipython:: python
788788
789789
dflookup = DataFrame(np.random.rand(20,4), columns = ['A','B','C','D'])
790-
dflookup.lookup(lrange(0,10,2), ['B','C','A','B','D'])
790+
dflookup.lookup(list(range(0,10,2)), ['B','C','A','B','D'])
791791
792792
Setting values in mixed-type DataFrame
793793
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -897,7 +897,7 @@ display:
897897

898898
.. ipython:: python
899899
900-
index = Index(lrange(5), name='rows')
900+
index = Index(list(range(5)), name='rows')
901901
columns = Index(['A', 'B', 'C'], name='cols')
902902
df = DataFrame(np.random.randn(5, 3), index=index, columns=columns)
903903
df
@@ -972,7 +972,7 @@ can think of ``MultiIndex`` an array of tuples where each tuple is unique. A
972972
973973
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
974974
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
975-
tuples = lzip(*arrays)
975+
tuples = list(zip(*arrays))
976976
tuples
977977
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
978978
s = Series(randn(8), index=index)

doc/source/io.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ Writing to a file, with a date index and a date column
10611061
10621062
dfj2 = dfj.copy()
10631063
dfj2['date'] = Timestamp('20130101')
1064-
dfj2['ints'] = lrange(5)
1064+
dfj2['ints'] = list(range(5))
10651065
dfj2['bools'] = True
10661066
dfj2.index = date_range('20130101',periods=5)
10671067
dfj2.to_json('test.json')
@@ -1156,7 +1156,7 @@ I like my string indicies
11561156
.. ipython:: python
11571157
11581158
si = DataFrame(np.zeros((4, 4)),
1159-
columns=lrange(4),
1159+
columns=list(range(4)),
11601160
index=[str(i) for i in range(4)])
11611161
si
11621162
si.index
@@ -1741,7 +1741,7 @@ similar to how ``read_csv`` and ``to_csv`` work. (new in 0.11.0)
17411741
17421742
.. ipython:: python
17431743
1744-
df_tl = DataFrame(dict(A=lrange(5), B=lrange(5)))
1744+
df_tl = DataFrame(dict(A=list(range(5)), B=list(range(5))))
17451745
df_tl.to_hdf('store_tl.h5','table',append=True)
17461746
read_hdf('store_tl.h5', 'table', where = ['index>2'])
17471747
@@ -1863,7 +1863,7 @@ defaults to `nan`.
18631863
'int' : 1,
18641864
'bool' : True,
18651865
'datetime64' : Timestamp('20010102')},
1866-
index=lrange(8))
1866+
index=list(range(8)))
18671867
df_mixed.ix[3:5,['A', 'B', 'string', 'datetime64']] = np.nan
18681868
18691869
store.append('df_mixed', df_mixed, min_itemsize = {'values': 50})
@@ -2288,7 +2288,7 @@ Starting in 0.11, passing a ``min_itemsize`` dict will cause all passed columns
22882288
22892289
.. ipython:: python
22902290
2291-
dfs = DataFrame(dict(A = 'foo', B = 'bar'),index=lrange(5))
2291+
dfs = DataFrame(dict(A = 'foo', B = 'bar'),index=list(range(5)))
22922292
dfs
22932293
22942294
# A and B have a size of 30

doc/source/missing_data.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Replace the '.' with ``nan`` (str -> str)
363363
364364
.. ipython:: python
365365
366-
d = {'a': lrange(4), 'b': list('ab..'), 'c': ['a', 'b', nan, 'd']}
366+
d = {'a': list(range(4)), 'b': list('ab..'), 'c': ['a', 'b', nan, 'd']}
367367
df = DataFrame(d)
368368
df.replace('.', nan)
369369
@@ -500,7 +500,7 @@ For example:
500500
s = Series(randn(5), index=[0, 2, 4, 6, 7])
501501
s > 0
502502
(s > 0).dtype
503-
crit = (s > 0).reindex(lrange(8))
503+
crit = (s > 0).reindex(list(range(8)))
504504
crit
505505
crit.dtype
506506
@@ -512,7 +512,7 @@ contains NAs, an exception will be generated:
512512
.. ipython:: python
513513
:okexcept:
514514
515-
reindexed = s.reindex(lrange(8)).fillna(0)
515+
reindexed = s.reindex(list(range(8))).fillna(0)
516516
reindexed[crit]
517517
518518
However, these can be filled in using **fillna** and it will work fine:

doc/source/reshaping.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
randn = np.random.randn
1313
np.set_printoptions(precision=4, suppress=True)
1414
from pandas.tools.tile import *
15-
from pandas.compat import lzip
15+
from pandas.compat import zip
1616
1717
**************************
1818
Reshaping and Pivot Tables
@@ -117,10 +117,10 @@ from the hierarchical indexing section:
117117

118118
.. ipython:: python
119119
120-
tuples = lzip(*[['bar', 'bar', 'baz', 'baz',
120+
tuples = list(zip(*[['bar', 'bar', 'baz', 'baz',
121121
'foo', 'foo', 'qux', 'qux'],
122122
['one', 'two', 'one', 'two',
123-
'one', 'two', 'one', 'two']])
123+
'one', 'two', 'one', 'two']]))
124124
index = MultiIndex.from_tuples(tuples, names=['first', 'second'])
125125
df = DataFrame(randn(8, 2), index=index, columns=['A', 'B'])
126126
df2 = df[:4]

doc/source/visualization.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ You can plot one column versus another using the `x` and `y` keywords in
102102
plt.figure()
103103
104104
df3 = DataFrame(randn(1000, 2), columns=['B', 'C']).cumsum()
105-
df3['A'] = Series(lrange(len(df)))
105+
df3['A'] = Series(list(range(len(df))))
106106
107107
@savefig df_plot_xy.png
108108
df3.plot(x='A', y='B')

0 commit comments

Comments
 (0)