Ensure that an object is a binning

    Parameters
    ---------
    obj : BinningBase or array_like
        Can be a binning, numpy-like bins or full physt bins
    copy : If true, ensure that the returned object is independent
358809
def as_binning(obj, copy: bool = False) -> BinningBase:
    
    if isinstance(obj, BinningBase):
        if copy:
            return obj.copy()
        else:
            return obj
    else:
        bins = make_bin_array(obj)
        return StaticBinning(bins)
1275184
def DiffAnyObjects(self, oldObj, newObj, isObjLink=False):
      """"""
      if oldObj == newObj:
         return True
      if not oldObj or not newObj:
         __Log__.debug('DiffAnyObjects: One of the objects is unset.')
         return self._looseMatch
      oldObjInstance = oldObj
      newObjInstance = newObj
      if isinstance(oldObj, list):
         oldObjInstance = oldObj[0]
      if isinstance(newObj, list):
         newObjInstance = newObj[0]
      # Need to see if it is a primitive type first since type information
      #   will not be available for them.
      if (IsPrimitiveType(oldObj) and IsPrimitiveType(newObj)
         and oldObj.__class__.__name__ == newObj.__class__.__name__):
         if oldObj == newObj:
            return True
         elif oldObj == None or newObj == None:
            __Log__.debug('DiffAnyObjects: One of the objects in None')
         return False
      oldType = Type(oldObjInstance)
      newType = Type(newObjInstance)
      if oldType != newType:
         __Log__.debug('DiffAnyObjects: Types do not match %s != %s' %
            (repr(GetWsdlName(oldObjInstance.__class__)),
             repr(GetWsdlName(newObjInstance.__class__))))
         return False
      elif isinstance(oldObj, list):
         return self.DiffArrayObjects(oldObj, newObj, isObjLink)
      elif isinstance(oldObjInstance, types.ManagedObject):
         return (not oldObj and not newObj) or (oldObj and newObj
            and oldObj._moId == newObj._moId)
      elif isinstance(oldObjInstance, types.DataObject):
         if isObjLink:
            bMatch = oldObj.GetKey() == newObj.GetKey()
            LogIf(not bMatch, 'DiffAnyObjects: Keys do not match %s != %s'
               % (oldObj.GetKey(), newObj.GetKey()))
            return bMatch
         return self.DiffDataObjects(oldObj, newObj)

      else:
         raise TypeError("Unknown type: "+repr(GetWsdlName(oldObj.__class__)))
1304112
def assertinstance(obj, types):
    
    if isinstance(obj, types):
        return obj
    raise TypeError('{} must be instance of {}'.format(obj, types))
918860
def is_bin_subset(sub, sup) -> bool:
    
    sub = make_bin_array(sub)
    sup = make_bin_array(sup)

    for row in sub:
        if not (row == sup).all(axis=1).any():
            # TODO: Enable also approximate equality
            return False
    return True
1123542
def isin(comps, values):
    

    if not is_list_like(comps):
        raise TypeError("only list-like objects are allowed to be passed"
                        " to isin(), you passed a [{comps_type}]"
                        .format(comps_type=type(comps).__name__))
    if not is_list_like(values):
        raise TypeError("only list-like objects are allowed to be passed"
                        " to isin(), you passed a [{values_type}]"
                        .format(values_type=type(values).__name__))

    if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
        values = construct_1d_object_array_from_listlike(list(values))

    if is_categorical_dtype(comps):
        # TODO(extension)
        # handle categoricals
        return comps._values.isin(values)

    comps = com.values_from_object(comps)

    comps, dtype, _ = _ensure_data(comps)
    values, _, _ = _ensure_data(values, dtype=dtype)

    # faster for larger cases to use np.in1d
    f = lambda x, y: htable.ismember_object(x, values)

    # GH16012
    # Ensure np.in1d doesn't get object types or it *may* throw an exception
    if len(comps) > 1000000 and not is_object_dtype(comps):
        f = lambda x, y: np.in1d(x, y)
    elif is_integer_dtype(comps):
        try:
            values = values.astype('int64', copy=False)
            comps = comps.astype('int64', copy=False)
            f = lambda x, y: htable.ismember_int64(x, y)
        except (TypeError, ValueError, OverflowError):
            values = values.astype(object)
            comps = comps.astype(object)

    elif is_float_dtype(comps):
        try:
            values = values.astype('float64', copy=False)
            comps = comps.astype('float64', copy=False)
            f = lambda x, y: htable.ismember_float64(x, y)
        except (TypeError, ValueError):
            values = values.astype(object)
            comps = comps.astype(object)

    return f(comps, values)
