Skip to content

Commit 58fd449

Browse files
topper-123gfyoung
authored andcommitted
CLN: remove compat.lmap (#26322)
xref gh-25725
1 parent ee6b131 commit 58fd449

File tree

21 files changed

+84
-97
lines changed

21 files changed

+84
-97
lines changed

pandas/compat/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Cross-compatible functions for different versions of Python.
66
77
Key items to import for compatible code:
8-
* lists: lrange(), lmap()
8+
* lists: lrange()
99
1010
Other items:
1111
* platform checker
@@ -24,10 +24,6 @@ def lrange(*args, **kwargs):
2424
return list(range(*args, **kwargs))
2525

2626

27-
def lmap(*args, **kwargs):
28-
return list(map(*args, **kwargs))
29-
30-
3127
# ----------------------------------------------------------------------------
3228
# functions largely based / taken from the six module
3329

pandas/core/computation/expr.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
import numpy as np
1313

14-
from pandas.compat import lmap
15-
1614
import pandas as pd
1715
from pandas.core import common as com
1816
from pandas.core.base import StringMixin
@@ -180,7 +178,7 @@ def _preparse(source, f=_compose(_replace_locals, _replace_booleans,
180178
the ``tokenize`` module and ``tokval`` is a string.
181179
"""
182180
assert callable(f), 'f must be callable'
183-
return tokenize.untokenize(lmap(f, tokenize_string(source)))
181+
return tokenize.untokenize((f(x) for x in tokenize_string(source)))
184182

185183

186184
def _is_type(t):

pandas/core/frame.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from pandas.util._validators import (validate_bool_kwarg,
3232
validate_axis_style_args)
3333

34-
from pandas.compat import PY36, lmap, raise_with_traceback
34+
from pandas.compat import PY36, raise_with_traceback
3535
from pandas.compat.numpy import function as nv
3636
from pandas.core.dtypes.cast import (
3737
maybe_upcast,
@@ -1633,7 +1633,7 @@ def to_records(self, index=True, convert_datetime64=None,
16331633
else:
16341634
if isinstance(self.index, MultiIndex):
16351635
# array of tuples to numpy cols. copy copy copy
1636-
ix_vals = lmap(np.array, zip(*self.index.values))
1636+
ix_vals = list(map(np.array, zip(*self.index.values)))
16371637
else:
16381638
ix_vals = [self.index.values]
16391639

@@ -1650,10 +1650,11 @@ def to_records(self, index=True, convert_datetime64=None,
16501650
elif index_names[0] is None:
16511651
index_names = ['index']
16521652

1653-
names = lmap(str, index_names) + lmap(str, self.columns)
1653+
names = [str(name) for name in itertools.chain(index_names,
1654+
self.columns)]
16541655
else:
16551656
arrays = [self[c].get_values() for c in self.columns]
1656-
names = lmap(str, self.columns)
1657+
names = [str(c) for c in self.columns]
16571658
index_names = []
16581659

16591660
index_len = len(index_names)

pandas/core/internals/construction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas._libs import lib
1111
from pandas._libs.tslibs import IncompatibleFrequency
12-
from pandas.compat import lmap, raise_with_traceback
12+
from pandas.compat import raise_with_traceback
1313

1414
from pandas.core.dtypes.cast import (
1515
construct_1d_arraylike_from_scalar, construct_1d_ndarray_preserving_na,
@@ -413,7 +413,7 @@ def to_arrays(data, columns, coerce_float=False, dtype=None):
413413
return arrays, columns
414414
else:
415415
# last ditch effort
416-
data = lmap(tuple, data)
416+
data = [tuple(x) for x in data]
417417
return _list_to_arrays(data, columns, coerce_float=coerce_float,
418418
dtype=dtype)
419419

pandas/core/sparse/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import numpy as np
88

99
from pandas._libs.sparse import BlockIndex, get_blocks
10-
from pandas.compat import lmap
1110
from pandas.compat.numpy import function as nv
1211
from pandas.util._decorators import Appender
1312

@@ -945,7 +944,7 @@ def applymap(self, func):
945944
-------
946945
applied : DataFrame
947946
"""
948-
return self.apply(lambda x: lmap(func, x))
947+
return self.apply(lambda x: [func(y) for y in x])
949948

950949

951950
def to_manager(sdf, columns, index):

pandas/core/sparse/scipy_sparse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"""
66
from collections import OrderedDict
77

8-
from pandas.compat import lmap
9-
108
from pandas.core.index import Index, MultiIndex
119
from pandas.core.series import Series
1210

@@ -53,7 +51,7 @@ def _get_label_to_i_dict(labels, sort_labels=False):
5351
""" Return OrderedDict of unique labels to number.
5452
Optionally sort by label.
5553
"""
56-
labels = Index(lmap(tuple, labels)).unique().tolist() # squish
54+
labels = Index(map(tuple, labels)).unique().tolist() # squish
5755
if sort_labels:
5856
labels = sorted(list(labels))
5957
d = OrderedDict((k, i) for i, k in enumerate(labels))

pandas/io/html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import re
1111

12-
from pandas.compat import lmap, raise_with_traceback
12+
from pandas.compat import raise_with_traceback
1313
from pandas.errors import AbstractMethodError, EmptyDataError
1414

1515
from pandas.core.dtypes.common import is_list_like
@@ -764,7 +764,7 @@ def _parse_tfoot_tr(self, table):
764764

765765

766766
def _expand_elements(body):
767-
lens = Series(lmap(len, body))
767+
lens = Series([len(elem) for elem in body])
768768
lens_max = lens.max()
769769
not_max = lens[lens != lens_max]
770770

pandas/io/stata.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
from pandas._libs.lib import infer_dtype
2525
from pandas._libs.writers import max_len_string_array
26-
from pandas.compat import lmap
2726
from pandas.util._decorators import Appender, deprecate_kwarg
2827

2928
from pandas.core.dtypes.common import (
@@ -1030,7 +1029,7 @@ def _read_header(self):
10301029
if type(x) is int]) > 0
10311030

10321031
# calculate size of a data record
1033-
self.col_sizes = lmap(lambda x: self._calcsize(x), self.typlist)
1032+
self.col_sizes = [self._calcsize(typ) for typ in self.typlist]
10341033

10351034
def _read_new_header(self, first_char):
10361035
# The first part of the header is common to 117 and 118.
@@ -1573,9 +1572,9 @@ def read(self, nrows=None, convert_dates=None,
15731572
data = self._do_convert_missing(data, convert_missing)
15741573

15751574
if convert_dates:
1576-
cols = np.where(lmap(lambda x: any(x.startswith(fmt)
1577-
for fmt in _date_formats),
1578-
self.fmtlist))[0]
1575+
def any_startswith(x: str) -> bool:
1576+
return any(x.startswith(fmt) for fmt in _date_formats)
1577+
cols = np.where([any_startswith(x) for x in self.fmtlist])[0]
15791578
for i in cols:
15801579
col = data.columns[i]
15811580
try:

pandas/plotting/_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# being a bit too dynamic
22
import numpy as np
33

4-
from pandas.compat import lmap, lrange
4+
from pandas.compat import lrange
55
from pandas.util._decorators import deprecate_kwarg
66

77
from pandas.core.dtypes.missing import notna
@@ -625,7 +625,7 @@ def r(h):
625625
return ((data[:n - h] - mean) *
626626
(data[h:] - mean)).sum() / float(n) / c0
627627
x = np.arange(n) + 1
628-
y = lmap(r, x)
628+
y = [r(loc) for loc in x]
629629
z95 = 1.959963984540054
630630
z99 = 2.5758293035489004
631631
ax.axhline(y=z99 / np.sqrt(n), linestyle='--', color='grey')

pandas/plotting/_style.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66

7-
from pandas.compat import lmap, lrange
7+
from pandas.compat import lrange
88

99
from pandas.core.dtypes.common import is_list_like
1010

@@ -20,7 +20,7 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
2020
colormap = cm.get_cmap(colormap)
2121
if colormap is None:
2222
raise ValueError("Colormap {0} is not recognized".format(cmap))
23-
colors = lmap(colormap, np.linspace(0, 1, num=num_colors))
23+
colors = [colormap(num) for num in np.linspace(0, 1, num=num_colors)]
2424
elif color is not None:
2525
if colormap is not None:
2626
warnings.warn("'color' and 'colormap' cannot be used "
@@ -49,7 +49,7 @@ def random_color(column):
4949
rs = com.random_state(column)
5050
return rs.rand(3).tolist()
5151

52-
colors = lmap(random_color, lrange(num_colors))
52+
colors = [random_color(num) for num in lrange(num_colors)]
5353
else:
5454
raise ValueError("color_type must be either 'default' or 'random'")
5555

0 commit comments

Comments
 (0)