Getting a WARNING and ERROR: unexpected keyword argument 'queryset' - arguments

Unexpected keyword argument 'queryset' in constructor call [E:unexpected-keyword-arg]
Tried using form_kwargs as shown on stack overflow here:
# How to use the new form_kwargs on an inline formset?
if request.method == "POST":
ctx['formset'] = project_comparison_form_set(
data=request.POST, files=request.FILES, queryset=ctx['projects'])
ctx['data1'] = request.POST.copy
if ctx['formset'].is_valid():
instances = ctx['formset'].save(commit=False)
for project in instances:
project.save()
Getting both a warning and error message in pylint Unexpected keyword argument 'queryset' in constructor call [E:unexpected-keyword-arg]

You don't show where project_comparison_form_set is defined, but i assume that it is a modelformset_factory.
Here, you do not have the queryset argument. If you do want to pass a queryset, you can pass it to the formset and the formset than to the modelformset_factory.
Check the documentation https://docs.djangoproject.com/en/4.1/topics/forms/modelforms/#changing-the-queryset.

Related

Unexpected keyword argument 'unk_token'

When trying to load this tokenizer I am getting this error but I don't know why it can't take the ink_token strangely. Any ideas?
tokenizer = tokenizers.SentencePieceUnigramTokenizer(unk_token="", eos_token="", pad_token="")
----> 1 tokenizer = tokenizers.SentencePieceUnigramTokenizer(unk_token="", eos_token="", pad_token="")
TypeError: init() got an unexpected keyword argument 'unk_token'

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

I am getting the following error:
AttributeError: 'DataFrame' object has no attribute 'as_matrix'
The code that produces the error:
def plot_fruit_knn(X, y, n_neighbors, weights):
X_mat = X[['height', 'width']].as_matrix()
y_mat = y.as_matrix()
Can anyone help me spot the problem?
as_matrix() is depreceated you can use Dataframe.to_numpy() instead
y_mat = y.to_numpy()
I had the same issue, and I used .to_numpy()
Use
y_mat = y.to_numpy()
instead

Django REST API: Queryset with arguments

folks: I am trying to get the details of an entry in the database table through Django REST Framework with "url arguments" I am using the following code to get the value of "symbol" parameter however, I am getting the runtime error on the command line related to base_name. Here is the detail of my code:
class ticker_detail_full_view(viewsets.ModelViewSet):
serializer_class = ticker_detail_full
def get_queryset(self):
ticker = self.kwargs['symbol']
return ticker.objects.filter(symbol = ticker)
url: http://localhost:8000/qres/ticker_detail_full/?symbol=AMZN
I am getting the following error on the Django command-line:
router.register('ticker_detail_full', views.ticker_detail_full_view)
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rest_framework/routers.py",
line 82, in register
base_name = self.get_default_base_name(viewset)
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rest_framework/routers.py",
line 161, in get_default_base_name
assert queryset is not None, 'base_name argument not specified, and could ' \
AssertionError: base_name argument not specified, and could not
automatically determine the name from the viewset, as it does not have
a .queryset attribute.

Wordcount Nonetype error pyspark-

I am trying to do some text analysis:
def cleaning_text(sentence):
sentence=sentence.lower()
sentence=re.sub('\'','',sentence.strip())
sentence=re.sub('^\d+\/\d+|\s\d+\/\d+|\d+\-\d+\-\d+|\d+\-\w+\-\d+\s\d+\:\d+|\d+\-\w+\-\d+|\d+\/\d+\/\d+\s\d+\:\d+',' ',sentence.strip())# dates removed
sentence=re.sub(r'(.)(\/)(.)',r'\1\3',sentence.strip())
sentence=re.sub("(.*?\//)|(.*?\\\\)|(.*?\\\)|(.*?\/)",' ',sentence.strip())
sentence=re.sub('^\d+','',sentence.strip())
sentence = re.sub('[%s]' % re.escape(string.punctuation),'',sentence.strip())
cleaned=' '.join([w for w in sentence.split() if not len(w)<2 and w not in ('no', 'sc','ln') ])
cleaned=cleaned.strip()
if(len(cleaned)<=1):
return "NA"
else:
return cleaned
org_val=udf(cleaning_text,StringType())
df_new =df.withColumn("cleaned_short_desc", org_val(df["symptom_short_description_"]))
df_new =df_new.withColumn("cleaned_long_desc", org_val(df_new["long_description"]))
longWordsDF = (df_new.select(explode(split('cleaned_long_desc',' ')).alias('word'))
longWordsDF.count()
I get the following error.
File "<stdin>", line 2, in cleaning_text
AttributeError: 'NoneType' object has no attribute 'lower'
I want to perform word counts but any kind of aggregation function is giving me an error.
I tried following things:
sentence=sentence.encode("ascii", "ignore")
Added this statement in the cleaning_text function
df.dropna()
Its still giving the same issue, I do not know how to resolve this issue.
It looks like you have null values in some columns. Add an if at the beginning of cleaning_text function and the error will disappear:
if sentence is None:
return "NA"

'SparkContext' object has no attribute 'textfile'

I tried loading a file by using following code:
textdata = sc.textfile('hdfs://localhost:9000/file.txt')
Error message:
AttributeError: 'SparkContext' object has no attribute 'textfile'
It is sc.textFile(...) with a capital F.
You can inspect the API of SparkContext here.

Resources