AttributeError: 'DataFrame' object has no attribute 'dtype'

Jaws picture Jaws · May 6, 2018 · Viewed 8.1k times · Source

I enountered

Error in py_get_attr_impl(x, name, silent) : AttributeError: 'DataFrame' object has no attribute 'dtype'

on calling python code in R using reticulate package in R.

The code in python runs correctly. I am not sure from where this error is coming. I am using pvlib python library to call some in build databases.

My code is for R is:

library('reticulate')
pd <- import('pandas')
pvlib <- import('pvlib')
np <- import('numpy') 
sandia_modules = pvlib$pvsystem$retrieve_sam('SandiaMod')
cec_inverters = pvlib$pvsystem$retrieve_sam("CECInverter")

I have issue with cec_inverters = pvlib$pvsystem$retrieve_sam("CECInverter") when I the code in python it's working but running same commands in R is giving me error. I am not sure what the issue is. Please help me resolve this issue.

The similar code in python is:

import pandas as pd
import numpy as np
import pvlib

sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
cec_inverters = pvlib.pvsystem.retrieve_sam('cecinverter')

I tried looking for solution but so far didn't find anything useful.

Here's the traceback:

10: stop(list(message = "AttributeError: 'DataFrame' object has no attribute 'dtype'", 
        call = py_get_attr_impl(x, name, silent), cppstack = list(
            file = "", line = -1L, stack = "C++ stack not available on this system")))
9: .Call(`_reticulate_py_get_attr_impl`, x, name, silent)
8: py_get_attr_impl(x, name, silent)
7: py_get_attr(x, name)
6: `$.python.builtin.object`(x[[column]], "dtype")
5: x[[column]]$dtype
4: py_to_r(x[[column]]$dtype$name)
3: py_to_r.pandas.core.frame.DataFrame(result)
2: py_to_r(result)
1: pvlib$pvsystem$retrieve_sam("CECInverter")

Answer

hrbrmstr picture hrbrmstr · May 6, 2018

Try using the as parameter in import(). Your code errored for me as well but this worked:

library(reticulate) # version 1.6

pd <- import('pandas', as = "pd")
pvlib <- import('pvlib', as = "pvlib")
np <- import('numpy', as = "np") 

sandia_modules <- pvlib$pvsystem$retrieve_sam('SandiaMod')
cec_inverters <- pvlib$pvsystem$retrieve_sam("CECInverter")