6
6
import nose
7
7
from nose .tools import assert_equal , assert_true
8
8
import numpy as np
9
+ import pandas as pd
9
10
from pandas .tslib import iNaT , NaT
10
- from pandas import Series , DataFrame , date_range , DatetimeIndex , Timestamp , Float64Index
11
+ from pandas import Series , DataFrame , date_range , DatetimeIndex , Timestamp
11
12
from pandas import compat
12
13
from pandas .compat import range , long , lrange , lmap , u
13
14
from pandas .core .common import notnull , isnull , array_equivalent
@@ -40,6 +41,7 @@ def __getitem__(self):
40
41
41
42
assert (not is_seq (A ()))
42
43
44
+
43
45
def test_get_callable_name ():
44
46
from functools import partial
45
47
getname = com ._get_callable_name
@@ -49,6 +51,7 @@ def fn(x):
49
51
lambda_ = lambda x : x
50
52
part1 = partial (fn )
51
53
part2 = partial (part1 )
54
+
52
55
class somecall (object ):
53
56
def __call__ (self ):
54
57
return x
@@ -61,6 +64,48 @@ def __call__(self):
61
64
assert getname (1 ) is None
62
65
63
66
67
+ def test_abc_types ():
68
+ tuples = [('bar' , 'one' ), ('bar' , 'two' )]
69
+ names = ['first' , 'second' ]
70
+ values = [1 , 2 , 3 , 4 ]
71
+ index = pd .Index (['a' , 'b' , 'c' ])
72
+ int64_index = pd .Int64Index ([1 , 2 , 3 ])
73
+ float64_index = pd .Float64Index ([1 , 2 , 3 ])
74
+ multi_index = pd .MultiIndex .from_tuples (tuples , names = names )
75
+ datetime_index = pd .to_datetime (['2000/1/1' , '2010/1/1' ])
76
+ timedelta_index = pd .to_timedelta (np .arange (5 ), unit = 's' )
77
+ period_index = pd .period_range ('2000/1/1' , '2010/1/1/' , freq = 'M' )
78
+ categorical = pd .Categorical ([1 , 2 , 3 , 4 ], categories = [4 , 2 , 3 , 1 ])
79
+ categorical_df = pd .DataFrame ({"values" : values }, index = categorical )
80
+ categorical_index = categorical_df .index
81
+ series = pd .Series (values )
82
+ df = pd .DataFrame ({"names" : names }, index = multi_index )
83
+ panel = df .to_panel ()
84
+ sparse_series = series .to_sparse ()
85
+ sparse_array = pd .SparseArray (np .random .randn (10 ))
86
+ period = pd .Period ('2012' , freq = 'A-DEC' )
87
+
88
+ assert (isinstance (index , com .ABCIndex ))
89
+ assert (isinstance (int64_index , com .ABCInt64Index ))
90
+ assert (isinstance (float64_index , com .ABCFloat64Index ))
91
+ assert (isinstance (multi_index , com .ABCMultiIndex ))
92
+ assert (isinstance (datetime_index , com .ABCDatetimeIndex ))
93
+ assert (isinstance (timedelta_index , com .ABCTimedeltaIndex ))
94
+ assert (isinstance (period_index , com .ABCPeriodIndex ))
95
+ assert (isinstance (categorical_index , com .ABCCategoricalIndex ))
96
+ assert (isinstance (index , com .ABCIndexClass ))
97
+ assert (isinstance (int64_index , com .ABCIndexClass ))
98
+ assert (isinstance (series , com .ABCSeries ))
99
+ assert (isinstance (df , com .ABCDataFrame ))
100
+ assert (isinstance (panel , com .ABCPanel ))
101
+ assert (isinstance (sparse_series , com .ABCSparseSeries ))
102
+ assert (isinstance (sparse_array , com .ABCSparseArray ))
103
+ assert (isinstance (categorical , com .ABCCategorical ))
104
+ assert (isinstance (period , com .ABCPeriod ))
105
+
106
+
107
+
108
+
64
109
def test_notnull ():
65
110
assert notnull (1. )
66
111
assert not notnull (None )
@@ -229,8 +274,6 @@ def test_array_equivalent():
229
274
assert not array_equivalent (np .array ([np .nan , 1 , np .nan ]),
230
275
np .array ([np .nan , 2 , np .nan ]))
231
276
assert not array_equivalent (np .array (['a' , 'b' , 'c' , 'd' ]), np .array (['e' , 'e' ]))
232
- assert array_equivalent (Float64Index ([0 , np .nan ]), Float64Index ([0 , np .nan ]))
233
- assert not array_equivalent (Float64Index ([0 , np .nan ]), Float64Index ([1 , np .nan ]))
234
277
assert array_equivalent (DatetimeIndex ([0 , np .nan ]), DatetimeIndex ([0 , np .nan ]))
235
278
assert not array_equivalent (DatetimeIndex ([0 , np .nan ]), DatetimeIndex ([1 , np .nan ]))
236
279
@@ -942,7 +985,7 @@ def test_2d_float32(self):
942
985
943
986
def test_2d_datetime64 (self ):
944
987
# 2005/01/01 - 2006/01/01
945
- arr = np .random .randint (long (11045376 ), long (11360736 ), (5 ,3 ))* 100000000000
988
+ arr = np .random .randint (long (11045376 ), long (11360736 ), (5 , 3 ))* 100000000000
946
989
arr = arr .view (dtype = 'datetime64[ns]' )
947
990
indexer = [0 , 2 , - 1 , 1 , - 1 ]
948
991
@@ -1026,6 +1069,7 @@ def test_dict_compat():
1026
1069
assert (com ._dict_compat (expected ) == expected )
1027
1070
assert (com ._dict_compat (data_unchanged ) == data_unchanged )
1028
1071
1072
+
1029
1073
def test_possibly_convert_objects_copy ():
1030
1074
values = np .array ([1 , 2 ])
1031
1075
0 commit comments