<commit_before>from __future__ import (absolute_import, division, print_function, unicode_literals)

import re
from copy import deepcopy
import collections

from ..utils.compat.misc import override__dir__
from ..extern import six
from ..units import Unit

from .angles import Latitude, Longitude
from .baseframe import BaseCoordinateFrame, frame_transform_graph

__all__ = ['SkyCoord']

# ALL THESE FIXED MAPPINGS NEED TO BE DYNAMIC

# Create FRAME_CLASSES dictionary mapping of frame name: frame class.
FRAME_NAMES = frame_transform_graph.get_aliases()
FRAME_CLASSES = dict((name, frame_transform_graph.lookup_name(name))
                     for name in FRAME_NAMES)
FRAME_CLASSES[None] = FRAME_CLASSES['icrs']

# Inverse mapping is useful
CLASS_TO_NAME_MAP = dict((cls, name) for name, cls in FRAME_CLASSES.items())


# Set of all possible frame-specific attributes
FRAME_ATTR_NAMES_SET = set()
for frame_cls in FRAME_CLASSES.values():
    for attr in frame_cls.frame_attr_names.keys():
        FRAME_ATTR_NAMES_SET.add(attr)


class SkyCoord(object):

    def __init__(self, *args, **kwargs):
        # Parse the args and kwargs to assemble a sanitized and validated
        # kwargs dict for initializing attributes for this object and for
        # creating the internal self._coords object
        args = list(args)  # Make it mutable
        kwargs = self._parse_inputs(args, kwargs)

        # Set internal versions of object state attributes
        self._frame = kwargs['frame']
        for attr in FRAME_ATTR_NAMES_SET:
            setattr(self, '_' + attr, kwargs[attr])

        # Set up the keyword args for creating the internal coordinate object.
        frame_cls = FRAME_CLASSES[self.frame]
        coord_kwargs = {}
        for attr, value in kwargs.items():
            if value is not None and (attr in frame_cls.preferred_attr_names
                                      or attr in frame_cls.frame_attr_names):
                coord_kwargs[attr] = value

        # Finally make the internal coordinate object.
        self._coord = frame_cls(**coord_kwargs)

    @property
    def frame(self):
        return self._frame

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

    def _parse_inputs(self, args, kwargs):
        """
        Assemble a validated and sanitized keyword args dict for instantiating a
        SkyCoord and coordinate object from the provided `args`, and `kwargs`.
        """
        valid_kwargs = {}

        # Put the SkyCoord attributes frame, equinox, obstime, location into valid_kwargs
        # dict.  `Frame` could come from args or kwargs, so set valid_kwargs['frame']
        # accordingly.  The others must be specified by keyword args.  Pop them off
        # of kwargs in the process.
        frame = valid_kwargs['frame'] = _get_frame_name(args, kwargs)
        for attr in FRAME_ATTR_NAMES_SET:
            valid_kwargs[attr] = kwargs.pop(attr, None)

        # Get latitude and longitude units
        lon_unit, lat_unit = _get_units(args, kwargs)

        # Grab any frame-specific attr names like `ra` or `l` or `distance`
        valid_kwargs.update(_get_preferred_attrs(frame, lon_unit, lat_unit, kwargs))

        # Error if anything is still left in kwargs
        if kwargs:
            raise ValueError('Unrecognized keyword argument(s) {0}'
                             .format(', '.join("'{0}'".format(key) for key in kwargs)))

        # Finally deal with the unnamed args.  This figures out what the arg[0] is
        # and returns a dict with appropriate key/values for initializing frame class.
        if args:
            if len(args) == 1:
                # One arg which must be a coordinate
                coord_kwargs = _parse_coordinate_arg(args[0], frame, lon_unit, lat_unit)

            elif len(args) == 2:
                attr_name_for_type = dict((attr_type, name) for name, attr_type in
                                          FRAME_CLASSES[frame].preferred_attr_names.items())
                coord_kwargs = {}
                coord_kwargs[attr_name_for_type['lon']] = Longitude(args[0], unit=lon_unit)
                coord_kwargs[attr_name_for_type['lat']] = Latitude(args[1], unit=lat_unit)
            else:
                raise ValueError('Must supply no more than two positional arguments, got {}'
                                 .format(len(args)))

            for attr in coord_kwargs:
                if attr in valid_kwargs:
                    raise ValueError("Cannot supply a '{0}' keyword along with a coordinate input"
                                     .format(attr))
                valid_kwargs[attr] = coord_kwargs[attr]

        return valid_kwargs

    def transform_to(self, frame):
        """
        Transform this coordinate to a new frame.
<commit_msg>Check that existing valid kwarg is not None for conflict resolution<commit_after>from __future__ import (absolute_import, division, print_function, unicode_literals)

import re
from copy import deepcopy
import collections

from ..utils.compat.misc import override__dir__
from ..extern import six
from ..units import Unit

from .angles import Latitude, Longitude
from .baseframe import BaseCoordinateFrame, frame_transform_graph

__all__ = ['SkyCoord']

# ALL THESE FIXED MAPPINGS NEED TO BE DYNAMIC

# Create FRAME_CLASSES dictionary mapping of frame name: frame class.
FRAME_NAMES = frame_transform_graph.get_aliases()
FRAME_CLASSES = dict((name, frame_transform_graph.lookup_name(name))
                     for name in FRAME_NAMES)
FRAME_CLASSES[None] = FRAME_CLASSES['icrs']

# Inverse mapping is useful
CLASS_TO_NAME_MAP = dict((cls, name) for name, cls in FRAME_CLASSES.items())


# Set of all possible frame-specific attributes
FRAME_ATTR_NAMES_SET = set()
for frame_cls in FRAME_CLASSES.values():
    for attr in frame_cls.frame_attr_names.keys():
        FRAME_ATTR_NAMES_SET.add(attr)


class SkyCoord(object):

    def __init__(self, *args, **kwargs):
        # Parse the args and kwargs to assemble a sanitized and validated
        # kwargs dict for initializing attributes for this object and for
        # creating the internal self._coords object
        args = list(args)  # Make it mutable
        kwargs = self._parse_inputs(args, kwargs)

        # Set internal versions of object state attributes
        self._frame = kwargs['frame']
        for attr in FRAME_ATTR_NAMES_SET:
            setattr(self, '_' + attr, kwargs[attr])

        # Set up the keyword args for creating the internal coordinate object.
        frame_cls = FRAME_CLASSES[self.frame]
        coord_kwargs = {}
        for attr, value in kwargs.items():
            if value is not None and (attr in frame_cls.preferred_attr_names
                                      or attr in frame_cls.frame_attr_names):
                coord_kwargs[attr] = value

        # Finally make the internal coordinate object.
        self._coord = frame_cls(**coord_kwargs)

    @property
    def frame(self):
        return self._frame

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

    def _parse_inputs(self, args, kwargs):
        """
        Assemble a validated and sanitized keyword args dict for instantiating a
        SkyCoord and coordinate object from the provided `args`, and `kwargs`.
        """
        valid_kwargs = {}

        # Put the SkyCoord attributes like frame, equinox, obstime, location
        # into valid_kwargs dict.  `Frame` could come from args or kwargs, so
        # set valid_kwargs['frame'] accordingly.  The others must be specified
        # by keyword args or else get a None default.  Pop them off of kwargs
        # in the process.
        frame = valid_kwargs['frame'] = _get_frame_name(args, kwargs)
        for attr in FRAME_ATTR_NAMES_SET:
            valid_kwargs[attr] = kwargs.pop(attr, None)

        # Get latitude and longitude units
        lon_unit, lat_unit = _get_units(args, kwargs)

        # Grab any frame-specific attr names like `ra` or `l` or `distance` from kwargs
        # and migrate to valid_kwargs.
        valid_kwargs.update(_get_preferred_attrs(frame, lon_unit, lat_unit, kwargs))

        # Error if anything is still left in kwargs
        if kwargs:
            raise ValueError('Unrecognized keyword argument(s) {0}'
                             .format(', '.join("'{0}'".format(key) for key in kwargs)))

        # Finally deal with the unnamed args.  This figures out what the arg[0] is
        # and returns a dict with appropriate key/values for initializing frame class.
        if args:
            if len(args) == 1:
                # One arg which must be a coordinate.  In this case
                # coord_kwargs will contain keys like 'ra', 'dec', 'distance'
                # along with any frame attributes like equinox or obstime which
                # were explicitly specified in the coordinate object (i.e. non-default).
                coord_kwargs = _parse_coordinate_arg(args[0], frame, lon_unit, lat_unit)

            elif len(args) == 2:
                # Must be longitude, latitude.
                attr_name_for_type = dict((attr_type, name) for name, attr_type in
                                          FRAME_CLASSES[frame].preferred_attr_names.items())
                coord_kwargs = {}
                coord_kwargs[attr_name_for_type['lon']] = Longitude(args[0], unit=lon_unit)
                coord_kwargs[attr_name_for_type['lat']] = Latitude(args[1], unit=lat_unit)
            else:
                raise ValueError('Must supply no more than two positional arguments, got {}'
                                 .format(len(args)))

            # Copy the coord_kwargs into the final valid_kwargs dict.  For each
            # of the coord_kwargs ensure that there is no conflict with a value
            # specified by the user in the original kwargs.
            for attr in coord_kwargs:
                if attr in valid_kwargs and valid_kwargs[attr] is not None:
                    raise ValueError("Cannot supply a '{0}' keyword along with a coordinate input"
                                     .format(attr))
                valid_kwargs[attr] = coord_kwargs[attr]

        return valid_kwargs

    def transform_to(self, frame):
        """
        Transform this coordinate to a new frame.

{'fraction_non_alphanumeric': 0.07538177220114775, 'fraction_numerical': 0.0017508024511234317, 'mean_word_length': 2.417082087072117, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5985089', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2725, 'n_words': 948}