def encode(obj):
try:<EOL><INDENT>return obj.encode(encode.encoding)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>logger.warning('<STR_LIT>'.format(type(obj)))<EOL>return str('<STR_LIT>').join([c for c in obj if c < MAX_CHR])<EOL><DEDENT>return obj<EOL>
r"""Encode all unicode/str objects in a dataframe in the encoding indicated (as a fun attribute)

    similar to to_ascii, but doesn't return a None, even when it fails.
    >>> encode(u'Is 2013 a year or a code point for "\u2013"?')
    b'Is 2013 a year or a code point for "\xe2\x80\x93"?'
    >>> print(u'Is 2013 a year or a code point for "\u2013"?')
    Is 2013 a year or a code point for "–"?