16
16
17
17
from pandas.compat import(
18
18
map, zip, range, long, lrange, lmap, lzip,
19
- OrderedDict, u, StringIO, string_types,
20
- is_platform_windows
19
+ OrderedDict, u, StringIO, is_platform_windows
21
20
)
22
21
from pandas import compat
23
22
33
32
import pandas.core.datetools as datetools
34
33
from pandas import (DataFrame, Index, Series, Panel, notnull, isnull,
35
34
MultiIndex, DatetimeIndex, Timestamp, date_range,
36
- read_csv, timedelta_range, Timedelta, CategoricalIndex,
37
- option_context, period_range)
35
+ read_csv, timedelta_range, Timedelta, option_context, period_range)
38
36
from pandas.core.dtypes import DatetimeTZDtype
39
37
import pandas as pd
40
38
from pandas.parser import CParserError
@@ -2239,7 +2237,6 @@ class TestDataFrame(tm.TestCase, CheckIndexing,
2239
2237
_multiprocess_can_split_ = True
2240
2238
2241
2239
def setUp(self):
2242
- import warnings
2243
2240
2244
2241
self.frame = _frame.copy()
2245
2242
self.frame2 = _frame2.copy()
@@ -3568,6 +3565,20 @@ def test_constructor_tuples(self):
3568
3565
expected = DataFrame({'A': Series([(1, 2), (3, 4)])})
3569
3566
assert_frame_equal(result, expected)
3570
3567
3568
+ def test_constructor_namedtuples(self):
3569
+ # GH11181
3570
+ from collections import namedtuple
3571
+ named_tuple = namedtuple("Pandas", list('ab'))
3572
+ tuples = [named_tuple(1, 3), named_tuple(2, 4)]
3573
+ expected = DataFrame({'a': [1, 2], 'b': [3, 4]})
3574
+ result = DataFrame(tuples)
3575
+ assert_frame_equal(result, expected)
3576
+
3577
+ # with columns
3578
+ expected = DataFrame({'y': [1, 2], 'z': [3, 4]})
3579
+ result = DataFrame(tuples, columns=['y', 'z'])
3580
+ assert_frame_equal(result, expected)
3581
+
3571
3582
def test_constructor_orient(self):
3572
3583
data_dict = self.mixed_frame.T._series
3573
3584
recons = DataFrame.from_dict(data_dict, orient='index')
@@ -4418,7 +4429,7 @@ def test_timedeltas(self):
4418
4429
4419
4430
def test_operators_timedelta64(self):
4420
4431
4421
- from datetime import datetime, timedelta
4432
+ from datetime import timedelta
4422
4433
df = DataFrame(dict(A = date_range('2012-1-1', periods=3, freq='D'),
4423
4434
B = date_range('2012-1-2', periods=3, freq='D'),
4424
4435
C = Timestamp('20120101')-timedelta(minutes=5,seconds=5)))
@@ -9645,7 +9656,6 @@ def test_replace_mixed(self):
9645
9656
assert_frame_equal(result,expected)
9646
9657
9647
9658
# test case from
9648
- from pandas.util.testing import makeCustomDataframe as mkdf
9649
9659
df = DataFrame({'A' : Series([3,0],dtype='int64'), 'B' : Series([0,3],dtype='int64') })
9650
9660
result = df.replace(3, df.mean().to_dict())
9651
9661
expected = df.copy().astype('float64')
@@ -12227,7 +12237,6 @@ def test_sort_index_inplace(self):
12227
12237
assert_frame_equal(df, expected)
12228
12238
12229
12239
def test_sort_index_different_sortorder(self):
12230
- import random
12231
12240
A = np.arange(20).repeat(5)
12232
12241
B = np.tile(np.arange(5), 20)
12233
12242
@@ -13301,7 +13310,6 @@ def test_quantile(self):
13301
13310
13302
13311
def test_quantile_axis_parameter(self):
13303
13312
# GH 9543/9544
13304
- from numpy import percentile
13305
13313
13306
13314
df = DataFrame({"A": [1, 2, 3], "B": [2, 3, 4]}, index=[1, 2, 3])
13307
13315
@@ -16093,8 +16101,6 @@ def test_query_doesnt_pickup_local(self):
16093
16101
n = m = 10
16094
16102
df = DataFrame(np.random.randint(m, size=(n, 3)), columns=list('abc'))
16095
16103
16096
- from numpy import sin
16097
-
16098
16104
# we don't pick up the local 'sin'
16099
16105
with tm.assertRaises(UndefinedVariableError):
16100
16106
df.query('sin > 5', engine=engine, parser=parser)
@@ -16392,7 +16398,6 @@ def setUpClass(cls):
16392
16398
cls.frame = _frame.copy()
16393
16399
16394
16400
def test_query_builtin(self):
16395
- from pandas.computation.engines import NumExprClobberingError
16396
16401
engine, parser = self.engine, self.parser
16397
16402
16398
16403
n = m = 10
@@ -16413,7 +16418,6 @@ def setUpClass(cls):
16413
16418
cls.frame = _frame.copy()
16414
16419
16415
16420
def test_query_builtin(self):
16416
- from pandas.computation.engines import NumExprClobberingError
16417
16421
engine, parser = self.engine, self.parser
16418
16422
16419
16423
n = m = 10
0 commit comments