def __init__(self, io, **kwds): import xlrd # throw an ImportError if we need to ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2])) if ver < (0, 9): # pragma: no cover raise ImportError("pandas requires xlrd >= 0.9.0 for excel " "support, current version " + xlrd.__VERSION__) self.io = io engine = kwds.pop('engine', None) if engine is not None and engine != 'xlrd': raise ValueError("Unknown engine: %s" % engine) if isinstance(io, compat.string_types): if _is_url(io): data = _urlopen(io).read() self.book = xlrd.open_workbook(file_contents=data) else: self.book = xlrd.open_workbook(io) elif engine == 'xlrd' and isinstance(io, xlrd.Book): self.book = io elif not isinstance(io, xlrd.Book) and hasattr(io, "read"): # N.B. xlrd.Book has a read attribute too data = io.read() self.book = xlrd.open_workbook(file_contents=data) else: raise ValueError('Must explicitly set engine if not passing in' ' buffer or path for io.')
def fetch_data(url, name): resp = _urlopen(url) resp = resp.read() resp = resp.decode('utf-8') data = read_jsdmx(resp) try: idx_name = data.index.name # hack for pandas 0.16.2 data.index = pd.to_datetime(data.index) data = data.sort_index() data = data.truncate(start, end) data.index.name = idx_name except ValueError: pass return data
def fetch_data(url, name): resp = _urlopen(url) resp = resp.read() resp = resp.decode("utf-8") data = read_jsdmx(resp) try: idx_name = data.index.name # hack for pandas 0.16.2 data.index = pd.to_datetime(data.index) data = data.sort_index() data = data.truncate(start, end) data.index.name = idx_name except ValueError: pass return data
def __init__(self, filepath_or_buffer): """Reader using xlrd engine. Parameters ---------- filepath_or_buffer : string, path object or Workbook Object to be parsed. """ err_msg = "Install xlrd >= 1.0.0 for Excel support" try: import xlrd except ImportError: raise ImportError(err_msg) else: if xlrd.__VERSION__ < LooseVersion("1.0.0"): raise ImportError(err_msg + ". Current version " + xlrd.__VERSION__) from pandas.io.excel._base import ExcelFile # If filepath_or_buffer is a url, want to keep the data as bytes so # can't pass to get_filepath_or_buffer() if _is_url(filepath_or_buffer): filepath_or_buffer = _urlopen(filepath_or_buffer) elif not isinstance(filepath_or_buffer, (ExcelFile, xlrd.Book)): filepath_or_buffer, _, _, _ = get_filepath_or_buffer( filepath_or_buffer) if isinstance(filepath_or_buffer, xlrd.Book): self.book = filepath_or_buffer elif hasattr(filepath_or_buffer, "read"): # N.B. xlrd.Book has a read attribute too if hasattr(filepath_or_buffer, 'seek'): try: # GH 19779 filepath_or_buffer.seek(0) except UnsupportedOperation: # HTTPResponse does not support seek() # GH 20434 pass data = filepath_or_buffer.read() self.book = xlrd.open_workbook(file_contents=data) elif isinstance(filepath_or_buffer, compat.string_types): self.book = xlrd.open_workbook(filepath_or_buffer) else: raise ValueError('Must explicitly set engine if not passing in' ' buffer or path for io.')