<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2015-2016, Exa Analytics Development Team
# Distributed under the terms of the Apache License 2.0
"""
Discrete Data Objects
###################################
Custom discrete data objects (such as series, dataframes, etc.) provide easy
description of relationships. There are three types of relationships, one-to-one
(matching index names), one-to-many (index name in columns), and many-to-many
(matching columns).
"""
import six
import pandas as pd
from exa.core.typed import TypedMeta
from exa.cms.unit import (Length, Mass, Time, Current, Amount, Luminosity,
                          Dose, Acceleration, Charge, Dipole, Energy, Force,
                          Frequency, MolarMass, Dimension, unit_list)


class Base(object):
    """Base class for discrete data objects."""
    def convert_units(self, to_unit):
        """Convert units."""
        from_unit = self.units
        unit = self._dim
        if unit is not None:
            self.values *= unit[from_unit, to_unit]
            self.units = to_unit

    @property
    def _dim(self):
        for unit in unit_list:
            if self.units in unit.units():
                return unit

    @property
    def _prefix(self):
        return self.__class__.__name__.lower()


class Series(pd.Series, Base):
    """
    A series is an indexed array. The index can be n-dimensional but most often
    is 1-dimensional.
    """
    _metadata = ['metadata', 'units']

    def copy(self, *args, **kwargs):
        """Copy maintaining class type."""
        cls = self.__class__
        return cls(super(Series, self).copy(*args, **kwargs))

    @property
    def _constructor(self):
        return Series

    def _combine_const(self, other, *args, **kwargs):
        return super(Series, self)._combine_const(other, *args, **kwargs).__finalize__(self)

#    def __finalize__(self, other, method=None, **kwargs):
#        if isinstance(other, pd.core.generic.NDFrame):
#            for name in self._metadata:
#                if name == 'units':
#                    self.convert_units(other.units)
#                else:
#                    object.__setattr__(self, name, getattr(other, name, None))
#        elif isinstance(other, Dimension):
#            raise NotImplementedError()
#        return self

    def __init__(self, *args, **kwargs):
        metadata = kwargs.pop("metadata", None)
        units = kwargs.pop("units", None)
        super(Series, self).__init__(*args, **kwargs)
        self.metadata = metadata
        self.units = units
        if self.name is None and self.index.name is None:
            try:
                self.name = self.metadata['name']
            except AttributeError:
                pass
        if self.index.name is None:
            self.index.name = self.name


#class DataFrame(pd.DataFrame):
#    """
#    """
#    def __init__(self, *args, **kwargs):
#        super(DataFrame, self).__init__(*args, **kwargs)
#        if self.index.name is None:
#            self.index.name = self.name
#
#
#class Frame(DataFrame):
#    """
#    """
#    pass
#
#
#class Atom(DataFrame):
#    """
#    """<commit_msg>minor<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2015-2016, Exa Analytics Development Team
# Distributed under the terms of the Apache License 2.0
"""
Discrete Data Objects
###################################
Custom discrete data objects (such as series, dataframes, etc.) provide easy
description of relationships. There are three types of relationships, one-to-one
(matching index names), one-to-many (index name in columns), and many-to-many
(matching columns).
"""
import six
import pandas as pd
from exa.core.typed import TypedMeta
from exa.cms.unit import (Length, Mass, Time, Current, Amount, Luminosity,
                          Dose, Acceleration, Charge, Dipole, Energy, Force,
                          Frequency, MolarMass, Dimension, unit_list)


class Base(object):
    """Base class for discrete data objects."""
    def convert_units(self, to_unit):
        """Convert units."""
        from_unit = self.units
        unit = self._dim
        if unit is not None:
            self.values *= unit[from_unit, to_unit]
            self.units = to_unit

    @property
    def _dim(self):
        for unit in unit_list:
            if self.units in unit.units():
                return unit

    @property
    def _prefix(self):
        return self.__class__.__name__.lower()


class Series(pd.Series, Base):
    """
    A series is an indexed array. The index can be n-dimensional but most often
    is 1-dimensional.
    """
    _metadata = ['units']

    def copy(self, *args, **kwargs):
        """Copy maintaining class type."""
        cls = self.__class__
        return cls(super(Series, self).copy(*args, **kwargs))

    @property
    def _constructor(self):
        return Series

    def _combine_const(self, other, *args, **kwargs):
        return super(Series, self)._combine_const(other, *args, **kwargs).__finalize__(self)

#    def __finalize__(self, other, method=None, **kwargs):
#        if isinstance(other, pd.core.generic.NDFrame):
#            for name in self._metadata:
#                if name == 'units':
#                    self.convert_units(other.units)
#                else:
#                    object.__setattr__(self, name, getattr(other, name, None))
#        elif isinstance(other, Dimension):
#            raise NotImplementedError()
#        return self

    def __init__(self, *args, **kwargs):
        units = kwargs.pop("units", None)
        super(Series, self).__init__(*args, **kwargs)
        self.units = units
        if self.name is None and self.index.name is None:
            try:
                self.name = self.metadata['name']
            except AttributeError:
                pass
        if self.index.name is None:
            self.index.name = self.name


#class DataFrame(pd.DataFrame):
#    """
#    """
#    def __init__(self, *args, **kwargs):
#        super(DataFrame, self).__init__(*args, **kwargs)
#        if self.index.name is None:
#            self.index.name = self.name
#
#
#class Frame(DataFrame):
#    """
#    """
#    pass
#
#
#class Atom(DataFrame):
#    """
#    """
{'fraction_non_alphanumeric': 0.13106873898413715, 'fraction_numerical': 0.0038455375741067136, 'mean_word_length': 2.346916890080429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263784', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1751, 'n_words': 526}