Skip to content

Tests for ABC Types #10859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion pandas/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.)
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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])

Expand Down