bifacial.pvfactors_timeseries() TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' - pvlib

I am trying to run the function: bifacial.pvfactors_timeseries(), and get the error:
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'.
I am not sure which of my imput values is wrong. Bellow you can see the function how I have written it and afterwards all the input values.
bifacial = pvlib.bifacial.pvfactors_timeseries(solar_azimuth=
interim_weather_df[cf.name_solar_azimuth_column],
solar_zenith=
interim_weather_df[cf.name_solar_zenith_column],
surface_azimuth=
interim_weather_df[cf.name_surface_azimuth_column],
surface_tilt=interim_weather_df[cf.name_surface_tilt_column],
axis_azimuth=self.axis_azimuth,
timestamps=interim_weather_df.index,
dni=interim_weather_df[cf.name_dni_column],
dhi=interim_weather_df[cf.name_dhi_column],
gcr=self.gcr,
pvrow_height=model.input_values.pv_row_height,
pvrow_width=model.input_values.pv_row_width,
albedo=model.input_values.albedo,
n_pvrows=3,
index_observed_pvrow=1,
rho_front_pvrow=0.03,
rho_back_pvrow=0.05,
horizon_band_angle=15.0)
Screenshots of the input structure:
input solar azimuth, input solar_zenith, input surface_azimuth, input surface_tilt, input timestamps, input dni, input dhi
all other inputs are float and int.
I also tried to only use single numerical values as input and no DataFrames, as can be seen below. I still got the same error.
bifacial = pvlib.bifacial.pvfactors_timeseries(solar_azimuth=235.7,
solar_zenith=75.6,
surface_azimuth=270,
surface_tilt=72.8,
axis_azimuth=180,
timestamps=datetime.datetime.strptime('01-01-2021 13:00:00', '%d-%m-%Y %H:%M:%S'),
dni=29,
dhi=275,
gcr=0.2,
pvrow_height=2,
pvrow_width=2,
albedo=0.1,
n_pvrows=3,
index_observed_pvrow=1,
rho_front_pvrow=0.03,
rho_back_pvrow=0.05,
horizon_band_angle=15.0)
python version: 3.8.5
pvlib version: 0.8.0
pv factors version: 1.5.0
pandas version: 1.2.1
Does anyone know the solution for that error? Thank you very much for your help!

I solved the problem. I only had some interference between the anaconda and pip environment.

Related

Cassandra COPY FROM query error, with a CSV file

