Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

InputStream object cannot be used with pandas

Aperta
#832 4 commenti 1 reazione 1 assegnatario Vedi su GitHub

@vrdmr ci sta già lavorando.

Dal 1/6/2021.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

area:python-functions new feature

In this example:

import logging
import os
from azure.cosmosdb.table.tableservice import TableService
import azure.functions as func
import pandas


def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    df = pandas.read_excel(myblob, index_col=0)

    table_service = TableService(account_name=os.getenv('TABLE_STORAGE_ACCOUNT_NAME'), 
                                 account_key=os.getenv('TABLE_STORAGE_KEY'))

    records = df.to_dict(orient="records") 
    for record in records:
        table_service.insert_entity('ais', record)

Configured with function.json as:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "ais/{name}.xlsx",
      "connection": "anthonyshawstorage_STORAGE"
    }
  ]
}

The script fails because InputStream does not implement the seek function. It does implement seakable() as returning false, which is correct, but pandas doesn't adhere to that API so you get this error:

Exception while executing function: Functions.BlobTrigger Result: Failure
Exception: UnsupportedOperation: seek
Stack:   File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 542, in __run_sync_func
    return func(**params)
  File "/home/site/wwwroot/BlobTrigger/__init__.py", line 13, in main
    df = pandas.read_excel(myblob, index_col=0)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/util/_decorators.py", line 299, in wrapper
    return func(*args, **kwargs)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/excel/_base.py", line 336, in read_excel
    io = ExcelFile(io, storage_options=storage_options, engine=engine)
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/excel/_base.py", line 1057, in __init__
    ext = inspect_excel_format(
  File "/home/site/wwwroot/.python_packages/lib/site-packages/pandas/io/excel/_base.py", line 942, in inspect_excel_format
    stream.seek(0)

Technically, this is a bug in pandas, because it should check seekable() first.

Is there a way to make the inputstream seekable if it comes from blob storage?

Lingua principale
Python
Stelle
357
Fork
117
Merge medio
13g 12h
PR unite (30g)
2

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-functions-python-worker

Tutte le issue di Azure/azure-functions-python-worker

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.