Skip to content

Commit b301d82

Browse files
committed
Added tests for ABC Types, Issue pandas-dev#10828
1 parent d27068f commit b301d82

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

pandas/tests/test_common.py

+48-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import nose
77
from nose.tools import assert_equal, assert_true
88
import numpy as np
9+
import pandas as pd
910
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
1112
from pandas import compat
1213
from pandas.compat import range, long, lrange, lmap, u
1314
from pandas.core.common import notnull, isnull, array_equivalent
@@ -40,6 +41,7 @@ def __getitem__(self):
4041

4142
assert(not is_seq(A()))
4243

44+
4345
def test_get_callable_name():
4446
from functools import partial
4547
getname = com._get_callable_name
@@ -49,6 +51,7 @@ def fn(x):
4951
lambda_ = lambda x: x
5052
part1 = partial(fn)
5153
part2 = partial(part1)
54+
5255
class somecall(object):
5356
def __call__(self):
5457
return x
@@ -61,6 +64,48 @@ def __call__(self):
6164
assert getname(1) is None
6265

6366

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+
64109
def test_notnull():
65110
assert notnull(1.)
66111
assert not notnull(None)
@@ -229,8 +274,6 @@ def test_array_equivalent():
229274
assert not array_equivalent(np.array([np.nan, 1, np.nan]),
230275
np.array([np.nan, 2, np.nan]))
231276
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]))
234277
assert array_equivalent(DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan]))
235278
assert not array_equivalent(DatetimeIndex([0, np.nan]), DatetimeIndex([1, np.nan]))
236279

@@ -942,7 +985,7 @@ def test_2d_float32(self):
942985

943986
def test_2d_datetime64(self):
944987
# 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
946989
arr = arr.view(dtype='datetime64[ns]')
947990
indexer = [0, 2, -1, 1, -1]
948991

@@ -1026,6 +1069,7 @@ def test_dict_compat():
10261069
assert(com._dict_compat(expected) == expected)
10271070
assert(com._dict_compat(data_unchanged) == data_unchanged)
10281071

1072+
10291073
def test_possibly_convert_objects_copy():
10301074
values = np.array([1, 2])
10311075

0 commit comments

Comments
 (0)