# Path: argos/repo/memoryrtis.py
# class MappingRti(BaseRti):
#     """ Represents a mapping (e.g. a dictionary)
#     """
#     _defaultIconGlyph = RtiIconFactory.FOLDER
# 
#     def __init__(self, dictionary,
#                  nodeName='', iconColor=ICON_COLOR_MEMORY, fileName='', attributes=None):
#         """ Constructor.
#             The dictionary may be None for under(or None for undefined/unopened nodes)
#         """
#         super(MappingRti, self).__init__(nodeName=nodeName, iconColor=iconColor, fileName=fileName)
#         check_is_a_mapping(dictionary, allow_none=True)
#         self._dictionary = dictionary
#         self._attributes = {} if attributes is None else attributes
# 
# 
#     @property
#     def attributes(self):
#         """ The attribute dictionary.
#             Reimplemented from BaseRti: the attribute dictionary is stored per-object.
#         """
#         return self._attributes
# 
# 
#     @property
#     def dimensionality(self):
#         """ String that describes if the RTI is an array, scalar, field, etc.
#         """
#         return ""  # Return empty string to be in line with directories, groups, etc
# 
# 
#     @property
#     def elementTypeName(self):
#         """ String representation of the element type.
#         """
#         if self._dictionary is None:
#             return super(MappingRti, self).elementTypeName
#         else:
#             return '' # A dictionary has no single element type
#             #return type_name(self._dictionary)
# 
# 
#     @property
#     def summary(self):
#         """ Returns a summary of the contents of the RTI.  E.g. 'array 20 x 30' elements.
#         """
#         return ""  # Don't show length info, so it has the same behaviour as directory and groups.
#         # if self._dictionary is None:
#         #     return ""
#         # else:
#         #     return lengthToSummary(len(self._dictionary))
# 
# 
#     def _fetchAllChildren(self):
#         """ Adds a child item for each item
#         """
#         childItems = []
#         logger.debug("_fetchAllChildren of {!r} ({}):  {!r}"
#                      .format(self, self.iconColor, self.fileName))
# 
#         if self.hasChildren():
#             for key, value in sorted(self._dictionary.items()):
#                 childItem = _createFromObject(value, nodeName=str(key), iconColor=self.iconColor,
#                                               fileName=self.fileName)
#                 childItems.append(childItem)
# 
#         return childItems
# 
# class SyntheticArrayRti(ArrayRti):
#     """ Calls a function that yields a Numpy array when the RTI is opened.
# 
#         Useful for creating test data.
#     """
#     def __init__(self, nodeName='', fun=None):
#         """ Constructor. Initializes as an ArrayRTI with None as underlying array.
#         """
#         super(SyntheticArrayRti, self).__init__(None, nodeName=nodeName, iconColor=ICON_COLOR_MEMORY)
#         assert callable(fun), "fun parameter should be callable"
#         self._fun = fun
# 
# 
#     def hasChildren(self):
#         """ Returns True if the item has (fetched or unfetched) children
# 
#             Returns True so that the function can be called, even though the array has no children.
#         """
#         return True
# 
# 
#     def _openResources(self):
#         """ Evaluates the function to result an array
#         """
#         arr = self._fun()
#         check_is_an_array(arr)
#         self._array = arr
# 
# 
#     def _closeResources(self):
#         """ Closes the underlying resources
#         """
#         self._array = None
# 
# Path: argos/repo/registry.py
# ICON_COLOR_MEMORY = RtiIconFactory.COLOR_MEMORY
# 
# ICON_COLOR_PANDAS = '#FB9A99'
# 
# Path: argos/utils/moduleinfo.py
# def versionStrToTuple(versionStr):
#     """ Converts a version string to tuple
# 
#         Version string has format <major>.<minor>.<patch><postfix> where postfix can be empty.
#             E.g. versionStrToTuple('0.3.1rc1') returns (0, 3, 1, 'rc1')
#     """
#     matchObj = re.match(r"(\d+)\.(\d+)\.(\d+)(\w*)", versionStr)
# 
#     major = int(matchObj.group(1))
#     minor = int(matchObj.group(2))
#     patch = int(matchObj.group(3))
#     postfix = matchObj.group(4)
# 
#     return (major, minor, patch, postfix)


import logging
import warnings
import numpy as np
import numpy.ma as ma
        import pandas as pd
from decimal import Decimal
from argos.repo.memoryrtis import MappingRti, SyntheticArrayRti
from argos.repo.registry import ICON_COLOR_MEMORY, ICON_COLOR_PANDAS
from argos.utils.moduleinfo import versionStrToTuple
        from argos.repo.rtiplugins.pandasio import (PandasSeriesRti, PandasDataFrameRti,
                                                    PandasPanelRti)

    with warnings.catch_warnings():
        # Ignore future warnins about Panel
        warnings.simplefilter(action='ignore', category=FutureWarning)
        addPandasTestData(mappingRti)

    return mappingRti


def addPandasTestData(rti):
    """ Add some Pandas child RTIs to the rti
    """
    try:
    except ImportError as ex:
        logger.warning("No pandas test data created: {}".format(ex))
        return

    versionInfo = versionStrToTuple(pd.__version__)

    pandsRti = rti.insertChild(MappingRti({}, nodeName="pandas"))

    s = pd.Series([1, 2, 3, -4, 5], index=list('abcde'), name='simple series')
    pandsRti.insertChild(PandasSeriesRti(s, s.name, iconColor=ICON_COLOR_PANDAS))


    df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
                       'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
                       'C' : np.random.randn(8),
                       'D' : np.random.randn(8)})


