common.py 654 B

1234567891011121314151617181920212223242526
  1. import numpy as np
  2. from pandas.compat import reduce
  3. import pandas as pd
  4. def _ensure_decoded(s):
  5. """ if we have bytes, decode them to unicode """
  6. if isinstance(s, (np.bytes_, bytes)):
  7. s = s.decode(pd.get_option('display.encoding'))
  8. return s
  9. def _result_type_many(*arrays_and_dtypes):
  10. """ wrapper around numpy.result_type which overcomes the NPY_MAXARGS (32)
  11. argument limit """
  12. try:
  13. return np.result_type(*arrays_and_dtypes)
  14. except ValueError:
  15. # we have > NPY_MAXARGS terms in our expression
  16. return reduce(np.result_type, arrays_and_dtypes)
  17. class NameResolutionError(NameError):
  18. pass