QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,977,408
12,403,888
Options request throws AssertionError error in Django REST Framework
<p>I have the following Viewset:</p> <pre><code>class My_ViewSet(viewsets.ModelViewSet): serializer_class = My_Serializer queryset = My_Object.objects.all() def list(self, request): # The code here is irrelevant return Response() def retrieve(self, request, pk=None): # The code...
<python><django><django-rest-framework><http-method><http-options-method>
2023-04-10 13:07:54
1
443
SWater
75,977,389
1,624,552
TypeError: a bytes-like object is required, not 'str' when trying to iterate over a list of running process
<p>I am using Python in Windows. I am trying to kill a windows running process if it is already running but i get below error:</p> <blockquote> <p>TypeError: a bytes-like object is required, not 'str'</p> </blockquote> <p>I import the following modules:</p> <pre><code>import os import subprocess from time import sleep ...
<python><windows><taskkill>
2023-04-10 13:05:18
1
10,752
Willy
75,977,327
6,117,017
Deploy .zip archive (python code) to Azure Function using TerraForm
<p>I am having issues with uploading Python code to a Function App, in the sense that the function-app is created, but the code is not uploaded in the &quot;Function&quot; section, but rather in the &quot;AppFiles&quot; (there is no function in &quot;Functions&quot; in Azure Portal).</p> <p>Here is my TerraForm code:</...
<python><azure><terraform><azure-functions>
2023-04-10 12:55:57
1
15,173
Timbus Calin
75,977,316
8,391,698
How to use output from T5 model to replace masked tokens in input sequence
<p>I'm working with the T5 model from the Hugging Face Transformers library and I have an input sequence with masked tokens that I want to replace with the output generated by the model. Here's the <a href="https://huggingface.co/docs/transformers/model_doc/t5#inference" rel="nofollow noreferrer">code</a>.</p> <pre><co...
<python><nlp><huggingface-transformers><generative-pretrained-transformer>
2023-04-10 12:54:14
1
5,189
littleworth
75,977,087
10,551,444
How to fix "sys.stderr is None" after compiled a script with Pyinstaller --noconsole?
<p><strong>ENVIRONMENT</strong></p> <p>Windows 10</p> <p>Python 3.10</p> <p>Pyinstaller 5.9</p> <p><strong>PROBLEM:</strong></p> <p>I am trying to compile a script that needs to run some command lines in the console in order to get some values from the system.</p> <pre><code>if __name__ == '__main__': faulthandler....
<python><python-3.x><pyinstaller>
2023-04-10 12:22:04
2
1,223
Gauthier Buttez
75,977,012
10,048,799
Save and return to cursor in CLI not working
<p>I am attempting a type ahead / predictive typing effect in a python cli. I am referencing the following list of ANSI escape codes: <a href="https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797" rel="nofollow noreferrer">https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797</a></p> <p>Looking at the ...
<python><ansi-escape>
2023-04-10 12:11:44
0
3,723
Ben
75,976,883
2,825,403
Fill in the previous value from specific column based on a condition
<p>I have a Polars DataFrame that looks something like so:</p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame( { 'val': [9, 7, 9, 11, 2, 5], 'count': [1, 2, 1, 2, 1, 2], 'id': [1, 1, 2, 2, 3, 3], } ) </code></pre> <p>What I need is to create a new column <code>'prev_va...
<python><python-polars>
2023-04-10 11:56:09
1
4,474
NotAName
75,976,820
913,749
Glue PySpark kernel not showing in VS Code
<p>I have a Window 10 VDI and have set-up AWS Glue Interactive session using <a href="https://docs.aws.amazon.com/glue/latest/dg/interactive-sessions.html" rel="nofollow noreferrer">this link</a>. Python version set-up for this is Python 3.9.7</p> <p>When I start the notebook from command prompt, I see the various ker...
<python><visual-studio-code><jupyter-notebook><kernel><aws-glue>
2023-04-10 11:46:22
2
2,259
adbdkb
75,976,755
7,225,171
Credentials object from google service-account has no attribute `to_json`
<p>In official <a href="https://developers.google.com/sheets/api/quickstart/python#configure_the_sample" rel="nofollow noreferrer">google python client library docs</a> it is suggested to create credentials using Oauth2 client id:</p> <pre><code>flow = InstalledAppFlow.from_client_secrets_file( 'credentials...
<python><google-api><google-oauth><google-api-python-client>
2023-04-10 11:38:01
1
1,091
Serob
75,976,716
8,406,122
Extracting i-th column from a tab separated text file in python
<p>Say, I have a text file like this</p> <pre><code>John 32 Britain Marry Sunny Britney 21 India Angel Cloudy Jack 22 UK Becky Snowy Jill 43 United States of America Bill Cloudy Amy 31 South Africa Claudey Sunny </code></pre> <p>The data is tab separated. I want to extract the 3rd column which has the country names in ...
<python>
2023-04-10 11:32:07
1
377
Turing101
75,976,629
331,174
Web Socket terminating prematurely
<p>I have been trying to connect to the <code>skinport</code> WebSocket using Python. The socket documentation is at the bottom of <a href="https://docs.skinport.com/?javascript--nodejs#salefeed" rel="nofollow noreferrer">this link</a>. I am using <code>websocket-client</code> module for making a connection but the con...
<python><python-3.x><websocket>
2023-04-10 11:20:43
1
17,844
Muhammad Adeel Zahid
75,976,617
1,867,328
Definition of custom class and different methods
<p>I have below definition:</p> <pre><code>def fun1(x) : return x + 2 class my_class : def fun1(x) : return x + 22 def fun2(x) : return fun1(x) + 33 print(my_class.fun2(10)) </code></pre> <p>However this returns 45, whereas I am expecting 65 (10 + 22 + 33).</p> <p>Where am I making a mista...
<python>
2023-04-10 11:19:37
1
3,832
Bogaso
75,976,403
12,291,110
Implementing event bridge rule onto aws CDK
<p>I am new to AWS CDK and have a issue implementing what I was able to implement on the AWS console successfully</p> <p>this is the event rule that I have setup {</p> <pre><code>&quot;$or&quot;: [{ &quot;detail.distance&quot;: [{ &quot;numeric&quot;: [&quot;&gt;=&quot;, 0] }] }, { &quot;d...
<python><amazon-web-services><aws-lambda><aws-cdk><aws-event-bridge>
2023-04-10 10:44:26
2
2,191
sumanth shetty
75,976,334
6,560,267
Jupyter notebook kernel error exclusively when running it as a systemctl service
<p>I have the following service file:</p> <pre class="lang-ini prettyprint-override"><code>[Unit] Description=Jupyter-Notebook Daemon [Service] Type=simple ExecStart=/bin/bash -c &quot;~/mambaforge/envs/main/bin/jupyter-notebook --no-browser --notebook-dir=~/Code/notebooks&quot; User=&lt;my_user&gt; PIDFile=/run/jupyt...
<python><python-3.x><linux><jupyter-notebook><jupyter>
2023-04-10 10:35:58
1
913
Adrian
75,976,239
5,016,028
Sagemath expression does not solve
<p>I am trying to implement this equation in SageMath as a function:</p> <pre><code>def prob_k(p_uv_list, tw): probs = [] w, k = var('w, k') # compute probability of generating k entanglements, k=1..w for tk in range(tw): pk = binomial(w, k)*(p_uv_list[tk]**k)*(1-p_uv_list[tk])**(w-k).subs({x:tw...
<python><list><sage>
2023-04-10 10:20:29
1
4,373
Qubix
75,975,877
5,672,673
error reshaping a Dense layer in Keras functional API
<p>Hi I want to reshape a layer after a Dense layer but it returns funny error. Here is the code</p> <pre><code>codings_size=10 decoder_inputs = tf.keras.layers.Input(shape=[codings_size]) # x=tf.keras.layers.Flatten(decoder_inputs) x=tf.keras.layers.Dense(3 * 3 * 16)(decoder_inputs), x=tf.keras.layers.Reshape((3, 3, 1...
<python><tensorflow><keras><deep-learning>
2023-04-10 09:29:58
1
1,177
Linh Chi Nguyen
75,975,807
1,279,355
How to stop a loop on shutdown in FastAPI?
<p>I have a route <code>/</code> which started an endless loop (technically until the websocket is disconnected but in this simplified example it is truly endless). How do I stop this loop on shutdown:</p> <pre><code>from fastapi import FastAPI import asyncio app = FastAPI() running = True @app.on_event(&quot;shutdo...
<python><python-asyncio><fastapi><asgi>
2023-04-10 09:19:37
3
4,420
Sir l33tname
75,975,641
5,672,673
shape must be rank 4 but is rank 5 for max pool layer
<p>Hi I want to build a CNN Model for RGB images of 32x32x3 But the max pooling returns error saying:</p> <pre><code>ValueError: Exception encountered when calling layer &quot;max_pooling2d_11&quot; (type MaxPooling2D). Shape must be rank 4 but is rank 5 for '{{node max_pooling2d_11/MaxPool}} = MaxPool[T=DT_FLOAT, dat...
<python><tensorflow><keras><image-processing><conv-neural-network>
2023-04-10 08:54:16
1
1,177
Linh Chi Nguyen
75,975,480
5,405,813
Reg. google cloud vision api
<p>I am trying to read the hand-written data on hot rolled coils using python and google-cloud-vision api. But what i have observed that when the data is written in slightly inclined manner the vision api completely fails. For eg if the data is written as <a href="https://i.sstatic.net/EDbRm.jpg" rel="nofollow noreferr...
<python><google-cloud-vision>
2023-04-10 08:29:29
1
455
bipin_s
75,975,294
4,420,797
Create labels.csv file ground truth (gt.txt)
<p>I have a <code>gt.txt</code> file and I would like to convert it into <code>labels.csv</code> file. There is a difference between the two of these files.</p> <p><strong>gt.txt</strong></p> <p><a href="https://i.sstatic.net/KOgqY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KOgqY.png" alt="enter ima...
<python>
2023-04-10 07:57:37
2
2,984
Khawar Islam
75,974,892
13,916,049
ValueError: s must be a scalar, or float array-like with the same size as x and y (NetworkX)
<p>I want to plot the network for <code>gp.enrichment_map(gsea_res.res2d)</code>.</p> <pre><code>import gseapy as gp import networkx as nx import matplotlib.pyplot as plt nodes, edges = gp.enrichment_map(gsea_res.res2d) # build graph G = nx.from_pandas_edgelist(edges, source='src_idx', ...
<python><networkx>
2023-04-10 06:51:46
1
1,545
Anon
75,974,839
3,423,825
How to fix wrong number of constraints in Django with psql prompt?
<p>I'm unable to migrate a model due to the following exception and I'm trying to fix the issue with <code>psql</code>.</p> <pre><code>ValueError: Found wrong number (2) of constraints for accounting_inventory(trade_id) </code></pre> <p><strong>models.py</strong></p> <pre><code>class Inventory(TimestampedModel): c...
<python><django><postgresql><psql>
2023-04-10 06:42:08
2
1,948
Florent
75,974,811
4,420,797
Fine-Tune/Train EASY OCR on any language/Korean handwritten dataset
<p>I would like to fine-tune the EASY OCR library on the Korean handwritten samples, I am assuming that the pre-trained model is already trained on Korean and English samples.</p> <p>My idea is to enhance the Korean handwritten accuracy on EASY OCR. How I can achieve it? I know how to train custom models but due to the...
<python><python-3.x><pytorch><ocr><easyocr>
2023-04-10 06:37:57
1
2,984
Khawar Islam
75,974,776
4,343,712
getting speed issues with tcp communication and getting data truncated problem with udp communication
<p>I need to send huge number of logs in json format to a program that examine them for issues. Tried using udp first. Data are sent and received instantly but losing 30% of them. (I discard any incomplete json)</p> <p>Then I try an answer from stackoverflow <a href="https://stackoverflow.com/questions/68425239/how-to-...
<python><sockets><tcp><udp>
2023-04-10 06:31:12
0
401
user4343712
75,974,655
2,964,927
How to reconstruct (changed) sys.argv from argparse
<p>I have an argparse that after parsing does preprocessing, changes and removes things etc. Then it wraps a main that is used to get <code>sys.argv</code>. Is there a preferred way to reconstruct a new <code>sys.argv</code> with the adapted fields?</p> <pre><code>args, unknown = parser.parse_known_args() args.new = ar...
<python><argparse>
2023-04-10 06:05:53
2
26,345
borgr
75,974,539
10,035,190
how to fetch all links from html without ancore tag?
<p>I want to fetch all links from the link given in code and particularly this <a href="https://api.somthing.com/v1/companies/" rel="nofollow noreferrer">https://api.somthing.com/v1/companies/</a> link. All the regex which I found online is only fetching simple links like <a href="https://api.somthing.com" rel="nofoll...
<python><beautifulsoup><html-parsing>
2023-04-10 05:40:04
1
930
zircon
75,974,202
654,019
error trying to train a model using ultralytics yolo 8 model
<p>I am trying to train Yolo 8 using a sample data set as explained here: <a href="https://learnopencv.com/train-yolov8-on-custom-dataset/#The-Pothole-Detection-Dataset-to-Train-YOLOv8" rel="nofollow noreferrer">https://learnopencv.com/train-yolov8-on-custom-dataset/#The-Pothole-Detection-Dataset-to-Train-YOLOv8</a></...
<python><artificial-intelligence><object-detection><yolo><yolov8>
2023-04-10 04:07:02
1
18,400
mans
75,974,118
3,018,860
Arithmetic operation in Python returns weird output
<p>I'm getting weird results in Python with a very simple operation. In my case, I'm making a funny terminal game to practice operations with fractions, and the game works fine until Python returns too much decimals. For example:</p> <pre class="lang-py prettyprint-override"><code>res1 =(3/4)-(6/5) res2 = -9/20 print(r...
<python><math><floating-point><precision>
2023-04-10 03:37:01
0
2,834
Unix
75,974,090
13,138,455
psutil error in building python Dockerfile
<p>I built below dockerfile using python image for my python heavy project</p> <pre><code>FROM python:3.11-slim-buster # Update and install system packages RUN apt-get update -y &amp;&amp; \ apt-get install --no-install-recommends -y -q \ git libpq-dev python-dev &amp;&amp; \ apt-get clean &amp;&amp; \ rm -rf ...
<python><docker>
2023-04-10 03:23:42
3
567
R0bert
75,974,053
8,968,910
MessageToDict: How to extract keys in multiple dictionaries?
<pre><code>from google.protobuf.json_format import MessageToDict audio={'results': [{'alternatives': [{'transcript': 'His name is Charlie', 'confidence': 0.9259988}], 'resultEndTime': '7.700s', 'languageCode': 'en'}, {'alternatives': [{'transcript': 'an...
<python><dictionary>
2023-04-10 03:13:12
1
699
Lara19
75,974,013
4,780,574
Python Selenium Geckodriver autoinstall: permission denied when getting Firefox version
<p>I was running a python script that has been fine on several different distros, but is giving me trouble on Gentoo. The problem command is <code>geckodriver_autoinstaller.install()</code>:</p> <pre><code>Traceback (most recent call last): File &quot;/home/james/Gits/News_Scraper/main.py&quot;, line 5, in &lt;module...
<python><selenium-webdriver><permissions><alias><geckodriver>
2023-04-10 02:57:18
0
814
Stonecraft
75,973,925
7,339,624
Can I use pytoch amp functions, GradScaler and autocast on CPU?
<p>I am currently trying to debug my code and would like to run it on the CPU, but I am using <code>torch.cuda.amp.autocast()</code> and <code>torch.cuda.amp.GradScaler()</code>, which are part of the Automatic Mixed Precision package that is from <code>cuda</code> and will be automatically on GPU.</p> <p>Is there a wa...
<python><pytorch>
2023-04-10 02:30:53
1
4,337
Peyman
75,973,809
3,398,324
Save dataframe as txt with specific delimiters
<p>I would like to save my dataframe in txt format with specific delimiters (libsvm format), to look like this:</p> <pre><code>1 qid:0 0:1.465648768921554 1:-0.2257763004865357 2:0.06752820468792384 3:-1.424748186213457 4:-0.5443827245251827 1 qid:0 0:1.465648768921554 1:-0.2257763004865357 2:0.06752820468792384 3:-1.4...
<python><pandas><libsvm>
2023-04-10 01:56:54
1
1,051
Tartaglia
75,973,552
9,873,381
How can I use the odeint function from torchdiffeq to classify two concentric annuli?
<p>I have a dataset where the two classes are distributed on two concentric circles with 0 overlap. How can I use a neural ODE to solve this?</p> <p>I get the error <code>RuntimeError: shape '[1024, 2]' is invalid for input of size 1024</code> when I run the network below.</p> <pre><code>class ODEFunc(nn.Module): ...
<python><pytorch><classification><odeint>
2023-04-10 00:25:33
1
672
Skywalker
75,973,437
14,509,604
Pandas | Make a summary table with multiple criteria per value
<p>I'm trying to make a summary table like this:</p> <p><a href="https://i.sstatic.net/uquq7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uquq7.png" alt="enter image description here" /></a></p> <p>From this dataset:</p> <pre class="lang-py prettyprint-override"><code> pd.DataFrame(data={&quot;grade&q...
<python><pandas>
2023-04-09 23:44:44
1
329
juanmac
75,973,322
1,574,054
Cannot create slots-dataclass with __dict__
<p>In python, it is possible to create slots classes which do have an explicit <code>__dict__</code> available. However, I am struggling to get this working with dataclasses:</p> <pre><code>from dataclasses import dataclass @dataclass(slots=True) class A: __dict__: dict[str, object] A() </code></pre> <p>This rais...
<python><python-dataclasses>
2023-04-09 23:09:15
0
4,589
HerpDerpington
75,973,296
12,300,981
Scipy Minimize, can the inverse hessian be used to eliminate multiple solutions with similar "fun"?
<p>Let's say you have a minimization problem:</p> <pre><code>data_set_1=[[24.714, 24.713, 24.605, 24.607], [25.708, 25.59, 25.557, 25.753], [22.713, 22.654, 22.655, 22.812], [24.231, 24.233, 24.289, 24.109], [24.401, 24.385, 24.396, 24.408], [26.124, 26.107, 25.915, 25.847], [15.341, 15.242, 15.049, 14.847], [22.332, 2...
<python><numpy><scipy><scipy-optimize>
2023-04-09 23:00:27
1
623
samman
75,973,288
480,118
regular expression to group matches and non-matches
<p>i have the following string. i want to tokenize this such that there are groups for both the matched curly braces and non match</p> <pre class="lang-py prettyprint-override"><code>str='{field1}somestring{field2}somestring2{feild3}&lt;somestring3&gt;' </code></pre> <p>i know i can tokenize the curly braces with:</p> ...
<python><regex>
2023-04-09 22:56:37
1
6,184
mike01010
75,973,048
20,947,319
How to check if a user is subscribed to a product in Django template
<p>I am working on a Django project whereby I want to check if a user is subscribed to a product or not. I have created in my models.py several model instances and I am stuck on how to check if the user is subscribed inside the template. Here is my template where I loop through the fetched data:</p> <pre><code>&lt;ul&g...
<python><django><django-templates><subscription>
2023-04-09 21:48:04
1
446
victor
75,973,040
15,724,084
attributeError 'tkinter.app' object has no attribute, where I defined method inside classs
<p>My code gives me an error of <code> File &quot;C:\pythonPro\...widgets.py&quot;, line 109, in openNewWindow self.btn_submit=self.button_creation(self.newWindow) File &quot;C:\Users\Admin\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py&quot;, line 2383, in __getattr__ return getattr(self.tk, attr) At...
<python><tkinter>
2023-04-09 21:46:41
1
741
xlmaster
75,972,956
3,398,324
Replace row values in Panda columns
<p>I have a dataframe column which is a date and I would like to replace it like this:</p> <p>Current DataFrame:</p> <pre><code>data = {'date': ['1/1/2022', '1/2/2022,1/3/2022]} df = pd.DataFrame(data) </code></pre> <p>Target DataFrame:</p> <pre><code>data = {'date': ['qid:0', 'qid:1','qid:2']} df = pd.DataFrame(data) ...
<python><pandas><date>
2023-04-09 21:25:01
1
1,051
Tartaglia
75,972,844
11,146,276
AWS CDK Lambda says "[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda': No module named 'orjson'"
<p>I'm writing the code on Windows. This is my project structure:</p> <pre><code>my-project/ ├─ stack/ │ ├─ src/ │ │ ├─ functions/ │ │ │ ├─ lambda.py │ ├─ __init__.py │ ├─ my_stack.py ├─ app.py ├─ poetry.lock ├─ pyproject.toml </code></pre> <p>My root stack defines a /package endpoint that takes query parameter...
<python><amazon-web-services><aws-lambda><aws-cdk>
2023-04-09 20:58:34
0
428
Firefly
75,972,670
357,024
Python asyncio "contains"
<p>Can the <code>__contains__</code> function by adapted to Python asyncio, where the method becomes a coroutine? For example</p> <pre><code>class A(): async def __contains__(self, a): return True async def main(): a = A() print(2 in a) </code></pre> <p>Of course this generates the warning</p> <blo...
<python><python-asyncio>
2023-04-09 20:18:31
1
61,290
Mike
75,972,643
9,764,940
How can i shift a 2d array by an 1d array in numpy? The same for 3d by 2d
<p>Say i have an 2d array and an 1d array like this:</p> <pre><code>a= np.array([[1,1,1,1],[2,2,2,2],[3,3,3,3]]) b= np.array([0,2,1,0]) </code></pre> <p>And as a result i want this:</p> <pre><code>out= np.array([[1,2,3,1],[2,3,1,2],[3,1,2,3]]) </code></pre> <p>Every values in a is shifted along an axis by a value in an...
<python><numpy>
2023-04-09 20:10:10
2
723
HrkBrkkl
75,972,600
5,617,608
Some CSV values appear in the wrong column (with open python)
<p>I'm writing data to a CSV file in Python. The data is in Unicode-8. I've written several rows successfully. However, a part of the data from column B is written to column A. The data already includes commas and numbers in English along with Arabic text.</p> <p>I also checked in NotePad that the text is between doubl...
<python><python-3.x><csv><writer><csvwriter>
2023-04-09 20:00:41
1
1,759
Esraa Abdelmaksoud
75,972,526
13,326,869
How to access camera or webcam in kaggle?
<p>I tried using a webcam in Kaggle to take capture for the face detection project. but it's not working.</p> <blockquote> <p>code working well in Jupyter Notebook in the system</p> </blockquote> <p>here is the code that I'm using :</p> <pre><code>cap = cv2.VideoCapture(0) for imgnum in range(number_images): print...
<python><data-science><webcam><face-detection><kaggle>
2023-04-09 19:42:42
0
651
Alireza Atashnejad
75,972,508
977,345
Typing an Optional staticmethod with and without arguments
<p>I'm trying to add typing for a method that is None (has the literal value of None) in the base class, but child classes can implement it using a staticmethod. What I have so far is as followed:</p> <pre class="lang-py prettyprint-override"><code>class BaseClass: attr: ClassVar[Optional[Callable[[str], None]]] = ...
<python><mypy><python-typing>
2023-04-09 19:39:07
1
821
Ivailo Karamanolev
75,972,375
8,923,742
get a dict with key as column names and value as column type of a pandas dataframe
<p>I have a pandas dataframe as shown below:-</p> <pre><code> A B C D 0 56 89 16 b 1 51 41 99 b 2 49 3 72 d 3 15 98 58 c 4 92 55 77 d </code></pre> <p>I want to create a dict where key is column name and value is column data type.</p> <pre><code>dtypes = df.dtypes.to_dict() print(dtypes) ...
<python>
2023-04-09 19:07:26
1
1,396
itthrill
75,972,319
799,593
Python 3.x functools.partial() function got multiple values for argument parameter
<p>I am trying to pass an extra argument to map function for a Django REST framework API endpoint. The following worked in my test, but I am not sure what am I missing in my Django API.</p> <pre><code>&gt;&gt;&gt; tt [(datetime.datetime(2023, 4, 1, 0, 0), datetime.datetime(2023, 4, 10, 0, 0)), (datetime.datetime(2023,...
<python><python-3.x><functools>
2023-04-09 18:55:12
0
722
ablaze
75,972,272
6,423,456
Adding custom expensive field on Django model serializer
<p>Normally, in Django, using rest_framework, to add a custom field to a model, you can use <code>SerializerMethodField</code>. From what I understand however, this works great for values that are easy to calculate, but if the value requires database queries to related tables, you're going to be performing these for ev...
<python><django><django-rest-framework>
2023-04-09 18:41:52
1
2,774
John
75,972,260
5,495,304
Cannot install own package with `pip install .`
<p>I have a package with a <code>setup.py</code> file importing external packages like <code>numpy</code> and <code>Cython</code> for building the package during installation. Here is how the top of my <code>setup.py</code> file looks like:</p> <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3 impo...
<python><pip><setuptools>
2023-04-09 18:38:21
1
6,659
Gerges
75,972,194
2,789,334
formatting groups of cells in pandas
<p>My pandas dataframe is shown below</p> <pre><code>import pandas as pd inp_df = pd.DataFrame( [ [&quot;a1&quot;, &quot;b1&quot;, &quot;c1&quot;, &quot;gbt&quot;, &quot;auc&quot;, 82.5, 80.1, 83.6], [&quot;a1&quot;, &quot;b1&quot;, &quot;c1&quot;, &quot;gbt&quot;, &quot;pr@5%&quot;, 0.3, 0.2, 0.4...
<python><pandas><dataframe>
2023-04-09 18:22:39
1
1,068
ironv
75,972,052
15,322,101
Correctly implementing specific formula into python
<p>This may be more of a math question, rather than a programing question but I am absolutely stuck and the problem occured to me while implementing it in python via <code>numpy</code>. So, in my Machine Learning course the professor constructed an estimator for <code>Linear Regression</code> which resulted into the fo...
<python><numpy><machine-learning><math><linear-algebra>
2023-04-09 17:59:33
2
347
Infomagier
75,971,842
5,431,132
Expose Python API to Kubernetes minikube deployment
<p>I want to expose an API written in Python to a Minikube cluster. I have the following directory structure</p> <pre><code>- Dockerfile - src - pyproject.toml - src - api.py - nginx-chart - templates - deployment.yaml - service.yaml - chart.yaml - values.yaml </code></pre> <p>In api...
<python><docker><kubernetes><nginx><minikube>
2023-04-09 17:04:10
1
582
AngusTheMan
75,971,704
10,395,139
"Zoom" in the most concentrated part of a plot
<p>I'm creating a scatter plot in matplot where I'm showing the spread of images width and height values. Is there a way to use the <code>plt.xlim</code> or another method to &quot;zoom&quot; in on the most concentrated values. Now I have a plot with many values ranging between 200 - 500, it would be nice to &quot;zoom...
<python><matplotlib>
2023-04-09 16:35:39
1
579
Krullmizter
75,971,521
7,093,241
Is the time complexity the same in finding target value in a 2D matrix with these 2 approaches?
<p>The <a href="https://leetcode.com/problems/search-a-2d-matrix/description/" rel="nofollow noreferrer">leetcode question</a> calls for searching for a target value in a 2D matrix. Both approaches use binary search.</p> <p><strong>My approach:</strong></p> <p>Consider the matrix as a single array where of length <code...
<python><algorithm><time-complexity>
2023-04-09 16:00:46
1
1,794
heretoinfinity
75,971,479
16,813,096
Can we change the height of tkinter menu?
<p>I am adding lots of options in the tkinter popup menu widget, but it fills the whole screen height (as shown in image). I want to limit the number of displayed options in tkinter menu like the <strong>tkinter combobox's listbox</strong> height (which can be changed by passing the <code>height</code> parameter)</p> <...
<python><python-3.x><tkinter><tkinter-canvas><ttk>
2023-04-09 15:50:12
0
582
Akascape
75,971,433
4,115,378
How do I "click" accept using requests in Python
<p>Here is the html that I am looking to &quot;click&quot;</p> <pre><code>&lt;input id=&quot;ctl00_mainContentPlaceHolder_acceptButton&quot; name=&quot;ctl00$mainContentPlaceHolder$acceptButton&quot; type=&quot;submit&quot; value=&quot;I accept the above terms&quot;/&gt; </code></pre> <p>The general template that I am ...
<python><python-requests>
2023-04-09 15:39:00
1
1,364
A1122
75,971,357
10,392,393
dockerized kafka consumer stuck at "Attaching to..." when having the line for iterating over messages
<p>I am very new to docker and Kafka, and have a simple kafka python publisher shown below</p> <p>The following are in my dockerfile:</p> <pre><code>FROM python:3.10 WORKDIR /app COPY . /app RUN pip install --user pip==23.0.1 &amp;&amp; pip install pipenv &amp;&amp; pipenv install --system ENV ENVIRONMENT=productio...
<python><docker><apache-kafka><docker-compose><kafka-consumer-api>
2023-04-09 15:25:16
1
979
Alejandro
75,971,333
6,430,403
Getting error when calling lambda function running locally on docker through browser
<p>I have a docker image that I use to deploy my python code on AWS lambda. Then I enable function url and call it using javascript's fetch written inside an HTML file, which runs in a browser. I enabled CORS setting in the lambda configuration. It is functioning properly.<br /> Here is my lambda function:</p> <pre><co...
<javascript><python><amazon-web-services><docker><cors>
2023-04-09 15:19:52
0
401
Rishabh Gupta
75,971,245
2,510,104
How to collate several protobuf messages into one object
<p>I have a a protobuf message in the form of:</p> <pre><code>message CustomMessage { SubMessageTypeA a_msg = 1; SubMessageTypeB b_msg = 2; SubMessageTypeC c_msg = 3; } </code></pre> <p>I have several objects (assume 3) of this type that each have one of their respective fields populated. I want to coll...
<python><descriptor><proto3><protobuf-python>
2023-04-09 15:02:19
1
541
Amir
75,971,147
2,304,735
Q Learning code error while running how can I fix it?
<p>I am trying to write a simple python program that implements Q-Learning on the OpenAI Gym Environment Frozen Lake. I found the program code on data camp website you will find the code and link below:</p> <p>Link: <a href="https://www.datacamp.com/tutorial/introduction-q-learning-beginner-tutorial" rel="nofollow nore...
<python><numpy><reinforcement-learning><openai-gym><q-learning>
2023-04-09 14:42:13
1
515
Mahmoud Abdel-Rahman
75,971,144
4,451,315
How to mimic pandas' duplicated in polars
<p>In this example:</p> <pre class="lang-py prettyprint-override"><code>In [6]: pd.Series([1, 2, 2, 3]).duplicated() Out[6]: 0 False 1 False 2 True 3 False dtype: bool In [7]: pl.Series([1, 2, 2, 3]).is_duplicated() Out[7]: shape: (4,) Series: '' [bool] [ false true true fa...
<python><pandas><python-polars>
2023-04-09 14:41:59
1
11,062
ignoring_gravity
75,971,119
20,999,526
How to reset permissions granted/denied to a pyinstaller executable?
<p>I have created an app using pyinstaller that uses <strong>pywebview</strong> and Zoom Meeting SDK. When the user opens the Zoom Meeting for the first time in my app, it automatically asks for microphone and camera permission. If the user denies the permission, there is no way to enable the permission again. How can ...
<python><pyinstaller><zoom-sdk><pywebview>
2023-04-09 14:34:49
0
337
George
75,971,106
3,413,239
Parsing complicated polynomial expressions in python
<p>I have complicated polynomial expressions in string format. For example, <code>-1/4 + 1/(2*Sqrt[5]) + u^2</code>, <code>u^2 + Root[1 + 84*#1 + 560*#1^2 + 448*#1^3 &amp; , 2, 0]</code>. Is there a way to parse this using <code>sympy</code> or any other library in Python?</p> <p>Here <code>Root[..., n, 0]</code> is a ...
<python><parsing><sympy><polynomials>
2023-04-09 14:32:29
1
5,248
pg2455
75,971,046
3,579,151
XML and probably LXML issue
<p>I have many XML files that look like this</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;no&quot;?&gt; &lt;reiXmlPrenos&gt; &lt;Qfl&gt;1808&lt;/Qfl&gt; &lt;fOVE&gt;13.7&lt;/fOVE&gt; &lt;NetoVolumen&gt;613&lt;/NetoVolumen&gt; &lt;Hv&gt;104.2&lt;/Hv&gt; &lt;energe...
<python><xml><dataframe><lxml>
2023-04-09 14:17:38
2
419
energyMax
75,970,820
4,508,962
Numba compiler fails with np.sum?
<p>I have a function that I want to accelerate using Numba (it computes the log-likelihood sum of residual given cov-var matrices, just for the context but <strong>this is not important for the question</strong>)</p> <pre><code>@jit(nopython=True) def log_ll_norm_multivar(sigma, epsilon, mean=None) -&gt; float: &qu...
<python><numpy><numba>
2023-04-09 13:30:09
0
1,207
Jerem Lachkar
75,970,819
11,925,464
Frequency rolling count with groupby, Pandas
<p>I'm trying to get the frequency count of a groupby which is grouped by name and date. I am having trouble figuring out how to do a 3 days roll count prior to the current day.</p> <p>example: on 2022-01-05, John's 3 days range are 2022-01-05 and 2022-01-01 with 2 times each, hence, showing 4 in the '3 days roll count...
<python><pandas><group-by><count><shift>
2023-04-09 13:29:45
1
597
ManOnTheMoon
75,970,673
653,397
Unable to call Language Studio Custom Named Entity Recognition Endpoint
<p>I have trained and deployed a <code>Custom Named Entity Recognition</code> model in <code>Language Studio</code>. The model is successfully deployed and I can test it from Language Studio UI, I can see the detected entities. But when I try to access the endpoint from either Postman or Python I get the message <code>...
<python><azure><named-entity-recognition><azure-cognitive-services><language-studio>
2023-04-09 13:04:27
1
1,930
Atinesh Singh
75,970,490
9,494,140
how to edit XML file in python
<p>I have an XML file that I need to change only 2 attributes inside :</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;kml xmlns=&quot;http://www.opengis.net/kml/2.2&quot; xmlns:gx=&quot;http://www.google.com/kml/ext/2.2&quot; xmlns:kml=&quot;ht...
<python><xml><elementtree><xml-namespaces>
2023-04-09 12:22:35
0
4,483
Ahmed Wagdi
75,970,233
6,057,371
pandas dataframe get rows when list values in specific columns meet certain condition
<p>I have a dataframe:</p> <pre><code>df = A B 1 [0.2,0.8] 2 [0.6,0.9] </code></pre> <p>I want to get only rows where all the values of B are &gt;= 0.5 So here:</p> <pre><code>new_df = A B 2 [0.6, 0.9] </code></pre> <p>What is the best way to do it?</p>
<python><pandas><dataframe><data-munging>
2023-04-09 11:31:17
4
2,050
Cranjis
75,970,153
2,707,864
Get rid of prefactors, without altering the rest of expression
<p>I have this expression in <code>sympy</code></p> <pre><code>expr = 60378125*139**(13/16)*2143750**(1/8)*x**(9/4)*m**(1/4)/(15420489728*y**(1/4)*z**(3/4)) </code></pre> <p>(Note: this actually comes from other calculations, which are too long to post here. So I am not sure I can work with anything different, e.g., an...
<python><sympy>
2023-04-09 11:10:14
3
15,820
sancho.s ReinstateMonicaCellio
75,970,040
216,190
Workaround Mutable Default Arguments in Python
<p>Going through the <a href="https://docs.python.org/3/tutorial/controlflow.html#default-argument-values" rel="nofollow noreferrer">python documentation</a>, I came across below.</p> <blockquote> <p><strong>Important warning</strong>: The default value is evaluated only once. This makes a difference when the default i...
<python><default-parameters>
2023-04-09 10:42:14
1
24,333
Kraken
75,969,974
1,335,473
OpenAI GPT-3 API: Why do I get an unexpected response?
<p>I am connecting to the GPT-3 API through a Jupyter Notebook. This is the code:</p> <pre><code>import openai import os # Set up your API key openai.api_key = os.environ[&quot;OPENAI_API_KEY&quot;] # Choose the API endpoint model_engine = &quot;davinci&quot; # Create a prompt prompt = &quot;Hello, ChatGPT!&quot; #...
<python><jupyter-notebook><openai-api><gpt-3>
2023-04-09 10:26:58
1
824
JoeyC
75,969,972
2,744,242
How to build Vue to be served by Python?
<p>I started a project in Vue 3 (Vite) with the name <code>poc_test</code> and chose everything <code>No</code></p> <pre><code>npm init vue@latest ✔ Project name: poc_test ✔ Add TypeScript? … No / Yes ✔ Add JSX Support? … No / Yes ✔ Add Vue Router for Single Page Application development? … No / Yes ✔ Add Pinia for sta...
<python><vue.js><vuejs3><vite>
2023-04-09 10:26:35
0
13,406
rafaelcb21
75,969,938
6,543,779
Not able to divide forloop.counter in django template?
<p>I am using django 4.1.5, and i am trying to divide the current forloop counter with 3. Problem is, i tried so many different syntax, but nothing is working</p> <pre><code>&lt;h3&gt; {{ forloop.counter|div:3 }} &lt;/h3&gt; Exception Value: Invalid filter: 'div' &lt;h3&gt; {{ forloop.counter|div:&quot;3&quot; }} ...
<python><django>
2023-04-09 10:20:28
2
499
Tarun K
75,969,875
11,098,908
What is the need to define a function to return a class's attribute?
<p>I came across some code like this</p> <pre><code>class Student(Person): def __init__(self, age): self.age = age def get_age(self): return self.age </code></pre> <p>Could you please explain the purpose of the function <code>get_age()</code>? If we want to know a student's age, can't we simply...
<python><class><oop><instance>
2023-04-09 10:06:26
1
1,306
Nemo
75,969,842
18,157,326
is the process still running in docker container
<p>When I login into the python container running in Kubernetes and using this command to check the process:</p> <pre><code>root@chat-server-service-594dc96485-rpphl:~/chat-server# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 97084 17560 ? Ssl 17:19 ...
<python><docker><uvicorn>
2023-04-09 09:59:57
0
1,173
spark
75,969,694
11,092,636
cmap not behaving like it should although the values of the array are all in the cmap indices
<p>MRE:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import matplotlib.pyplot as plt # Define a custom colormap (for the masks images) colors = ['black', 'red', 'blue', 'purple', 'green'] labels = ['a', 'b', 'c', 'd', 'e'] cmap = mcolors.ListedColormap(colors) # Function to display the legen...
<python><matplotlib>
2023-04-09 09:25:31
1
720
FluidMechanics Potential Flows
75,969,529
11,246,330
`pip install --upgrade ` behaves differently for pyproject.toml and requirements.txt
<p>If I have a <code>venv</code> with <code>black==22.12.0</code> installed and I run <code>pip install --U black</code> then <code>pip</code> will update to the newest version of black. I will see same behavior if <code>black</code> is listed in a requirements.txt and I run <code>pip install -U -r requirements.txt</co...
<python><pip><pyproject.toml>
2023-04-09 08:43:38
1
370
PerJensen
75,969,388
4,399,016
Using Python APIs to download data and make pandas
<p>I want to download data from <a href="https://tablebuilder.singstat.gov.sg/table/TS/M250141" rel="nofollow noreferrer">this website</a> using APIs that are made available.</p> <p>However, the <a href="https://tablebuilder.singstat.gov.sg/view-api/for-developers" rel="nofollow noreferrer">code I have</a> with me only...
<python><json><pandas>
2023-04-09 07:57:50
1
680
prashanth manohar
75,969,386
1,949,081
Python - PDF to HTML failing with OSError in AWS Lambda
<p>I have following code executed in AWS Lambda</p> <pre><code>def handler(event, context): s3 = boto3.resource('s3') env = Environment(loader=FileSystemLoader(searchpath='templates'), trim_blocks=True, lstrip_blocks=True, autoescape=select_autoescape(['html', 'xml'])) template = env.g...
<python><amazon-web-services><aws-lambda><pdfkit>
2023-04-09 07:57:31
1
5,528
slysid
75,969,294
3,667,693
AssertionError: No inf checks were recorded for this optimizer
<p>Code was based off on <a href="https://github.com/tloen/alpaca-lora/blob/main/finetune.py" rel="noreferrer">https://github.com/tloen/alpaca-lora/blob/main/finetune.py</a></p> <p>My objective of this training was to made use of unsupervised training dataset to get the model to understand how words are written in my d...
<python><pytorch><alpaca>
2023-04-09 07:31:20
4
405
John Jam
75,969,212
1,815,710
flask db migrate adds project name to generated script
<p>When I run <code>flask db upgrade</code>, I am getting this error</p> <pre><code> File &quot;/Users/user/Development/projects/zen/zen_api/zen_api/migrations/versions/88e9c6a7b904_.py&quot;, line 23, in upgrade sa.Column('first_name', sa.String(length=zen_api.config.Config['NAME_LENGTH']), nullable=False), ...
<python><flask><flask-sqlalchemy><flask-migrate>
2023-04-09 07:11:07
0
16,539
Liondancer
75,969,176
12,667,081
Is there a faster way to parse large json list of lists?
<p>I am fetching responses from thousands of API calls, each of which is a new JSON, as the api is paginated. The result I get is a list of lists, with each inner list the JSON of one page. The following code is how I am successfully parsing the data:</p> <pre><code>import csv import... def save(csv_data): with o...
<python><list><nested-for-loop>
2023-04-09 06:58:45
1
545
Brian - RGY Studio
75,968,905
3,398,324
Create txt file from Pandas Dataframe
<p>I would like to save my dataframe in a way that matches an existing txt file (I have a trained model based on the this txt file and I now want to predict on new data, that needs to match this format).</p> <p>The target txt file looks like this (first3 rows):</p> <pre><code>2 qid:0 0:0.4967141530112327 1:-0.13826430...
<python><pandas><txt>
2023-04-09 05:21:55
2
1,051
Tartaglia
75,968,903
11,720,193
Glue Python script to read xml (from SOAP) and write as Parquet to S3
<p>I have a requirement to create a Glue Python script to read XML using SOAP API and store the returned xml string in Parquet format on S3.</p> <p>I got the SOAP communication working fine. Now, for the later part, my intention was to create a <code>Pandas</code> <code>dataframe</code> by using <code>read_xml()</code>...
<python><pandas><soap><xml-parsing>
2023-04-09 05:20:35
1
895
marie20
75,968,750
13,916,049
How to extract substring from pandas column?
<p>I want to retrieve only the first part of the string for the entire column.</p> <pre><code>meta[&quot;Cell_type&quot;].str.rstrip(&quot; &quot;)[0] </code></pre> <p>Data:</p> <p><code>meta.iloc[1:5]</code></p> <pre><code>pd.DataFrame({'Assay Type': {'SRR9200814': 'RNA-Seq', 'SRR9200815': 'RNA-Seq', 'SRR9200816':...
<python><pandas>
2023-04-09 04:16:53
4
1,545
Anon
75,968,724
9,565,958
how to remove some of one array's elements according to other array's value in numpy
<p>In numpy,</p> <pre><code>a = np.array([[0, 0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0]]) b = np.array([[5, 2, 0, 1, 0, 2, 3], [0, 0, 0, 1, 5, 3, 0]]) </code></pre> <p>I want to remove some of <code>b</code>'s elements according to <code>a</code>'s values. I want to keep the elements of <code>b</code> only when the valu...
<python><numpy>
2023-04-09 04:03:36
3
512
June Yoon
75,968,675
3,233,017
DistributionNotFound exception in Jupyter but not in standard Python
<p>I have a fork of an open-source Python module (CLTK) which is needed for a particular application. To make it easier on people running my code, I specifically modify the PATH before importing it, so that they can have standard CLTK for most applications and my forked CLTK for this one purpose.</p> <pre><code>import ...
<python><jupyter-notebook>
2023-04-09 03:45:19
0
3,547
Draconis
75,968,672
844,936
Python LangChain CSV Agent need help in Chart Image saving
<p>I am pretty new in LangChain, playing with Langchain's CSV Agent. It is giving me the desired result. Look at the attached image</p> <p><a href="https://i.sstatic.net/vrDGo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vrDGo.png" alt="enter image description here" /></a></p> <p>Now, I want to use th...
<python><google-colaboratory><langchain>
2023-04-09 03:42:14
2
520
LuckyCoder
75,968,670
20,262,902
Change the cell size/width of imshow or similar function
<p>I need the first and last cells to be half the width.</p> <p>My goal is to get something like this:</p> <p><a href="https://i.sstatic.net/ereWv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ereWv.png" alt="enter image description here" /></a></p> <p>But I got this:</p> <p><a href="https://i.sstatic....
<python><matplotlib><plot><imshow>
2023-04-09 03:41:14
1
670
Joao_PS
75,968,600
13,776,631
Why does my simple linear model learn a threshold function f(x) = (x > 0) on the dataset g(X) but perform poorly on X?
<p>Why does the <em>validation loss</em> increase while <em>train loss</em> decreases when training data is x and validation data is gen(x)?</p> <p>I made a <code>classifier(SimpleModel)</code>. when I train a classifier with <code>input=torch.randn(100,1)</code> and <code>label=(1 if input&gt;0, else 0)</code>, the cl...
<python><deep-learning><pytorch><neural-network>
2023-04-09 03:13:11
1
301
beginner
75,968,481
4,019,495
What causes the difference between `f"{a}"` vs `f"{a=}"` in python's f strings?
<p>In the following python code, what causes the difference in outputs?</p> <pre><code>try: open('nonexistent') except Exception as err: print(f'{err=}') print(f'{err}') </code></pre> <p>result:</p> <pre><code>err=FileNotFoundError(2, 'No such file or directory') [Errno 2] No such file or directory: 'nonexi...
<python><python-3.x><f-string>
2023-04-09 02:12:43
1
835
extremeaxe5
75,968,471
3,725,925
Google-Drive-API File not found using FORM_ID
<p>I'm a novice Python hobbyist programmer who is trying to automate some vocabulary tests for my students. Everything in the below code works except for sharing it with the list of emails. I know for a fact that the Drive ID is the same as the Forms ID as I have manually checked with testing. I'm able to add all of th...
<python><google-drive-api><google-forms-api>
2023-04-09 02:09:27
1
340
Mikitz06
75,968,433
13,854,064
How to access Android notifications with a Toga app
<p>I am trying to build an app with Toga/Beeware, mainly for Android but ideally cross-platform. I need the app to send push notifications at user-specified times. I see <a href="https://github.com/beeware/toga/issues/907" rel="nofollow noreferrer">some have previously attempted the same challenge</a>, but <a href="htt...
<python><android><push-notification><notifications><beeware>
2023-04-09 01:48:07
1
434
gimi
75,968,376
4,930,914
Lowercase text with regex pattern
<p>I use regex pattern to block acronyms while lower casing text.</p> <p>The code is</p> <pre><code># -*- coding: utf-8 -*- #!/usr/bin/env python from __future__ import unicode_literals import codecs import os import re text = &quot;This sentence contains ADS, NASA and K.A. as acronymns.&quot; pattern = r'([A-Z][a-z...
<python><regex>
2023-04-09 01:20:58
1
915
Programmer_nltk
75,968,226
274,610
How can I install Tensorflow and CUDA drivers?
<p>I have a clean install of CUDA drivers and TensorFlow, but I cannot get TensorFlow to use my CUDA drivers.</p> <p>My version of Windows 11 Pro is 22H2.</p> <p>I'm running Anaconda Python 3.9.15.</p> <p>Here is the information on my CUDA drivers (by running nvidia-smi):</p> <pre><code>Sat Apr 8 16:44:56 2023 +------...
<python><tensorflow>
2023-04-09 00:13:47
2
529
user274610
75,968,070
6,423,456
How do I fix the return type of a Django model manager's method?
<p>I'm using Django 4.1.7 with django-stubs 1.16.0, and mypy 1.1.1.</p> <p>I have code that looks like this:</p> <pre class="lang-py prettyprint-override"><code>class ProductQuerySet(QuerySet): ... class ProductManager(Manager): def create_red_product(self, **kwargs) -&gt; &quot;Product&quot;: return s...
<python><django><mypy>
2023-04-08 23:01:14
1
2,774
John
75,968,037
6,423,456
How do I type a custom User model manager for mypy in Django?
<p>I'm using Django 4.1.7 with django-stubs 1.16.0, and mypy 1.1.1.</p> <p>I created a custom user manager for my User model like this:</p> <pre class="lang-py prettyprint-override"><code>from django.contrib.auth.models import UserManager class MyUserManager(UserManager): def delete_test_data(self): retur...
<python><django><mypy>
2023-04-08 22:49:03
1
2,774
John