The problem:
I'm trying to get it so I can use Cassandra to work with Python properly. I've been using a toy dataset to practice uploading a csv file into Cassandra with no luck.
Cassandra seems to work fine when I am not using COPY FROM for csv files.
My intention is to use this dataset as a test to make sure that I can load a csv file's information into Cassandra, so I can then load 5 csv files totaling 2 GB into it for my originally intended project.
Note: Whenever I use CREATE TABLE and then run SELECT * FROM tvshow_data, the columns don't appear in the order that I set them, is this going to affect anything, or does it not matter?
Info about my installations and usage:
I've tried running both cqlsh and cassandra with an admin powershell.
I have Python 2.7 installed inside of the apache-cassandra-3.11.6 folder.
I have Cassandra version 3.11.6 installed.
I have cassandra-driver 3.18.0 installed, with conda.
I use Python 3.7 installed for everything other than Cassandra's directory.
I have tried both CREATE TABLE tvshow and CREATE TABLE tvshow.tvshow_data.
My Python script:
from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect()
create_and_add_file_to_tvshow = [
"DROP KEYSPACE tvshow;",
"CREATE KEYSPACE tvshow WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};",
"USE tvshow;",
"CREATE TABLE tvshow.tvshow_data (id int PRIMARY KEY, title text, year int, age int, imdb decimal, rotten_tomatoes int, netflix int, hulu int, prime_video int, disney_plus int, is_tvshow int);",
"COPY tvshow_data (id, title, year, age, imdb, rotten_tomatoes, netflix, hulu, prime_video, disney_plus, is_tvshow) FROM 'C:tvshows.csv' WITH HEADER = true;"
]
print('\n')
for query in create_and_add_file_to_tvshow:
session.execute(query)
print(query, "\nsuccessful\n")
Resulting python error:
This is the error I get when I run my code in the powershell with the following command, python cassandra_test.py.
cassandra.protocol.SyntaxException: <Error from server: code=2000 [Syntax error in
CQL query] message="line 1:0 no viable alternative at input 'COPY' ([
Resulting cqlsh error:
Running the previously stated cqlsh code in the create_and_add_file_to_tvshow variable in powershell after running cqlsh in the apache-cassandra-3.1.3/bin/ directory, creates the following error.
Note: The following error is only the first few lines to the code as well as the last new lines, I choose not to include it since it was several hundred lines long. If necessary I will include it.
Starting copy of tvshow.tvshow_data with columns [id, title, year, age, imdb, rotten_tomatoes, netflix, hulu, prime_video, disney_plus, is_tvshow].
Failed to import 0 rows: IOError - Can't open 'C:tvshows.csv' for reading: no matching file found, given up after 1 attempts
Process ImportProcess-44:
PTrocess ImportProcess-41:
raceback (most recent call last):
PTPProcess ImportProcess-42:
...
...
...
AA cls._loop.add_timer(timer)
AAttributeError: 'NoneType' object has no attribute 'add_timer'
ttributeError: 'NoneType' object has no attribute 'add_timer'
AttributeError: 'NoneType' object has no attribute 'add_timer'
ttributeError: 'NoneType' object has no attribute 'add_timer'
ttributeError: 'NoneType' object has no attribute 'add_timer'
Processed: 0 rows; Rate: 0 rows/s; Avg. rate: 0 rows/s
0 rows imported from 0 files in 1.974 seconds (0 skipped).
A sample of the first 10 lines of the csv file used to import
I have tried creating a csv file with just these first two lines, for a toy's toy test, since I couldn't get anything else to work.
id,title,year,age,imdb,rotten_tomatoes,netflix,hulu,prime_video,disney_plus,is_tvshow
0,Breaking Bad,2008,18+,9.5,96%,1,0,0,0,1
1,Stranger Things,2016,16+,8.8,93%,1,0,0,0,1
2,Money Heist,2017,18+,8.4,91%,1,0,0,0,1
3,Sherlock,2010,16+,9.1,78%,1,0,0,0,1
4,Better Call Saul,2015,18+,8.7,97%,1,0,0,0,1
5,The Office,2005,16+,8.9,81%,1,0,0,0,1
6,Black Mirror,2011,18+,8.8,83%,1,0,0,0,1
7,Supernatural,2005,16+,8.4,93%,1,0,0,0,1
8,Peaky Blinders,2013,18+,8.8,92%,1,0,0,0,1

Run Matlab script from Python: TypeError: 'float' object is not iterable

Actually I have a problem when calling a Matlab script from Python.
import matlab.engine
import os
import random
import numpy as np
a=[str(random.randint(1,3)) for _ in range(3)]
print(a)
eng=matlab.engine.start_matlab()
eng.cd("/Users/dha/Documents/MATLAB/test-matlab/",nargout=0)
sr, state=eng.test_func()
print(sr)
print(state)
In fact I want to return "sr" which is a float and an array of integer "state", e.g. sr = 34.31 and state = [1,2,5]. The function test_func() work well on Matlab, but when I run this in Python from terminal (python test_matlab_engine.py) I received the following error:
Traceback (most recent call last):
File "test_matlab_engine.py", line 10, in <module>
sr, state=eng.mabuc_drl(a)
TypeError: 'float' object is not iterable
Anyone please give me the solution. Thank you so much in advance.
It seems that the result from MATLAB to Python has been cut off. If you have two parameters, you only get one which is the first parameter from the MATLAB. So, the question is how to get two or more parameters.
In a word, you should write this in your Python file:
re = eng.your_function_name(parameter1, parameter2, nargout=2)
where re contains two parameters which come from MATLAB.
You can find more information in the official documentation: Call MATLAB Functions from Python

