From 4417106533d0b12866f50ae4bf5137ade084a81a Mon Sep 17 00:00:00 2001 From: tp Date: Wed, 8 May 2019 23:54:23 +0200 Subject: [PATCH] CLN: remove compat.lmap --- pandas/compat/__init__.py | 6 +-- pandas/core/computation/expr.py | 4 +- pandas/core/frame.py | 9 ++-- pandas/core/internals/construction.py | 4 +- pandas/core/sparse/frame.py | 3 +- pandas/core/sparse/scipy_sparse.py | 4 +- pandas/io/html.py | 4 +- pandas/io/stata.py | 9 ++-- pandas/plotting/_misc.py | 4 +- pandas/plotting/_style.py | 6 +-- pandas/tests/frame/test_constructors.py | 4 +- pandas/tests/frame/test_to_csv.py | 46 +++++++++++-------- pandas/tests/groupby/test_groupby.py | 11 ++--- pandas/tests/indexes/datetimes/test_tools.py | 3 +- .../tests/indexes/period/test_construction.py | 4 +- pandas/tests/indexing/test_iloc.py | 4 +- pandas/tests/io/parser/test_converters.py | 4 +- pandas/tests/plotting/test_frame.py | 26 +++++------ pandas/tests/plotting/test_misc.py | 12 ++--- pandas/tests/test_compat.py | 10 +--- pandas/util/testing.py | 4 +- 21 files changed, 84 insertions(+), 97 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 90444efd2ea18..6acd3c65e4bea 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -5,7 +5,7 @@ Cross-compatible functions for different versions of Python. Key items to import for compatible code: -* lists: lrange(), lmap() +* lists: lrange() Other items: * platform checker @@ -24,10 +24,6 @@ def lrange(*args, **kwargs): return list(range(*args, **kwargs)) -def lmap(*args, **kwargs): - return list(map(*args, **kwargs)) - - # ---------------------------------------------------------------------------- # functions largely based / taken from the six module diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index b87ef465459b4..cb9d537e61ebc 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -11,8 +11,6 @@ import numpy as np -from pandas.compat import lmap - import pandas as pd from pandas.core import common as com from pandas.core.base import StringMixin @@ -180,7 +178,7 @@ def _preparse(source, f=_compose(_replace_locals, _replace_booleans, the ``tokenize`` module and ``tokval`` is a string. """ assert callable(f), 'f must be callable' - return tokenize.untokenize(lmap(f, tokenize_string(source))) + return tokenize.untokenize((f(x) for x in tokenize_string(source))) def _is_type(t): diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c27bb743c8126..63daae83916c2 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -31,7 +31,7 @@ from pandas.util._validators import (validate_bool_kwarg, validate_axis_style_args) -from pandas.compat import PY36, lmap, raise_with_traceback +from pandas.compat import PY36, raise_with_traceback from pandas.compat.numpy import function as nv from pandas.core.dtypes.cast import ( maybe_upcast, @@ -1633,7 +1633,7 @@ def to_records(self, index=True, convert_datetime64=None, else: if isinstance(self.index, MultiIndex): # array of tuples to numpy cols. copy copy copy - ix_vals = lmap(np.array, zip(*self.index.values)) + ix_vals = list(map(np.array, zip(*self.index.values))) else: ix_vals = [self.index.values] @@ -1650,10 +1650,11 @@ def to_records(self, index=True, convert_datetime64=None, elif index_names[0] is None: index_names = ['index'] - names = lmap(str, index_names) + lmap(str, self.columns) + names = [str(name) for name in itertools.chain(index_names, + self.columns)] else: arrays = [self[c].get_values() for c in self.columns] - names = lmap(str, self.columns) + names = [str(c) for c in self.columns] index_names = [] index_len = len(index_names) diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 9c0c5fd4a2a4c..2ee49c30b226d 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -9,7 +9,7 @@ from pandas._libs import lib from pandas._libs.tslibs import IncompatibleFrequency -from pandas.compat import lmap, raise_with_traceback +from pandas.compat import raise_with_traceback from pandas.core.dtypes.cast import ( construct_1d_arraylike_from_scalar, construct_1d_ndarray_preserving_na, @@ -413,7 +413,7 @@ def to_arrays(data, columns, coerce_float=False, dtype=None): return arrays, columns else: # last ditch effort - data = lmap(tuple, data) + data = [tuple(x) for x in data] return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 22f5df411a2ad..3adeefd6ffd4e 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -7,7 +7,6 @@ import numpy as np from pandas._libs.sparse import BlockIndex, get_blocks -from pandas.compat import lmap from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender @@ -945,7 +944,7 @@ def applymap(self, func): ------- applied : DataFrame """ - return self.apply(lambda x: lmap(func, x)) + return self.apply(lambda x: [func(y) for y in x]) def to_manager(sdf, columns, index): diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index 5a39a1529a33a..40b4452caa8dc 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -5,8 +5,6 @@ """ from collections import OrderedDict -from pandas.compat import lmap - from pandas.core.index import Index, MultiIndex from pandas.core.series import Series @@ -53,7 +51,7 @@ def _get_label_to_i_dict(labels, sort_labels=False): """ Return OrderedDict of unique labels to number. Optionally sort by label. """ - labels = Index(lmap(tuple, labels)).unique().tolist() # squish + labels = Index(map(tuple, labels)).unique().tolist() # squish if sort_labels: labels = sorted(list(labels)) d = OrderedDict((k, i) for i, k in enumerate(labels)) diff --git a/pandas/io/html.py b/pandas/io/html.py index 2ef2ebf80f117..cbdc513cfbbe3 100644 --- a/pandas/io/html.py +++ b/pandas/io/html.py @@ -9,7 +9,7 @@ import os import re -from pandas.compat import lmap, raise_with_traceback +from pandas.compat import raise_with_traceback from pandas.errors import AbstractMethodError, EmptyDataError from pandas.core.dtypes.common import is_list_like @@ -764,7 +764,7 @@ def _parse_tfoot_tr(self, table): def _expand_elements(body): - lens = Series(lmap(len, body)) + lens = Series([len(elem) for elem in body]) lens_max = lens.max() not_max = lens[lens != lens_max] diff --git a/pandas/io/stata.py b/pandas/io/stata.py index b4daca6a4dbb9..c59e21678ed1e 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -23,7 +23,6 @@ from pandas._libs.lib import infer_dtype from pandas._libs.writers import max_len_string_array -from pandas.compat import lmap from pandas.util._decorators import Appender, deprecate_kwarg from pandas.core.dtypes.common import ( @@ -1030,7 +1029,7 @@ def _read_header(self): if type(x) is int]) > 0 # calculate size of a data record - self.col_sizes = lmap(lambda x: self._calcsize(x), self.typlist) + self.col_sizes = [self._calcsize(typ) for typ in self.typlist] def _read_new_header(self, first_char): # The first part of the header is common to 117 and 118. @@ -1573,9 +1572,9 @@ def read(self, nrows=None, convert_dates=None, data = self._do_convert_missing(data, convert_missing) if convert_dates: - cols = np.where(lmap(lambda x: any(x.startswith(fmt) - for fmt in _date_formats), - self.fmtlist))[0] + def any_startswith(x: str) -> bool: + return any(x.startswith(fmt) for fmt in _date_formats) + cols = np.where([any_startswith(x) for x in self.fmtlist])[0] for i in cols: col = data.columns[i] try: diff --git a/pandas/plotting/_misc.py b/pandas/plotting/_misc.py index 8d3aa06131126..1a25d2cd133eb 100644 --- a/pandas/plotting/_misc.py +++ b/pandas/plotting/_misc.py @@ -1,7 +1,7 @@ # being a bit too dynamic import numpy as np -from pandas.compat import lmap, lrange +from pandas.compat import lrange from pandas.util._decorators import deprecate_kwarg from pandas.core.dtypes.missing import notna @@ -625,7 +625,7 @@ def r(h): return ((data[:n - h] - mean) * (data[h:] - mean)).sum() / float(n) / c0 x = np.arange(n) + 1 - y = lmap(r, x) + y = [r(loc) for loc in x] z95 = 1.959963984540054 z99 = 2.5758293035489004 ax.axhline(y=z99 / np.sqrt(n), linestyle='--', color='grey') diff --git a/pandas/plotting/_style.py b/pandas/plotting/_style.py index 72b14e721c6df..ba75d05f62131 100644 --- a/pandas/plotting/_style.py +++ b/pandas/plotting/_style.py @@ -4,7 +4,7 @@ import numpy as np -from pandas.compat import lmap, lrange +from pandas.compat import lrange from pandas.core.dtypes.common import is_list_like @@ -20,7 +20,7 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default', colormap = cm.get_cmap(colormap) if colormap is None: raise ValueError("Colormap {0} is not recognized".format(cmap)) - colors = lmap(colormap, np.linspace(0, 1, num=num_colors)) + colors = [colormap(num) for num in np.linspace(0, 1, num=num_colors)] elif color is not None: if colormap is not None: warnings.warn("'color' and 'colormap' cannot be used " @@ -49,7 +49,7 @@ def random_color(column): rs = com.random_state(column) return rs.rand(3).tolist() - colors = lmap(random_color, lrange(num_colors)) + colors = [random_color(num) for num in lrange(num_colors)] else: raise ValueError("color_type must be either 'default' or 'random'") diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 0ec533f4d8b50..a6ce2bfb31248 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -7,7 +7,7 @@ import numpy.ma as ma import pytest -from pandas.compat import PY36, is_platform_little_endian, lmap +from pandas.compat import PY36, is_platform_little_endian from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import is_integer_dtype @@ -2224,7 +2224,7 @@ def __iter__(self): return iter(self.args) recs = [Record(1, 2, 3), Record(4, 5, 6), Record(7, 8, 9)] - tups = lmap(tuple, recs) + tups = [tuple(rec) for rec in recs] result = DataFrame.from_records(recs) expected = DataFrame.from_records(tups) diff --git a/pandas/tests/frame/test_to_csv.py b/pandas/tests/frame/test_to_csv.py index 20cd8c9dc744a..012441d8a66b7 100644 --- a/pandas/tests/frame/test_to_csv.py +++ b/pandas/tests/frame/test_to_csv.py @@ -5,7 +5,6 @@ import numpy as np import pytest -from pandas.compat import lmap from pandas.errors import ParserError import pandas as pd @@ -120,8 +119,8 @@ def test_to_csv_from_csv3(self): df2.to_csv(path, mode='a', header=False) xp = pd.concat([df1, df2]) rs = pd.read_csv(path, index_col=0) - rs.columns = lmap(int, rs.columns) - xp.columns = lmap(int, xp.columns) + rs.columns = [int(label) for label in rs.columns] + xp.columns = [int(label) for label in xp.columns] assert_frame_equal(xp, rs) def test_to_csv_from_csv4(self): @@ -292,19 +291,24 @@ def _to_uni(x): if r_dtype: if r_dtype == 'u': # unicode r_dtype = 'O' - recons.index = np.array(lmap(_to_uni, recons.index), - dtype=r_dtype) - df.index = np.array(lmap(_to_uni, df.index), dtype=r_dtype) + recons.index = np.array( + [_to_uni(label) for label in recons.index], + dtype=r_dtype) + df.index = np.array( + [_to_uni(label) for label in df.index], dtype=r_dtype) elif r_dtype == 'dt': # unicode r_dtype = 'O' - recons.index = np.array(lmap(Timestamp, recons.index), - dtype=r_dtype) + recons.index = np.array( + [Timestamp(label) for label in recons.index], + dtype=r_dtype) df.index = np.array( - lmap(Timestamp, df.index), dtype=r_dtype) + [Timestamp(label) for label in df.index], + dtype=r_dtype) elif r_dtype == 'p': r_dtype = 'O' + idx_list = to_datetime(recons.index) recons.index = np.array( - list(map(Timestamp, to_datetime(recons.index))), + [Timestamp(label) for label in idx_list], dtype=r_dtype) df.index = np.array( list(map(Timestamp, df.index.to_timestamp())), @@ -316,23 +320,29 @@ def _to_uni(x): if c_dtype: if c_dtype == 'u': c_dtype = 'O' - recons.columns = np.array(lmap(_to_uni, recons.columns), - dtype=c_dtype) + recons.columns = np.array( + [_to_uni(label) for label in recons.columns], + dtype=c_dtype) df.columns = np.array( - lmap(_to_uni, df.columns), dtype=c_dtype) + [_to_uni(label) for label in df.columns], + dtype=c_dtype) elif c_dtype == 'dt': c_dtype = 'O' - recons.columns = np.array(lmap(Timestamp, recons.columns), - dtype=c_dtype) + recons.columns = np.array( + [Timestamp(label) for label in recons.columns], + dtype=c_dtype) df.columns = np.array( - lmap(Timestamp, df.columns), dtype=c_dtype) + [Timestamp(label) for label in df.columns], + dtype=c_dtype) elif c_dtype == 'p': c_dtype = 'O' + col_list = to_datetime(recons.columns) recons.columns = np.array( - lmap(Timestamp, to_datetime(recons.columns)), + [Timestamp(label) for label in col_list], dtype=c_dtype) + col_list = df.columns.to_timestamp() df.columns = np.array( - lmap(Timestamp, df.columns.to_timestamp()), + [Timestamp(label) for label in col_list], dtype=c_dtype) else: c_dtype = type_map.get(c_dtype) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 31065cbb6f69a..c9df40504cc3b 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -6,7 +6,6 @@ import numpy as np import pytest -from pandas.compat import lmap from pandas.errors import PerformanceWarning import pandas as pd @@ -874,7 +873,7 @@ def test_mutate_groups(): 'cat1': ['a'] * 8 + ['b'] * 6, 'cat2': ['c'] * 2 + ['d'] * 2 + ['e'] * 2 + ['f'] * 2 + ['c'] * 2 + ['d'] * 2 + ['e'] * 2, - 'cat3': lmap(lambda x: 'g%s' % x, range(1, 15)), + 'cat3': ['g{}'.format(x) for x in range(1, 15)], 'val': np.random.randint(100, size=14), }) @@ -1248,17 +1247,17 @@ def test_groupby_sort_multi(): 'c': [0, 1, 2], 'd': np.random.randn(3)}) - tups = lmap(tuple, df[['a', 'b', 'c']].values) + tups = [tuple(row) for row in df[['a', 'b', 'c']].values] tups = com.asarray_tuplesafe(tups) result = df.groupby(['a', 'b', 'c'], sort=True).sum() tm.assert_numpy_array_equal(result.index.values, tups[[1, 2, 0]]) - tups = lmap(tuple, df[['c', 'a', 'b']].values) + tups = [tuple(row) for row in df[['c', 'a', 'b']].values] tups = com.asarray_tuplesafe(tups) result = df.groupby(['c', 'a', 'b'], sort=True).sum() tm.assert_numpy_array_equal(result.index.values, tups) - tups = lmap(tuple, df[['b', 'c', 'a']].values) + tups = [tuple(x) for x in df[['b', 'c', 'a']].values] tups = com.asarray_tuplesafe(tups) result = df.groupby(['b', 'c', 'a'], sort=True).sum() tm.assert_numpy_array_equal(result.index.values, tups[[2, 1, 0]]) @@ -1270,7 +1269,7 @@ def test_groupby_sort_multi(): result = grouped.sum() def _check_groupby(df, result, keys, field, f=lambda x: x.sum()): - tups = lmap(tuple, df[keys].values) + tups = [tuple(row) for row in df[keys].values] tups = com.asarray_tuplesafe(tups) expected = f(df.groupby(tups)[field]) for k, v in expected.items(): diff --git a/pandas/tests/indexes/datetimes/test_tools.py b/pandas/tests/indexes/datetimes/test_tools.py index 5bad5d415f5f7..d0f551f55f5ad 100644 --- a/pandas/tests/indexes/datetimes/test_tools.py +++ b/pandas/tests/indexes/datetimes/test_tools.py @@ -14,7 +14,6 @@ from pandas._libs import tslib from pandas._libs.tslibs import iNaT, parsing -from pandas.compat import lmap from pandas.errors import OutOfBoundsDatetime import pandas.util._test_decorators as td @@ -1264,7 +1263,7 @@ def test_to_datetime_types(self, cache): # array = ['2012','20120101','20120101 12:01:01'] array = ['20120101', '20120101 12:01:01'] expected = list(to_datetime(array, cache=cache)) - result = lmap(Timestamp, array) + result = [Timestamp(date_str) for date_str in array] tm.assert_almost_equal(result, expected) # currently fails ### diff --git a/pandas/tests/indexes/period/test_construction.py b/pandas/tests/indexes/period/test_construction.py index 1c3125571a27d..a017fc693e1de 100644 --- a/pandas/tests/indexes/period/test_construction.py +++ b/pandas/tests/indexes/period/test_construction.py @@ -2,7 +2,7 @@ import pytest from pandas._libs.tslibs.period import IncompatibleFrequency -from pandas.compat import lmap, lrange +from pandas.compat import lrange from pandas.core.dtypes.dtypes import PeriodDtype @@ -514,7 +514,7 @@ def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] index = PeriodIndex(raw, freq='A') - expected = Index(lmap(str, raw)) + expected = Index([str(num) for num in raw]) res = index.map(str) # should return an Index diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 27f62af8394ef..88d20b8f68173 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -5,7 +5,7 @@ import numpy as np import pytest -from pandas.compat import lmap, lrange +from pandas.compat import lrange import pandas as pd from pandas import DataFrame, Series, concat, date_range, isna @@ -603,7 +603,7 @@ def test_iloc_mask(self): # the possibilities locs = np.arange(4) nums = 2 ** locs - reps = lmap(bin, nums) + reps = [bin(num) for num in nums] df = DataFrame({'locs': locs, 'nums': nums}, reps) expected = { diff --git a/pandas/tests/io/parser/test_converters.py b/pandas/tests/io/parser/test_converters.py index bb67367cd3210..4df99d396b7ac 100644 --- a/pandas/tests/io/parser/test_converters.py +++ b/pandas/tests/io/parser/test_converters.py @@ -8,8 +8,6 @@ import numpy as np import pytest -from pandas.compat import lmap - import pandas as pd from pandas import DataFrame, Index import pandas.util.testing as tm @@ -126,7 +124,7 @@ def convert_score(x): return np.nan if x.find("-") > 0: - val_min, val_max = lmap(int, x.split("-")) + val_min, val_max = map(int, x.split("-")) val = 0.5 * (val_min + val_max) else: val = float(x) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 3bb49baf78c3a..bae386a98b988 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -10,7 +10,7 @@ from numpy.random import rand, randn import pytest -from pandas.compat import lmap, lrange +from pandas.compat import lrange import pandas.util._test_decorators as td from pandas.core.dtypes.api import is_list_like @@ -897,13 +897,13 @@ def test_bar_colors(self): from matplotlib import cm # Test str -> colormap functionality ax = df.plot.bar(colormap='jet') - rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5)) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)] self._check_colors(ax.patches[::5], facecolors=rgba_colors) tm.close() # Test colormap functionality ax = df.plot.bar(colormap=cm.jet) - rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5)) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)] self._check_colors(ax.patches[::5], facecolors=rgba_colors) tm.close() @@ -1853,12 +1853,12 @@ def test_line_colors(self): tm.close() ax = df.plot(colormap='jet') - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] self._check_colors(ax.get_lines(), linecolors=rgba_colors) tm.close() ax = df.plot(colormap=cm.jet) - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] self._check_colors(ax.get_lines(), linecolors=rgba_colors) tm.close() @@ -1941,7 +1941,7 @@ def test_line_colors_and_styles_subplots(self): with tm.assert_produces_warning(UserWarning): _check_plot_works(df.plot, color=custom_colors, subplots=True) - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] for cmap in ['jet', cm.jet]: axes = df.plot(colormap=cmap, subplots=True) for ax, c in zip(axes, rgba_colors): @@ -1987,7 +1987,7 @@ def test_area_colors(self): tm.close() ax = df.plot.area(colormap='jet') - jet_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + jet_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] self._check_colors(ax.get_lines(), linecolors=jet_colors) poly = [o for o in ax.get_children() if isinstance(o, PolyCollection)] self._check_colors(poly, facecolors=jet_colors) @@ -2028,13 +2028,13 @@ def test_hist_colors(self): from matplotlib import cm # Test str -> colormap functionality ax = df.plot.hist(colormap='jet') - rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5)) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)] self._check_colors(ax.patches[::10], facecolors=rgba_colors) tm.close() # Test colormap functionality ax = df.plot.hist(colormap=cm.jet) - rgba_colors = lmap(cm.jet, np.linspace(0, 1, 5)) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, 5)] self._check_colors(ax.patches[::10], facecolors=rgba_colors) tm.close() @@ -2058,12 +2058,12 @@ def test_kde_colors(self): tm.close() ax = df.plot.kde(colormap='jet') - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] self._check_colors(ax.get_lines(), linecolors=rgba_colors) tm.close() ax = df.plot.kde(colormap=cm.jet) - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] self._check_colors(ax.get_lines(), linecolors=rgba_colors) @pytest.mark.slow @@ -2097,7 +2097,7 @@ def test_kde_colors_and_styles_subplots(self): self._check_colors(ax.get_lines(), linecolors=[c]) tm.close() - rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) + rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))] for cmap in ['jet', cm.jet]: axes = df.plot(kind='kde', colormap=cmap, subplots=True) for ax, c in zip(axes, rgba_colors): @@ -2165,7 +2165,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c='k', from matplotlib import cm # Test str -> colormap functionality bp = df.plot.box(colormap='jet', return_type='dict') - jet_colors = lmap(cm.jet, np.linspace(0, 1, 3)) + jet_colors = [cm.jet(n) for n in np.linspace(0, 1, 3)] _check_colors(bp, jet_colors[0], jet_colors[0], jet_colors[2]) tm.close() diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index a184c024f4459..5ffbe9ec8fd47 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -7,7 +7,6 @@ from numpy.random import randn import pytest -from pandas.compat import lmap import pandas.util._test_decorators as td from pandas import DataFrame @@ -115,7 +114,7 @@ def test_andrews_curves(self, iris): ax = _check_plot_works(andrews_curves, frame=df, class_column='Name', colormap=cm.jet) - cmaps = lmap(cm.jet, np.linspace(0, 1, df['Name'].nunique())) + cmaps = [cm.jet(n) for n in np.linspace(0, 1, df['Name'].nunique())] self._check_colors( ax.get_lines()[:10], linecolors=cmaps, mapping=df['Name'][:10]) @@ -141,7 +140,7 @@ def test_andrews_curves(self, iris): ax = _check_plot_works(andrews_curves, frame=df, class_column='Name', colormap=cm.jet) - cmaps = lmap(cm.jet, np.linspace(0, 1, df['Name'].nunique())) + cmaps = [cm.jet(n) for n in np.linspace(0, 1, df['Name'].nunique())] self._check_colors( ax.get_lines()[:10], linecolors=cmaps, mapping=df['Name'][:10]) @@ -183,7 +182,7 @@ def test_parallel_coordinates(self, iris): ax = _check_plot_works(parallel_coordinates, frame=df, class_column='Name', colormap=cm.jet) - cmaps = lmap(cm.jet, np.linspace(0, 1, df['Name'].nunique())) + cmaps = [cm.jet(n) for n in np.linspace(0, 1, df['Name'].nunique())] self._check_colors( ax.get_lines()[:10], linecolors=cmaps, mapping=df['Name'][:10]) @@ -250,7 +249,7 @@ def test_radviz(self, iris): _check_plot_works(radviz, frame=df, class_column='Name', colormap=cm.jet) - cmaps = lmap(cm.jet, np.linspace(0, 1, df['Name'].nunique())) + cmaps = [cm.jet(n) for n in np.linspace(0, 1, df['Name'].nunique())] patches = [p for p in ax.patches[:20] if p.get_label() != ''] self._check_colors(patches, facecolors=cmaps, mapping=df['Name'][:10]) @@ -337,8 +336,7 @@ def test_plot_single_color(self): 'rank': [52, 525, 32], }) ax = df.client.value_counts().plot.bar() - colors = lmap(lambda rect: rect.get_facecolor(), - ax.get_children()[0:3]) + colors = [rect.get_facecolor() for rect in ax.get_children()[0:3]] assert all(color == colors[0] for color in colors) def test_get_standard_colors_no_appending(self): diff --git a/pandas/tests/test_compat.py b/pandas/tests/test_compat.py index 1add28c1f56ab..478cb87b8ab68 100644 --- a/pandas/tests/test_compat.py +++ b/pandas/tests/test_compat.py @@ -3,7 +3,7 @@ """ import builtins -from pandas.compat import lmap, lrange +from pandas.compat import lrange class TestBuiltinIterators: @@ -24,11 +24,3 @@ def test_lrange(self): lengths += 5, expecteds += list(builtins.range(1, 10, 2)), self.check_results(results, expecteds, lengths) - - def test_lmap(self): - func = lambda x, y, z: x + y + z - lst = [builtins.range(10), builtins.range(10), builtins.range(10)] - results = lmap(func, *lst), - expecteds = list(builtins.map(func, *lst)), - lengths = 10, - self.check_results(results, expecteds, lengths) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index b7fa15984f294..9084ebc736599 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -22,7 +22,7 @@ can_set_locale, get_locales, set_locale) from pandas._libs import testing as _testing -from pandas.compat import lmap, raise_with_traceback +from pandas.compat import raise_with_traceback from pandas.core.dtypes.common import ( is_bool, is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype, @@ -1815,7 +1815,7 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None, def keyfunc(x): import re numeric_tuple = re.sub(r"[^\d_]_?", "", x).split("_") - return lmap(int, numeric_tuple) + return [int(num) for num in numeric_tuple] # build a list of lists to create the index from div_factor = nentries // ndupe_l[i] + 1