# Path: dynts/conf.py
# def toupper(x):
#     def __init__(self):
#     def special_operators(self):
#     def getdc(self):
#     def ismissing(self, value):
# class Settings(object):
# 
# Path: dynts/exc.py
# class DateNotFound(DyntsException):
#     '''A :class:`DyntsException` exception raised when
#     a date is not found in a :class:`dynts.TimeSeries`.'''
#     pass
# 
# class OutOfBound(DyntsException):
#     '''A :class:`DyntsException` exception raised when
#     trying to access :class:`dynts.TimeSeries` outside its dates range.
#     '''
#     pass
# 
# class RightOutOfBound(OutOfBound):
#     '''A :class:`DyntsOutOfBound` exception raised when
#     trying to access :class:`dynts.TimeSeries` after the end date.'''
#     pass
# 
# Path: dynts/utils/section.py
# def asarray(x, dtype=None):
#     '''Convert ``x`` into a ``numpy.ndarray``.'''
#     iterable = scalarasiter(x)
#     if isinstance(iterable, ndarray):
#         return iterable
#     else:
#         if not hasattr(iterable, '__len__'):
#             iterable = list(iterable)
#         if dtype == object_type:
#             a = ndarray((len(iterable),), dtype=dtype)
#             for i,v in enumerate(iterable):
#                 a[i] = v
#             return a
#         else:
#             return array(iterable, dtype=dtype)


from bisect import bisect_left, bisect_right
from numpy import ndarray
from ..conf import settings
from ..exc import DateNotFound, OutOfBound, RightOutOfBound
from .section import asarray

    '''Wrap a :class:`dynts.TimeSeries` and
expose binary-tree like functionalities. A :class:`dynts.TimeSeries` instance
has a shortcut method which construct a ``asbtree``. Here is an example::

    >>> from dynts.utils.populate import randomts, date
    >>> ts = randomts(cols = 2, start = date(2010, 1, 1), size = 50)
    >>> dts = ts.asbtree()
    >>> sts.find_ge(ts.start())
    1
    >>> sts.find_ge(ts.end())
    49
'''
    def wrap(self):
        ts = self.ts
        self.dates  = asarray(ts.dates())
        self.values = ts.values()

    def __len__(self):
        return len(self.dates)

    def __getitem__(self, dt):
        '''Get the value at *dt* otherwise it raises
an :class:`dynts.exceptions.DateNotFound`.'''
        try:
            index = self.find_ge(dt)
        except OutOfBound:
            raise DateNotFound
        if self.dates[index] == dt:
            return self.values[index]
        else:

# Path: dynts/conf.py
# def toupper(x):
#     def __init__(self):
#     def special_operators(self):
#     def getdc(self):
#     def ismissing(self, value):
# class Settings(object):
# 
# Path: dynts/exc.py
# class DateNotFound(DyntsException):
#     '''A :class:`DyntsException` exception raised when
#     a date is not found in a :class:`dynts.TimeSeries`.'''
#     pass
# 
# class OutOfBound(DyntsException):
#     '''A :class:`DyntsException` exception raised when
#     trying to access :class:`dynts.TimeSeries` outside its dates range.
#     '''
#     pass
# 
# class RightOutOfBound(OutOfBound):
#     '''A :class:`DyntsOutOfBound` exception raised when
#     trying to access :class:`dynts.TimeSeries` after the end date.'''
#     pass
# 
# Path: dynts/utils/section.py
# def asarray(x, dtype=None):
#     '''Convert ``x`` into a ``numpy.ndarray``.'''
#     iterable = scalarasiter(x)
#     if isinstance(iterable, ndarray):
#         return iterable
#     else:
#         if not hasattr(iterable, '__len__'):
#             iterable = list(iterable)
#         if dtype == object_type:
#             a = ndarray((len(iterable),), dtype=dtype)
#             for i,v in enumerate(iterable):
#                 a[i] = v
#             return a
#         else:
#             return array(iterable, dtype=dtype)


# Path: dynts/utils/wrappers.py
from bisect import bisect_left, bisect_right
from numpy import ndarray
from ..conf import settings
from ..exc import DateNotFound, OutOfBound, RightOutOfBound
from .section import asarray

    '''Wrap a :class:`dynts.TimeSeries` and
expose binary-tree like functionalities. A :class:`dynts.TimeSeries` instance
has a shortcut method which construct a ``asbtree``. Here is an example::

    >>> from dynts.utils.populate import randomts, date
    >>> ts = randomts(cols = 2, start = date(2010, 1, 1), size = 50)
    >>> dts = ts.asbtree()
    >>> sts.find_ge(ts.start())
    1
    >>> sts.find_ge(ts.end())
    49
'''
    def wrap(self):
        ts = self.ts
        self.dates  = asarray(ts.dates())
        self.values = ts.values()

    def __len__(self):
        return len(self.dates)

    def __getitem__(self, dt):
        '''Get the value at *dt* otherwise it raises
an :class:`dynts.exceptions.DateNotFound`.'''
        try:
            index = self.find_ge(dt)
        except OutOfBound:
            raise DateNotFound
        if self.dates[index] == dt:
            return self.values[index]
        else:

            raise DateNotFound
