Format subset as with units

        :param unit: string to use as unit
        :param location: prefix or suffix
        :param subset: Pandas subset
428731
def as_unit(self, unit, location='suffix', *args, **kwargs):
        
        f = Formatter(
            as_unit(unit, location=location),
            args,
            kwargs
        )
        return self._add_formatter(f)
1093084
def _write_subset_index_file(options, core_results):
    

    f_path = os.path.join(options['run_dir'], '_subset_index.csv')
    subset_strs = zip(*core_results)[0]
    index = np.arange(len(subset_strs)) + 1
    df = pd.DataFrame({'subsets': subset_strs}, index=index)
    df.to_csv(f_path)
419965
public static void formatLatitude(Appendable out, Locale locale, double latitude, UnitType unit)
    {
        format(out, locale, latitude, unit, NS);
    }
1297249
def unit(self, unit):
        
        allowed_values = ["cm", "inch", "foot"]  # noqa: E501
        if unit is not None and unit not in allowed_values:
            raise ValueError(
                "Invalid value for `unit` ({0}), must be one of {1}"  # noqa: E501
                .format(unit, allowed_values)
            )

        self._unit = unit
631260
def parse_v4_unit_placement(placement_str):
    
    placement = placement_str
    container = machine = service = unit = ''
    if ':' in placement:
        try:
            container, placement = placement_str.split(':')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if '/' in placement:
        try:
            placement, unit = placement.split('/')
        except ValueError:
            msg = 'placement {} is malformed, too many parts'.format(
                placement_str)
            raise ValueError(msg.encode('utf-8'))
    if placement.isdigit() or placement == 'new':
        machine = placement
    else:
        service = placement
    if (container and container not in VALID_CONTAINERS):
        msg = 'invalid container {} for placement {}'.format(
            container, placement_str)
        raise ValueError(msg.encode('utf-8'))
    unit = _parse_unit(unit, placement_str)
    return UnitPlacement(container, machine, service, unit)
405025
private String formatTimeUnit(TimeUnit timeUnit)
   {
      int units = timeUnit.getValue();
      String result;
      String[][] unitNames = LocaleData.getStringArrays(m_locale, LocaleData.TIME_UNITS_ARRAY);

      if (units < 0 || units >= unitNames.length)
      {
         result = "";
      }
      else
      {
         result = unitNames[units][0];
      }

      return (result);
   }
366261
def p_unit(self, p):
        
        unit = TimexLexer.reserved_words[p[1]]
        unit = unit.lower()
        p[0] = unit
485465
def disambiguate_unit(unit, text):
    
    new_unit = l.UNITS[unit]
    if not new_unit:
        new_unit = l.LOWER_UNITS[unit.lower()]
        if not new_unit:
            raise KeyError('Could not find unit "%s"' % unit)

    if len(new_unit) > 1:
        transformed = TFIDF_MODEL.transform([clean_text(text)])
        scores = CLF.predict_proba(transformed).tolist()[0]
        scores = sorted(zip(scores, TARGET_NAMES), key=lambda x: x[0],
                        reverse=True)
        names = [i.name for i in new_unit]
        scores = [i for i in scores if i[1] in names]
        try:
            final = l.UNITS[scores[0][1]][0]
            logging.debug('\tAmbiguity resolved for "%s" (%s)', unit, scores)
        except IndexError:
            logging.debug('\tAmbiguity not resolved for "%s"', unit)
            final = new_unit[0]
    else:
        final = new_unit[0]

    return final
78319
def units2pint(value):
    

    def _transform(s):
        """Convert a CF-unit string to a pint expression."""
        return re.subn(r'\^?(-?\d)', r'**\g<1>', s)[0]

    if isinstance(value, str):
        unit = value
    elif isinstance(value, xr.DataArray):
        unit = value.attrs['units']
    elif isinstance(value, units.Quantity):
        return value.units
    else:
        raise NotImplementedError("Value of type {} not supported.".format(type(value)))

    try:  # Pint compatible
        return units.parse_expression(unit).units
    except (pint.UndefinedUnitError, pint.DimensionalityError):  # Convert from CF-units to pint-compatible
        return units.parse_expression(_transform(unit)).units
754298
private String format(double duration, Units units)
  {
    StringBuilder builder = new StringBuilder();
    builder.append(numberFormat.format(duration));
    builder.append(' ');
    builder.append(units.display());
    return builder.toString();
  }
912707
def _format_value(self, value):
        
        value, unit = self.py3.format_units(value, unit=self.unit, si=self.si_units)
        return self.py3.safe_format(self.format_value, {"value": value, "unit": unit})
660957
def parse_unit(item, group, slash):
    """"""
    surface = item.group(group).replace('.', '')
    power = re.findall(r'\-?[0-9%s]+' % r.SUPERSCRIPTS, surface)

    if power:
        power = [r.UNI_SUPER[i] if i in r.UNI_SUPER else i for i
                 in power]
        power = ''.join(power)
        new_power = (-1 * int(power) if slash else int(power))
        surface = re.sub(r'\^?\-?[0-9%s]+' % r.SUPERSCRIPTS, '', surface)

    elif re.findall(r'\bcubed\b', surface):
        new_power = (-3 if slash else 3)
        surface = re.sub(r'\bcubed\b', '', surface).strip()

    elif re.findall(r'\bsquared\b', surface):
        new_power = (-2 if slash else 2)
        surface = re.sub(r'\bsquared\b', '', surface).strip()

    else:
        new_power = (-1 if slash else 1)

    return surface, new_power
1137510
def subset(self, *args):
        
        df = self._subset(*args)
        if df is None:
            self.err("Can get subset of data")
            return
        self.df = df
610936
def apply_units_to_cache(self, data):
        
        # iterate through sheets in parameters
        # iterate through the parameters on each sheet
        for param, pval in self.parameters.iteritems():
            # try to apply units
            try:
                data[param] *= UREG(str(pval.get('units') or ''))
            except TypeError:
                continue
        return data
1205203
def match_axis_label_suffix(str)
      best = [nil, nil]
      Unit.each do |unit|
        label_s = unit.label.to_s
        best = [label_s, unit] if suffix?(label_s, str) and (best.first.nil? or label_s.length > best.first.length)
      end
      best
    end
949071
def format_units(v, step=None, system="si", units=None):
    
    if v is None:
        return 0, ''

    for prefix, size in UnitSystems[system]:
        if condition(v, size, step):
            v2 = v / size
            if v2 - math.floor(v2) < 0.00000000001 and v > 1:
                v2 = float(math.floor(v2))
            if units:
                prefix = "%s%s" % (prefix, units)
            return v2, prefix

    if v - math.floor(v) < 0.00000000001 and v > 1:
        v = float(math.floor(v))
    if units:
        prefix = units
    else:
        prefix = ''
    return v, prefix
1321782
def get_unit_by_index(self, unit_index) -> typing.Optional['BaseUnit']:
        
        if unit_index in self._section_group['units'].keys():
            if unit_index not in self.__units.keys():
                _category = self.units_class_enum[self.group_category]  # type: ignore
                self.__units[unit_index] = _category(self.d, self.l10n, self.coa_color,
                                                     self.country_index,
                                                     self.group_category,
                                                     self.group_index, unit_index)
            return self.__units[unit_index]
        return None