Skip to content

Commit 18012f0

Browse files
DanNi0130jreback
authored andcommitted
Added tests for ABC Types, Issue pandas-dev#10828
1 parent 08e055b commit 18012f0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

pandas/tests/test_common.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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
1011
from pandas import Series, DataFrame, date_range, DatetimeIndex, Timestamp, Float64Index
1112
from pandas import compat
@@ -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
@@ -60,6 +63,38 @@ def __call__(self):
6063
assert getname(somecall()) == 'somecall'
6164
assert getname(1) is None
6265

66+
#Issue 10859
67+
class TestABCClasses(tm.TestCase):
68+
tuples = [[1, 2, 2], ['red', 'blue', 'red']]
69+
multi_index = pd.MultiIndex.from_arrays(tuples, names=('number', 'color'))
70+
datetime_index = pd.to_datetime(['2000/1/1', '2010/1/1'])
71+
timedelta_index = pd.to_timedelta(np.arange(5), unit='s')
72+
period_index = pd.period_range('2000/1/1', '2010/1/1/', freq='M')
73+
categorical = pd.Categorical([1, 2, 3], categories=[2, 3, 1])
74+
categorical_df = pd.DataFrame({"values": [1, 2, 3]}, index=categorical)
75+
df = pd.DataFrame({'names': ['a', 'b', 'c']}, index=multi_index)
76+
sparse_series = pd.Series([1, 2, 3]).to_sparse()
77+
sparse_array = pd.SparseArray(np.random.randn(10))
78+
79+
def test_abc_types(self):
80+
self.assertIsInstance(pd.Index(['a', 'b', 'c']), com.ABCIndex)
81+
self.assertIsInstance(pd.Int64Index([1, 2, 3]), com.ABCInt64Index)
82+
self.assertIsInstance(pd.Float64Index([1, 2, 3]), com.ABCFloat64Index)
83+
self.assertIsInstance(self.multi_index, com.ABCMultiIndex)
84+
self.assertIsInstance(self.datetime_index, com.ABCDatetimeIndex)
85+
self.assertIsInstance(self.timedelta_index, com.ABCTimedeltaIndex)
86+
self.assertIsInstance(self.period_index, com.ABCPeriodIndex)
87+
self.assertIsInstance(self.categorical_df.index, com.ABCCategoricalIndex)
88+
self.assertIsInstance(pd.Index(['a', 'b', 'c']), com.ABCIndexClass)
89+
self.assertIsInstance(pd.Int64Index([1, 2, 3]), com.ABCIndexClass)
90+
self.assertIsInstance(pd.Series([1, 2, 3]), com.ABCSeries)
91+
self.assertIsInstance(self.df, com.ABCDataFrame)
92+
self.assertIsInstance(self.df.to_panel(), com.ABCPanel)
93+
self.assertIsInstance(self.sparse_series, com.ABCSparseSeries)
94+
self.assertIsInstance(self.sparse_array, com.ABCSparseArray)
95+
self.assertIsInstance(self.categorical, com.ABCCategorical)
96+
self.assertIsInstance(pd.Period('2012', freq='A-DEC'), com.ABCPeriod)
97+
6398

6499
def test_notnull():
65100
assert notnull(1.)
@@ -942,7 +977,7 @@ def test_2d_float32(self):
942977

943978
def test_2d_datetime64(self):
944979
# 2005/01/01 - 2006/01/01
945-
arr = np.random.randint(long(11045376), long(11360736), (5,3))*100000000000
980+
arr = np.random.randint(long(11045376), long(11360736), (5, 3))*100000000000
946981
arr = arr.view(dtype='datetime64[ns]')
947982
indexer = [0, 2, -1, 1, -1]
948983

@@ -1026,6 +1061,7 @@ def test_dict_compat():
10261061
assert(com._dict_compat(expected) == expected)
10271062
assert(com._dict_compat(data_unchanged) == data_unchanged)
10281063

1064+
10291065
def test_possibly_convert_objects_copy():
10301066
values = np.array([1, 2])
10311067

0 commit comments

Comments
 (0)