def test_map(self): index = PeriodIndex([2005, 2007, 2009], freq='A') result = index.map(lambda x: x + 1) expected = index + 1 tm.assert_index_equal(result, expected) result = index.map(lambda x: x.ordinal) exp = Index([x.ordinal for x in index]) tm.assert_index_equal(result, exp)
def test_map(self): index = PeriodIndex([2005, 2007, 2009], freq='A') result = index.map(lambda x: x + 1) expected = index + 1 tm.assert_index_equal(result, expected) result = index.map(lambda x: x.ordinal) exp = Index([x.ordinal for x in index]) tm.assert_index_equal(result, exp)
def test_map(self): # test_map_dictlike generally tests index = PeriodIndex([2005, 2007, 2009], freq="A") result = index.map(lambda x: x.ordinal) exp = Index([x.ordinal for x in index]) tm.assert_index_equal(result, exp)
def test_map(self): # test_map_dictlike generally tests index = PeriodIndex([2005, 2007, 2009], freq='A') result = index.map(lambda x: x.ordinal) exp = Index([x.ordinal for x in index]) tm.assert_index_equal(result, exp)
def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] index = PeriodIndex(raw, freq="A") expected = Index([str(num) for num in raw]) res = index.map(str) # should return an Index assert isinstance(res, Index) # preserve element types assert all(isinstance(resi, str) for resi in res) # lastly, values should compare equal tm.assert_index_equal(res, expected)
def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] index = PeriodIndex(raw, freq='A') expected = Index([str(num) for num in raw]) res = index.map(str) # should return an Index assert isinstance(res, Index) # preserve element types assert all(isinstance(resi, str) for resi in res) # lastly, values should compare equal tm.assert_index_equal(res, expected)
def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] index = PeriodIndex(raw, freq='A') types = [str, text_type] for t in types: expected = Index(lmap(t, raw)) res = index.map(t) # should return an Index assert isinstance(res, Index) # preserve element types assert all(isinstance(resi, t) for resi in res) # lastly, values should compare equal tm.assert_index_equal(res, expected)
def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] index = PeriodIndex(raw, freq='A') types = str, if PY3: # unicode types += text_type, for t in types: expected = Index(lmap(t, raw)) res = index.map(t) # should return an Index tm.assertIsInstance(res, Index) # preserve element types self.assertTrue(all(isinstance(resi, t) for resi in res)) # lastly, values should compare equal tm.assert_index_equal(res, expected)