Python 3.4 caused type function error

I am a fresher in python.I had python 2.7 and 3.4.When I compile python 3.4 I get the following error but not in 2.7
File "C:\pyprojects\focus\site\focus2\flow.py", line 24, in _wrapper
cls._meta = type("Meta", (), BaseFlowTile.Meta.__dict__)
TypeError: type() argument 3 must be dict, not mappingproxy
If I just use dict instead __dict__ then I get the following error
AttributeError: type object 'Meta' has no attribute 'dict'
Any help is highly appreciated.
Python 3.3 introduced a MappingProxyType, that basically allowed some optimizations.
You should be able to use a copy of this for both Python versions:
cls._meta = type("Meta", (), BaseFlowTile.Meta.__dict__.copy())

Python 3: TypeError: '>' not supported between instances of 'str' and 'int'

I'm a new user of Python. I have recently changed from Python 2.7 to Python 3.6 and I am having trouble with the one line of the code that worked before in Python 2.7. Please can someone help with the line below:
paidgrouped_large = paidgrouped.loc[paidgrouped['Gross Incurred Inf'].astype(int) > paidgrouped['Largeclaimcutoff'].astype(int), :].set_index('Claim', drop=True)
which now gives me the error:
TypeError: '>' not supported between instances of 'str' and 'int'
Both columns are just columns of numbers and there are no null data.
Does anyone have an idea why it's not working?

string vs unicode encoding - Struct() argument

I am experiencing a strange problem that returns the same error, regardless of the encoding I use. The code works well, without the encoding part in Python 2.7.8, but it breaks in 2.7.6 which is the version that I use for all my development.
import MIDI_PY2 as md
import glob
import ast
import os
dir = '/Users/user/Desktop/sample midis/'
os.chdir(dir)
file_list = []
for file in glob.glob('*.mid'):
file_list.append((dir + file))
dir = '/Users/user/Desktop/sample midis/'
os.chdir(dir)
file_list returns this:
[u'/Users/user/Desktop/sample midis/M1.mid',
u'/Users/user/Desktop/sample midis/M2.mid',
u'/Users/user/Desktop/sample midis/M3.mid',
u'/Users/user/Desktop/sample midis/M4.mid']
md.concatenate_midis(file_list,'/Users/luissanchez/Desktop/temp/out.mid') returns this error:
-
TypeError Traceback (most recent call last)
<ipython-input-73-2d7eef92f566> in <module>()
----> 1 md.concatenate_midis(file_list_1,'/Users/user/Desktop/temp/out.mid')
/Users/user/Desktop/sample midis/MIDI_PY2.pyc in concatenate_midis(paths, outPath)
/Users/user/Desktop/sample midis/MIDI_PY2.pyc in midi2score(midi)
/Users/user/Desktop/sample midis/MIDI_PY2.pyc in midi2opus(midi)
TypeError: Struct() argument 1 must be string, not unicode
then I modify the code so the first argument is string, not unicode:
file_list_1 = [str(x) for x in file_list]
which returns:
['/Users/user/Desktop/sample midis/M1.mid',
'/Users/user/Desktop/sample midis/M2.mid',
'/Users/user/Desktop/sample midis/M3.mid',
'/Users/user/Desktop/sample midis/M4.mid']
running the function concatenate_midis with this last list (file_list_1) returns exactly the same error: TypeError: Struct() argument 1 must be string, not unicode.
Does anybody knows what's going on here? concatenate_midi works well in python 2.7.8, but can't figure out why it doesn't work in what I use, Enthought Canopy Python 2.7.6 | 64-bit
Thanks
The error
error: TypeError: Struct() argument 1 must be string, not unicode.
is usually caused by the struct.unpack() function which in older versions of python requires string arguments and not unicode. Check that struct.unpack() arguments are strings and not unicodes.
One possible cause is from __future__ .. statement.
>>> type('a')
<type 'str'>
>>> from __future__ import unicode_literals
>>> type('a')
<type 'unicode'>
Check whether your code contains the statement.