Search code examples
pythonpandasazurefacebook-prophet

Unable to read prophet model from ADLS to python


Trying to read prophet model json file strored on ADLS gen2 container from python using below code

from prophet.serialize import model_from_json

def reading_model_file():
    credentials = ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
    dataLakeServiceClient = DataLakeServiceClient(
    account_url="https://{}.dfs.core.windows.net".format(ACCOUNT_NAME),
    credential=credentials
    )
    file_system_client = dataLakeServiceClient.get_file_system_client(FILE_SYSTEM_NAME)
    source_directory_client = file_system_client.get_directory_client(SOURCE_DIRECTORY)
    source_file_client = source_directory_client.get_file_client(file_name) 
    source_file_contents = source_file_client.download_file().readall()
    return source_file_contents

model = model_from_json(reading_model_file())`

getting below error message:

TypeError: Cannot use .astype to convert from timezone-aware dtype to timezone-naive dtype. Use obj.tz_localize(None) or obj.tz_convert('UTC').tz_localize(None) instead.

python - 3.10.4 prophet - 1.1.4 pandas - 2.1.0

saving the model json files from databricks with the below code

with open('model.json', 'w') as fout:
        fout.write(model_to_json(model))  

also I am able to read the model files successfully on databricks only.

Databricks: python - 3.9.5 prophet - 1.1.4 pandas - 1.3.4


Solution

  • Even I got the same error as you.

    enter image description here

    This is because usage of different pandas version while saving the model and loading the model.

    In databricks, you save the model using pandas==1.3.4. So load the model with the same pandas version.

    pip install pandas==1.3.4
    

    and run your code.

    enter image description here

    By default, in databricks pandas version will be 1.4.2 you can use the same in both environments to load and save the model or you can upgrade it to 2.1.0 in both environments.

    My suggestion is, try to save the model in latest version of pandas.