# Path: argos/repo/memoryrtis.py
# class MappingRti(BaseRti):
#     """ Represents a mapping (e.g. a dictionary)
#     """
#     _defaultIconGlyph = RtiIconFactory.FOLDER
# 
#     def __init__(self, dictionary,
#                  nodeName='', iconColor=ICON_COLOR_MEMORY, fileName='', attributes=None):
#         """ Constructor.
#             The dictionary may be None for under(or None for undefined/unopened nodes)
#         """
#         super(MappingRti, self).__init__(nodeName=nodeName, iconColor=iconColor, fileName=fileName)
#         check_is_a_mapping(dictionary, allow_none=True)
#         self._dictionary = dictionary
#         self._attributes = {} if attributes is None else attributes
# 
# 
#     @property
#     def attributes(self):
#         """ The attribute dictionary.
#             Reimplemented from BaseRti: the attribute dictionary is stored per-object.
#         """
#         return self._attributes
# 
# 
#     @property
#     def dimensionality(self):
#         """ String that describes if the RTI is an array, scalar, field, etc.
#         """
#         return ""  # Return empty string to be in line with directories, groups, etc
# 
# 
#     @property
#     def elementTypeName(self):
#         """ String representation of the element type.
#         """
#         if self._dictionary is None:
#             return super(MappingRti, self).elementTypeName
#         else:
#             return '' # A dictionary has no single element type
#             #return type_name(self._dictionary)
# 
# 
#     @property
#     def summary(self):
#         """ Returns a summary of the contents of the RTI.  E.g. 'array 20 x 30' elements.
#         """
#         return ""  # Don't show length info, so it has the same behaviour as directory and groups.
#         # if self._dictionary is None:
#         #     return ""
#         # else:
#         #     return lengthToSummary(len(self._dictionary))
# 
# 
#     def _fetchAllChildren(self):
#         """ Adds a child item for each item
#         """
#         childItems = []
#         logger.debug("_fetchAllChildren of {!r} ({}):  {!r}"
#                      .format(self, self.iconColor, self.fileName))
# 
#         if self.hasChildren():
#             for key, value in sorted(self._dictionary.items()):
#                 childItem = _createFromObject(value, nodeName=str(key), iconColor=self.iconColor,
#                                               fileName=self.fileName)
#                 childItems.append(childItem)
# 
#         return childItems
# 
# class SyntheticArrayRti(ArrayRti):
#     """ Calls a function that yields a Numpy array when the RTI is opened.
# 
#         Useful for creating test data.
#     """
#     def __init__(self, nodeName='', fun=None):
#         """ Constructor. Initializes as an ArrayRTI with None as underlying array.
#         """
#         super(SyntheticArrayRti, self).__init__(None, nodeName=nodeName, iconColor=ICON_COLOR_MEMORY)
#         assert callable(fun), "fun parameter should be callable"
#         self._fun = fun
# 
# 
#     def hasChildren(self):
#         """ Returns True if the item has (fetched or unfetched) children
# 
#             Returns True so that the function can be called, even though the array has no children.
#         """
#         return True
# 
# 
#     def _openResources(self):
#         """ Evaluates the function to result an array
#         """
#         arr = self._fun()
#         check_is_an_array(arr)
#         self._array = arr
# 
# 
#     def _closeResources(self):
#         """ Closes the underlying resources
#         """
#         self._array = None
# 
# Path: argos/repo/registry.py
# ICON_COLOR_MEMORY = RtiIconFactory.COLOR_MEMORY
# 
# ICON_COLOR_PANDAS = '#FB9A99'
# 
# Path: argos/utils/moduleinfo.py
# def versionStrToTuple(versionStr):
#     """ Converts a version string to tuple
# 
#         Version string has format <major>.<minor>.<patch><postfix> where postfix can be empty.
#             E.g. versionStrToTuple('0.3.1rc1') returns (0, 3, 1, 'rc1')
#     """
#     matchObj = re.match(r"(\d+)\.(\d+)\.(\d+)(\w*)", versionStr)
# 
#     major = int(matchObj.group(1))
#     minor = int(matchObj.group(2))
#     patch = int(matchObj.group(3))
#     postfix = matchObj.group(4)
# 
#     return (major, minor, patch, postfix)


# Path: argos/repo/testdata.py
import logging
import warnings
import numpy as np
import numpy.ma as ma
        import pandas as pd
from decimal import Decimal
from argos.repo.memoryrtis import MappingRti, SyntheticArrayRti
from argos.repo.registry import ICON_COLOR_MEMORY, ICON_COLOR_PANDAS
from argos.utils.moduleinfo import versionStrToTuple
        from argos.repo.rtiplugins.pandasio import (PandasSeriesRti, PandasDataFrameRti,
                                                    PandasPanelRti)


    with warnings.catch_warnings():
        # Ignore future warnins about Panel
        warnings.simplefilter(action='ignore', category=FutureWarning)
        addPandasTestData(mappingRti)

    return mappingRti


def addPandasTestData(rti):
    """ Add some Pandas child RTIs to the rti
    """
    try:
    except ImportError as ex:
        logger.warning("No pandas test data created: {}".format(ex))
        return

    versionInfo = versionStrToTuple(pd.__version__)

    pandsRti = rti.insertChild(MappingRti({}, nodeName="pandas"))

    s = pd.Series([1, 2, 3, -4, 5], index=list('abcde'), name='simple series')
    pandsRti.insertChild(PandasSeriesRti(s, s.name, iconColor=ICON_COLOR_PANDAS))


    df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
                       'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
                       'C' : np.random.randn(8),
                       'D' : np.random.randn(8)})


    pandsRti.insertChild(PandasDataFrameRti(df, 'df', iconColor=ICON_COLOR_PANDAS))