Skip to content

Commit 12d71f0

Browse files
committed
Merge branch 'mcsalgado-master'
Conflicts: doc/source/whatsnew/v0.15.2.txt
2 parents 98ea53b + 4661525 commit 12d71f0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.15.2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Enhancements
7474
- ``Timedelta`` now supports arithemtic with ``numpy.ndarray`` objects of the appropriate dtype (numpy 1.8 or newer only) (:issue:`8884`).
7575
- Added ``Timedelta.to_timedelta64`` method to the public API (:issue:`8884`).
7676
- Added ``gbq.generate_bq_schema`` function to the gbq module (:issue:`8325`).
77+
- ``Series`` now works with map objects the same way as generators (:issue:`8909`).
7778

7879
.. _whatsnew_0152.performance:
7980

pandas/core/series.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
183183
raise ValueError("cannot specify a dtype with a Categorical")
184184
if name is None:
185185
name = data.name
186-
elif isinstance(data, types.GeneratorType):
186+
elif (isinstance(data, types.GeneratorType) or
187+
(compat.PY3 and isinstance(data, map))):
187188
data = list(data)
188189
elif isinstance(data, (set, frozenset)):
189190
raise TypeError("{0!r} type is unordered"

pandas/tests/test_series.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,19 @@ def test_constructor_generator(self):
632632
exp.index = lrange(10, 20)
633633
assert_series_equal(result, exp)
634634

635+
def test_constructor_map(self):
636+
# GH8909
637+
m = map(lambda x: x, range(10))
638+
639+
result = Series(m)
640+
exp = Series(lrange(10))
641+
assert_series_equal(result, exp)
642+
643+
m = map(lambda x: x, range(10))
644+
result = Series(m, index=lrange(10, 20))
645+
exp.index = lrange(10, 20)
646+
assert_series_equal(result, exp)
647+
635648
def test_constructor_categorical(self):
636649
cat = pd.Categorical([0, 1, 2, 0, 1, 2], ['a', 'b', 'c'], fastpath=True)
637650
cat.name = 'foo'

0 commit comments

Comments
 (0)