diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 94f151efbe2a6..b234773359f8c 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -6,6 +6,7 @@ import nose from nose.tools import assert_equal, assert_true import numpy as np +import pandas as pd from pandas.tslib import iNaT, NaT from pandas import Series, DataFrame, date_range, DatetimeIndex, Timestamp, Float64Index from pandas import compat @@ -40,6 +41,7 @@ def __getitem__(self): assert(not is_seq(A())) + def test_get_callable_name(): from functools import partial getname = com._get_callable_name @@ -49,6 +51,7 @@ def fn(x): lambda_ = lambda x: x part1 = partial(fn) part2 = partial(part1) + class somecall(object): def __call__(self): return x @@ -60,6 +63,38 @@ def __call__(self): assert getname(somecall()) == 'somecall' assert getname(1) is None +#Issue 10859 +class TestABCClasses(tm.TestCase): + tuples = [[1, 2, 2], ['red', 'blue', 'red']] + multi_index = pd.MultiIndex.from_arrays(tuples, names=('number', 'color')) + datetime_index = pd.to_datetime(['2000/1/1', '2010/1/1']) + timedelta_index = pd.to_timedelta(np.arange(5), unit='s') + period_index = pd.period_range('2000/1/1', '2010/1/1/', freq='M') + categorical = pd.Categorical([1, 2, 3], categories=[2, 3, 1]) + categorical_df = pd.DataFrame({"values": [1, 2, 3]}, index=categorical) + df = pd.DataFrame({'names': ['a', 'b', 'c']}, index=multi_index) + sparse_series = pd.Series([1, 2, 3]).to_sparse() + sparse_array = pd.SparseArray(np.random.randn(10)) + + def test_abc_types(self): + self.assertIsInstance(pd.Index(['a', 'b', 'c']), com.ABCIndex) + self.assertIsInstance(pd.Int64Index([1, 2, 3]), com.ABCInt64Index) + self.assertIsInstance(pd.Float64Index([1, 2, 3]), com.ABCFloat64Index) + self.assertIsInstance(self.multi_index, com.ABCMultiIndex) + self.assertIsInstance(self.datetime_index, com.ABCDatetimeIndex) + self.assertIsInstance(self.timedelta_index, com.ABCTimedeltaIndex) + self.assertIsInstance(self.period_index, com.ABCPeriodIndex) + self.assertIsInstance(self.categorical_df.index, com.ABCCategoricalIndex) + self.assertIsInstance(pd.Index(['a', 'b', 'c']), com.ABCIndexClass) + self.assertIsInstance(pd.Int64Index([1, 2, 3]), com.ABCIndexClass) + self.assertIsInstance(pd.Series([1, 2, 3]), com.ABCSeries) + self.assertIsInstance(self.df, com.ABCDataFrame) + self.assertIsInstance(self.df.to_panel(), com.ABCPanel) + self.assertIsInstance(self.sparse_series, com.ABCSparseSeries) + self.assertIsInstance(self.sparse_array, com.ABCSparseArray) + self.assertIsInstance(self.categorical, com.ABCCategorical) + self.assertIsInstance(pd.Period('2012', freq='A-DEC'), com.ABCPeriod) + def test_notnull(): assert notnull(1.) @@ -942,7 +977,7 @@ def test_2d_float32(self): def test_2d_datetime64(self): # 2005/01/01 - 2006/01/01 - arr = np.random.randint(long(11045376), long(11360736), (5,3))*100000000000 + arr = np.random.randint(long(11045376), long(11360736), (5, 3))*100000000000 arr = arr.view(dtype='datetime64[ns]') indexer = [0, 2, -1, 1, -1] @@ -1026,6 +1061,7 @@ def test_dict_compat(): assert(com._dict_compat(expected) == expected) assert(com._dict_compat(data_unchanged) == data_unchanged) + def test_possibly_convert_objects_copy(): values = np.array([1, 2])