From b301d82fcd58f4af317e868f63b15bc5464ee966 Mon Sep 17 00:00:00 2001 From: Daniel Ni Date: Wed, 19 Aug 2015 04:55:00 -0500 Subject: [PATCH 1/3] Added tests for ABC Types, Issue #10828 --- pandas/tests/test_common.py | 52 ++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 94f151efbe2a6..d31e02d4b3a50 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -6,8 +6,9 @@ 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 Series, DataFrame, date_range, DatetimeIndex, Timestamp from pandas import compat from pandas.compat import range, long, lrange, lmap, u from pandas.core.common import notnull, isnull, array_equivalent @@ -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 @@ -61,6 +64,48 @@ def __call__(self): assert getname(1) is None +def test_abc_types(): + tuples = [('bar', 'one'), ('bar', 'two')] + names = ['first', 'second'] + values = [1, 2, 3, 4] + index = pd.Index(['a', 'b', 'c']) + int64_index = pd.Int64Index([1, 2, 3]) + float64_index = pd.Float64Index([1, 2, 3]) + multi_index = pd.MultiIndex.from_tuples(tuples, names=names) + 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, 4], categories=[4, 2, 3, 1]) + categorical_df = pd.DataFrame({"values": values}, index=categorical) + categorical_index = categorical_df.index + series = pd.Series(values) + df = pd.DataFrame({"names": names}, index=multi_index) + panel = df.to_panel() + sparse_series = series.to_sparse() + sparse_array = pd.SparseArray(np.random.randn(10)) + period = pd.Period('2012', freq='A-DEC') + + assert(isinstance(index, com.ABCIndex)) + assert(isinstance(int64_index, com.ABCInt64Index)) + assert(isinstance(float64_index, com.ABCFloat64Index)) + assert(isinstance(multi_index, com.ABCMultiIndex)) + assert(isinstance(datetime_index, com.ABCDatetimeIndex)) + assert(isinstance(timedelta_index, com.ABCTimedeltaIndex)) + assert(isinstance(period_index, com.ABCPeriodIndex)) + assert(isinstance(categorical_index, com.ABCCategoricalIndex)) + assert(isinstance(index, com.ABCIndexClass)) + assert(isinstance(int64_index, com.ABCIndexClass)) + assert(isinstance(series, com.ABCSeries)) + assert(isinstance(df, com.ABCDataFrame)) + assert(isinstance(panel, com.ABCPanel)) + assert(isinstance(sparse_series, com.ABCSparseSeries)) + assert(isinstance(sparse_array, com.ABCSparseArray)) + assert(isinstance(categorical, com.ABCCategorical)) + assert(isinstance(period, com.ABCPeriod)) + + + + def test_notnull(): assert notnull(1.) assert not notnull(None) @@ -229,8 +274,6 @@ def test_array_equivalent(): assert not array_equivalent(np.array([np.nan, 1, np.nan]), np.array([np.nan, 2, np.nan])) assert not array_equivalent(np.array(['a', 'b', 'c', 'd']), np.array(['e', 'e'])) - assert array_equivalent(Float64Index([0, np.nan]), Float64Index([0, np.nan])) - assert not array_equivalent(Float64Index([0, np.nan]), Float64Index([1, np.nan])) assert array_equivalent(DatetimeIndex([0, np.nan]), DatetimeIndex([0, np.nan])) assert not array_equivalent(DatetimeIndex([0, np.nan]), DatetimeIndex([1, np.nan])) @@ -942,7 +985,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 +1069,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]) From c46ff07c985bbcc8b12bc076854aa018bec654c5 Mon Sep 17 00:00:00 2001 From: Daniel Ni Date: Wed, 19 Aug 2015 05:02:08 -0500 Subject: [PATCH 2/3] Added tests for ABC Types, Issue #10828 --- pandas/tests/test_common.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index d31e02d4b3a50..4e10363d39e57 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -104,8 +104,6 @@ def test_abc_types(): assert(isinstance(period, com.ABCPeriod)) - - def test_notnull(): assert notnull(1.) assert not notnull(None) From 1ec75e1b1a6c370fc1873b64b8dc4cf153f9eb31 Mon Sep 17 00:00:00 2001 From: Daniel Ni Date: Wed, 19 Aug 2015 05:08:49 -0500 Subject: [PATCH 3/3] Added tests for ABC Types, Issue #10828 --- pandas/tests/test_common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 4e10363d39e57..df1e30817adbc 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -84,7 +84,6 @@ def test_abc_types(): sparse_series = series.to_sparse() sparse_array = pd.SparseArray(np.random.randn(10)) period = pd.Period('2012', freq='A-DEC') - assert(isinstance(index, com.ABCIndex)) assert(isinstance(int64_index, com.ABCInt64Index)) assert(isinstance(float64_index, com.ABCFloat64Index))