8000 [WIP] Add basic ExtensionIndex class by jorisvandenbossche · Pull Request #23223 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Add basic ExtensionIndex class #23223

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
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
clean-up
  • Loading branch information
jorisvandenbossche committed Oct 18, 2018
commit 9e282c96fbf9cd0f0c5df14ecbd1e23fcdf4ba0d
83 changes: 18 additions & 65 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,19 @@
from datetime import datetime, timedelta
import warnings
import operator
from textwrap import dedent

import numpy as np
from pandas._libs import (lib, index as libindex, tslibs,
algos as libalgos, join as libjoin,
Timedelta)
from pandas._libs.lib import is_datetime_array
from pandas._libs import index as libindex

# from pandas._libs import (lib, index as libindex, tslibs,
# algos as libalgos, join as libjoin,
# Timedelta)

from pandas.compat import range, u, set_function_name
from pandas.compat.numpy import function as nv
from pandas import compat

from pandas.core.accessor import CachedAccessor
from pandas.core.arrays import ExtensionArray
from pandas.core.dtypes.generic import (
ABCSeries, ABCDataFrame,
ABCMultiIndex,
ABCPeriodIndex, ABCTimedeltaIndex,
ABCDateOffset)
from pandas.core.dtypes.missing import isna, array_equivalent
from pandas.core.dtypes.cast import maybe_cast_to_integer_array
from pandas.core.dtypes.common import (
ensure_int64,
ensure_object,
ensure_categorical,
ensure_platform_int,
is_integer,
is_float,
is_dtype_equal,
is_dtype_union_equal,
is_object_dtype,
is_categorical,
is_categorical_dtype,
is_interval_dtype,
is_period_dtype,
is_bool,
is_bool_dtype,
is_signed_integer_dtype,
is_unsigned_integer_dtype,
is_integer_dtype, is_float_dtype,
is_datetime64_any_dtype,
is_datetime64tz_dtype,
is_timedelta64_dtype,
is_extension_array_dtype,
is_hashable,
is_iterator, is_list_like,
is_scalar)

from pandas.core.base import PandasObject, IndexOpsMixin
import pandas.core.common as com
from pandas.core import ops
is_integer_dtype, is_float_dtype)

from pandas.util._decorators import (
Appender, Substitution, cache_readonly)
from pandas.core.indexes.frozen import FrozenList
import pandas.core.indexes.base as ibase
import pandas.core.dtypes.concat as _concat
import pandas.core.missing as missing
import pandas.core.algorithms as algos
import pandas.core.sorting as sorting
from pandas.io.formats.printing import (
pprint_thing, default_pprint, format_object_summary, format_object_attrs)
from pandas.core.ops import make_invalid_op
from pandas.core.strings import StringMethods
Appender, cache_readonly)

from .base import Index

Expand All @@ -81,7 +31,8 @@

class ExtensionIndex(Index):
"""

Index class that holds an ExtensionArray.

"""
_typ = 'extensionindex'
_comparables = ['name']
Expand All @@ -92,7 +43,8 @@ class ExtensionIndex(Index):
@property
def _is_numeric_dtype(self):
return self.dtype._is_numeric


# TODO
# # would we like our indexing holder to defer to us
# _defer_to_indexing = False

Expand All @@ -104,8 +56,9 @@ def __new__(cls, *args, **kwargs):
return object.__new__(cls)

def __init__(self, array, name=None, copy=False, **kwargs):
# needs to accept and ignore kwargs eg for freq passed in Index._shallow_copy_with_infer

# needs to accept and ignore kwargs eg for freq passed in
# Index._shallow_copy_with_infer

if isinstance(array, ExtensionIndex):
array = array._data

Expand All @@ -121,15 +74,15 @@ def __len__(self):
return the length of the Index
"""
return len(self._data)

@property
def size(self):
# EA does not have .size
return len(self._data)

def __array__(self, dtype=None):
""" the array interface, return my values """
return np.array(self._values)
return np.array(self._data)

@cache_readonly
def dtype(self):
Expand Down Expand Up @@ -165,7 +118,7 @@ def _engine_type(self):
# TODO add more
else:
return libindex.ObjectEngine

@cache_readonly
def _engine(self):
# property, for now, slow to look up
Expand Down
0