1006648
def bin(self, size, name, value=None):
        
        self._add_field(Binary(size, name, value))
372142
def is_filelike(ob):
    
    if hasattr(ob, 'read') and callable(ob.read):
        return True

    if hasattr(ob, 'write') and callable(ob.write):
        return True

    return False
248344
def DiffArrayObjects(self, oldObj, newObj, isElementLinks=False):
      """"""
      if oldObj == newObj:
         return True
      if not oldObj or not newObj:
         return False
      if len(oldObj) != len(newObj):
         __Log__.debug('DiffArrayObjects: Array lengths do not match %d != %d'
            % (len(oldObj), len(newObj)))
         return False
      firstObj = oldObj[0]
      if IsPrimitiveType(firstObj):
         return self.DiffPrimitiveArrays(oldObj, newObj)
      elif isinstance(firstObj, types.ManagedObject):
         return self.DiffAnyArrays(oldObj, newObj, isElementLinks)
      elif isinstance(firstObj, types.DataObject):
         return self.DiffDoArrays(oldObj, newObj, isElementLinks)
      else:
         raise TypeError("Unknown type: %s" % oldObj.__class__)
265298
def array_to_binary(val)
      saved_object_count = @written_object_count
      @written_object_count += 1
      #@object_refs += val.value.size

      values = val.value.map { |v| v.to_binary(self) }
      bdata = Binary.type_bytes(0b1010, val.value.size) <<
        Binary.pack_int_array_with_size(object_ref_size(@object_refs),
                                        values)

      @object_table[saved_object_count] = bdata
      saved_object_count
    end
336705
def ensure_object_is_ndarray(item, title):
    
    assert isinstance(title, str)

    if not isinstance(item, np.ndarray):
        msg = "{} must be a np.ndarray. {} passed instead."
        raise TypeError(msg.format(title, type(item)))

    return None
80097
function clone(obj) {
  if (null == obj || "object" != typeof obj)
    return obj;

  if (obj instanceof Object) {
    var copy = {};
    for (var attr in obj) {
      if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
    }
    return copy;
  }

  throw new Error("Unable to copy obj! Its type isn't supported.");
}
839986
def _assert_is_dictlike(maybe_dictlike, valid_keys):
  """"""
  # This covers a common mistake when people use incorrect dictionary nesting
  # for initializers / partitioners etc. The previous error message was quite
  # opaque, this should be much clearer.
  if not hasattr(maybe_dictlike, "__getitem__"):
    raise TypeError(
        "Expected a dict-like object with possible keys %s, received %s" %
        (str(valid_keys), str(maybe_dictlike)))
1016961
def as_static(self, copy: bool = True) -> 'StaticBinning':
        
        if copy:
            return StaticBinning(bins=self.bins.copy(),
                                 includes_right_edge=self.includes_right_edge)
        else:
            return self
229739
def _instance_callable(obj):
    """"""
    if not isinstance(obj, ClassTypes):
        # already an instance
        return getattr(obj, '__call__', None) is not None

    if six.PY3:
        # *could* be broken by a class overriding __mro__ or __dict__ via
        # a metaclass
        for base in (obj,) + obj.__mro__:
            if base.__dict__.get('__call__') is not None:
                return True
    else:
        klass = obj
        # uses __bases__ instead of __mro__ so that we work with old style classes
        if klass.__dict__.get('__call__') is not None:
            return True

        for base in klass.__bases__:
            if _instance_callable(base):
                return True
    return False
1115122
def obj_with_unit(obj, unit):
    
    unit_type = _UNAME2UTYPE[unit]

    if isinstance(obj, numbers.Number):
        return FloatWithUnit(obj, unit=unit, unit_type=unit_type)
    elif isinstance(obj, collections.Mapping):
        return {k: obj_with_unit(v, unit) for k,v in obj.items()}
    else:
        return ArrayWithUnit(obj, unit=unit, unit_type=unit_type)
419002
function mixable(obj, recursive) {
  if (obj == null) {
    obj = {};
  }
  if (recursive == null) {
    recursive = true;
  }
  // Do not override the mixin function, even it is not mine.
  if (isPrimitive(obj) || obj.mixin != null) {
    return obj;
  }
  // Recursively make the prototypes mixable.
  if (recursive && (obj.prototype != null)) {
    mixable(obj.prototype);
  }
  // The common mixin.
  defineProp(obj, 'mixin', {
    configurable: true,
    enumerable: false,
    value: mixin
  });
  return obj;
}
662111
def is_binarized(self):
        
        is_binarized = np.issubdtype(self.pianoroll.dtype, np.bool_)
        return is_binarized