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
⌀
77,472,215
12,320,336
Run Python script using a hotkey when a specific program is active
<p>Intended setup:</p> <ul> <li>Have <code>.py</code> script saved locally</li> <li>Run required program</li> <li>Use program normally until the need for the script arises</li> <li>Press hotkey that tells Windows to run the python script</li> <li>Close program when the script + my work is done</li> <li>Hotkey should no...
<python><windows><automation><hotkeys>
2023-11-13 07:10:13
1
319
SpectraXCD
77,472,100
1,609,464
How to get Selenium to extract the link for each tweet via clicking "Copy link" on Twitter?
<p>I'm trying to extract the links to each specific tweet on Twitter using Selenium (with Python). E.g., let's say I'm looking at <a href="https://twitter.com/search?q=from%3A%40POTUS&amp;src=typed_query&amp;f=live" rel="nofollow noreferrer">https://twitter.com/search?q=from%3A%40POTUS&amp;src=typed_query&amp;f=live</...
<python><selenium-webdriver><web-scraping><twitter>
2023-11-13 06:41:00
1
1,541
nwly
77,471,991
41,948
how to decide if StreamingResponse was closed in FastAPI/Starlette?
<p>When looping a generator in StreamingResponse() using FastAPI/starlette</p> <p><a href="https://www.starlette.io/responses/#streamingresponse" rel="nofollow noreferrer">https://www.starlette.io/responses/#streamingresponse</a></p> <p>how can we tell if the connection was somehow disconnected, so a event could be fir...
<python><fastapi><starlette><asgi>
2023-11-13 06:11:33
1
11,975
est
77,471,973
2,985,331
Custom classifier won't accept data from test_train_split in sklearn
<p>I am attempting to write a custom classifier for use in a sklearn gridsearchCV pipeline.</p> <p>I've stripped everything back to the bare minimum in the class which currently looks like this:</p> <pre><code>from sklearn.base import BaseEstimator, ClassifierMixin import pandas as pd class DifferentialMethylation(Bas...
<python><scikit-learn><sklearn-pandas>
2023-11-13 06:05:32
1
451
Ben
77,471,965
12,725,674
Iteration in Parsing Script: Value remains the same
<p>I am currently developing a parser that iterates over .txt files containing transcripts of earnings conference calls. The objective is to extract sections spoken by a CEO. The provided code snippet is part of a larger script responsible for extracting various pieces of information, such as the date of the call and t...
<python><regex>
2023-11-13 06:03:14
1
367
xxgaryxx
77,471,934
12,104,604
How to get multiprocessing working in Python with Kivy
<p>I do not understand how to combine multiprocessing with Kivy, a Python GUI library, so please help me on this.</p> <p>Initially, I had created a code using Kivy, a Python GUI library, and threading.Thread, as follows.</p> <pre class="lang-py prettyprint-override"><code>#-*- coding: utf-8 -*- from kivy.lang import B...
<python><kivy>
2023-11-13 05:56:00
1
683
taichi
77,471,818
308,827
Exclude subplots without any data and left-align the rest in relplot
<p>Related to this question: <a href="https://stackoverflow.com/questions/77442845/use-relplot-to-plot-a-pandas-dataframe-leading-to-error">Use relplot to plot a pandas dataframe leading to error</a></p> <p>Data for reproducible example is here:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd d...
<python><pandas><seaborn><relplot>
2023-11-13 05:06:51
2
22,341
user308827
77,471,745
4,451,521
Plot with Xaxis vertical and Yaxis horizontal to the left
<p>How can I use matplotlib in a way that I can get something like this:</p> <p><a href="https://i.sstatic.net/G1exj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/G1exj.png" alt="enter image description here" /></a></p> <p>As you can see X is vertical up and Y is horizontal to the left.</p> <p>(You can...
<python><matplotlib>
2023-11-13 04:35:00
1
10,576
KansaiRobot
77,471,613
1,035,279
When I use redirect_stdout in python 3.11, the terminal width appears to be set to 80. How can I change this value?
<p>For example, when automatically collating arparse help, I'd ideally like to set a specific width:</p> <pre><code>def parse_help(command_list=... width=168): command_list = [] if command_list is ... else command_list s = io.StringIO() with redirect_stdout(s, width=width): try: do_comm...
<python><argparse>
2023-11-13 03:32:58
2
16,671
Paul Whipp
77,471,567
188,331
Evaluate's METEOR Implementation returns 0 score
<p>I have the following codes:</p> <pre><code>import evaluate reference1 = &quot;犯人受到了嚴密的監控。&quot; # Ground Truth hypothesis1 = &quot;犯人受到嚴密監視。&quot; # Translated Sentence meteor = metric_meteor.compute(predictions=[hypothesis1], references=[reference1]) print(&quot;METEOR:&quot;, meteor[&quot;meteor&quot;]) </code></...
<python><meteor><huggingface-evaluate>
2023-11-13 03:11:47
1
54,395
Raptor
77,471,517
11,645,727
Debugger not stopping at breakpoints in VSCode (python code)
<p>When I run python in 1.84.2 vscode, I found that breakpoints did not work. It didn't stop where I interrupted, but stopped where thre was not breakpoint. This problem makes me very anxisous. I can't find a solution to the problem, and if I can't solve it, I would give up vscode, but I don't want to do this. Please h...
<python><visual-studio-code><breakpoints>
2023-11-13 02:45:30
4
455
Min Guo
77,471,459
371,408
OpenAI Whisper segfaulting when running inside Docker container on M1 Mac
<p>I am trying to run Whisper in a Docker container on my M1 MacBook Air. When I run it, it gives a segfault. Any ideas how to debug?</p> <p>The Dockerfile is pretty simple. Relevant excerpt:</p> <pre><code>FROM ubuntu:22.04 # Update base image RUN apt-get update &amp;&amp; \ apt-get upgrade -y &amp;&amp; \ ap...
<python><docker><openai-whisper>
2023-11-13 02:24:29
0
21,479
Zach Rattner
77,471,415
1,942,868
How to check the order of appearance on django test
<p>I use this sentences to check the letters <code>line1</code> and <code>line2</code> appears.</p> <p>self.assertContains(response,&quot;line1&quot;); self.assertContains(response,&quot;line2&quot;);</p> <p>However I want to check the order of appearance.</p> <p>I checked in this page, but can't figure out which I sho...
<python><django><testunit>
2023-11-13 02:05:34
2
12,599
whitebear
77,471,197
16,307,782
Add numpy random values to a Polars dataframe using a column as input to numpy.random?
<p>Let's say I have a dataframe that has a column named <code>mean</code> that I want to use as an input to a random number generator. Coming from R, this is relatively easy to do in a pipeline:</p> <pre class="lang-r prettyprint-override"><code>library(dplyr) tibble(alpha = rnorm(1000), beta = rnorm(1000)) %&g...
<python><dataframe><numpy><python-polars>
2023-11-13 00:20:10
1
372
Mark Rieke
77,471,168
21,305,238
How to know which pyparsing ParserElement created which ParseResults?
<h2>The problem</h2> <p>I have a bunch of <code>Group</code>-ed expressions like these, all of which contribute to the same grammar:</p> <pre class="lang-py prettyprint-override"><code>first_and_operator = Group(Char('ab')('first') + Char('+-')('operator')) full_expression = Group(first_and_operator + Char('cd')('secon...
<python><pyparsing>
2023-11-13 00:04:41
1
12,143
InSync
77,471,038
5,246,226
Pass C++ matrix into Python to use as Numpy array?
<p>I am doing some processing of matrices in C++ that I would like to pass to a Python program/function, which should accept data in the form of a Numpy array, and pass something back to the C++ program. I've looked through the documentation on <a href="https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.htm...
<python><c++><numpy><pybind11>
2023-11-12 23:12:31
0
759
Victor M
77,471,022
1,924,087
PyGame - Draw Line Based on Heading
<p>I'm using <code>pygame.draw.line</code> to draw a line between two coordinates in pixels, the required format of this function is <code>(begin_x,begin_y),(end_x, end_y)</code>.</p> <p>The begining coordinate for this line can be (0,0), and the line must have 100px of entire length. But which will be the ending coord...
<python><math><trigonometry>
2023-11-12 23:05:51
2
681
Ygor Montenegro
77,470,842
3,195,413
tensorflow2 save_model method failing on encoding error
<p>using python 3.9 and tf 2.14, i am able to successfully run through the entire notebook posted here and successfully create the model, and have it make its predictions:</p> <p><a href="https://www.tensorflow.org/tutorials/keras/text_classification" rel="nofollow noreferrer">https://www.tensorflow.org/tutorials/keras...
<python><tensorflow2.0>
2023-11-12 21:59:00
1
599
10mjg
77,470,471
614,963
filtered_df and str in Python
<p>I am new to Python. I'm trying to filter Dataset. The filter seems to work well or I think it does:)</p> <pre><code>valid_Cas = [&quot;yut&quot;, &quot;thj&quot;, &quot;bnm&quot;,&quot;vfd&quot;] filtered_df = df[df['Cas ID'].str[-3:].isin(valid_Cas)] </code></pre> <p>but when a filter more than three letters, it d...
<python><string>
2023-11-12 20:09:48
1
865
user614963
77,470,456
726,730
Qt Designer - Is it possible for QToolBar to have QToolButtons or QMenu as actions?
<p>Is it possible to have QMenu or QToolButton as action for QToolBar in Qt Designer?</p> <p>The only choice is to create actions in Action Center, then add the actions in the QToolBar.</p> <p>I want with some way to have submenu's for some actions.</p> <p>I know (almost) how to do this in code but i don't know how can...
<python><pyqt5><qt-designer>
2023-11-12 20:04:57
0
2,427
Chris P
77,470,446
21,370,869
Python programme executes all lines but does not run any 'subprocess.Popen()' lines
<p>I have simple Firefox add-on that, I am using it to test and discover the capabilities of <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging#exchanging_messages" rel="nofollow noreferrer">Native Messaging</a>, something I recently came across.</p> <p>The add-on side of ...
<javascript><python><subprocess><firefox-addon><firefox-addon-webextensions>
2023-11-12 19:58:43
0
1,757
Ralf_Reddings
77,470,398
201,657
Can I mandate that a function in a base class is always run from a derived class' __init__?
<p>I have an abstract base class <code>BudgetCategories</code> and a class, <code>BudgetCategoriesFromFile</code>, derived from it:</p> <pre class="lang-py prettyprint-override"><code>from abc import ABCMeta import csv class BudgetCategories(metaclass=ABCMeta): def __init__(self) -&gt; None: self._budget_c...
<python>
2023-11-12 19:43:53
2
12,662
jamiet
77,470,014
7,895,542
Python change directory while keeping symlinks in the path
<p>So i have a this path: <code>/nfs/dust/atlas/user/jnitschk/CAF/StatisticTool/Output/frac_100ex_3_smooth_truth</code></p> <p>that i execute a script from and thus get that when i do <code>os.getcwd()</code>.</p> <p>Now i need to change to the following path to execute some subprocesses from:</p> <p><code>/nfs/dust/at...
<python><path>
2023-11-12 17:53:33
1
360
J.N.
77,469,944
616,460
Getting physical dimensions of screen in MacOS
<p>Is it possible to get the physical dimensions (millimeters or otherwise) of a given monitor with Python on macOS?</p> <p>I was looking at <a href="https://developer.apple.com/documentation/appkit/nsscreen" rel="nofollow noreferrer">AppKit's NSScreen</a> but it only gives pixel resolution (via <code>frame</code>) and...
<python><macos><appkit>
2023-11-12 17:32:45
2
40,602
Jason C
77,469,808
11,860,883
vectorized way of checking element existence
<p>I have a pytorch tensor a of floats a, a corresponding pytorch tensor of ints b of the same size as a. I have another tensor of ints c of variable length. I need to multiply the position of a by two if the corresponding element in b has appeared in c.</p> <pre><code>import torch a = torch.tensor([1.0, 2.0, 3.0, 4.0...
<python><pytorch>
2023-11-12 16:56:44
1
361
Adam
77,469,785
1,362,485
Denormalize array of columns into multiple pandas columns
<p>Why column 'x' is always 't2'? I need it to be 't2', 't3', 't4'.... and the result should be 9 rows, not 3.</p> <pre><code>import pandas as pd rows = [{'id': 'x1', 'seq': 0, 'amount': 2000, 'payments': 4, 'dummy': 1 }, {'id': 'x2', 'seq': 0, 'amount': 4000, 'payments': 2, 'dummy': 11 }, {'id': '...
<python><pandas>
2023-11-12 16:52:02
1
1,207
ps0604
77,469,596
9,137,547
Normalize list of floats to probabilities
<p>I have a list of probability weights like <code>weights = [3, 7, 4, 2]</code> and I want to <strong>normalize</strong> it so that <code>sum(weights) == 1</code>.</p> <p>This can be later used for something like &quot;<a href="https://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice">A weighted...
<python><numpy><probability><normalization>
2023-11-12 15:51:01
1
659
Umberto Fontanazza
77,469,419
6,455,731
Scrapy Spider: Stuck with callback not firing
<p>I am trying to scrape a <a href="https://github.com/orgs/COST-ELTeC/repositories" rel="nofollow noreferrer">github repo</a>.</p> <p>I want to extract all XML file urls at level1 of every repo and in the best case also extract information from the XML files.</p> <pre><code>import scrapy from scrapy.crawler import Cra...
<python><scrapy>
2023-11-12 14:57:26
1
964
lupl
77,469,382
201,657
How do I view a polars dataframe without truncating the values?
<p>I have a polars dataframe containing a column called <code>Notes</code> that has long text in it. If I simply output that dataframe (i.e. execute <code>df</code>) in a Jupyter notebook then the values therein get truncated</p> <p><a href="https://i.sstatic.net/82fv6.png" rel="noreferrer"><img src="https://i.sstatic....
<python><dataframe><python-polars>
2023-11-12 14:45:01
2
12,662
jamiet
77,469,293
974,733
Why does my Python CLI project structure result in ModuleNotFoundErrors?
<p>I have a Python application used as a CLI, let's call it <code>foo</code>. My problem is that the project works if I do <code>pip install .</code> in the root of my repository, and then execute <code>foo</code> in the terminal.<br /> But if I try to run the source code directly with the Python interpreter, then the ...
<python>
2023-11-12 14:19:45
1
8,115
Mark Vincze
77,469,134
17,487,457
StackingClassifier with base-models trained on feature subsets
<p>I can best describe my goal using a synthetic dataset. Suppose I have the following:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeCl...
<python><machine-learning><scikit-learn><classification><ensemble-learning>
2023-11-12 13:36:50
2
305
Amina Umar
77,469,097
6,907,703
How can I process a pdf using OpenAI's APIs (GPTs)?
<p>The web interface for ChatGPT has an easy pdf upload. <strong>Is there an API from openAI that can receive pdfs?</strong></p> <p>I know there are 3rd party libraries that can read pdf but given there are images and other important information in a pdf, it might be better if a model like GPT 4 Turbo was fed the actua...
<python><machine-learning><pdf><openai-api><chat-gpt-4>
2023-11-12 13:25:44
7
1,281
Muhammad Mubashirullah Durrani
77,469,094
1,550,974
ImportError: cannot import name 'ModelField' from 'pydantic.fields'
<p>I clone <a href="https://huggingface.co/spaces/os1187/docquery" rel="nofollow noreferrer">this huggingface</a> and tested on my app. But, I got this error.</p> <pre><code>===== Application Startup at 2023-11-12 13:13:59 ===== The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cac...
<python><pydantic><huggingface>
2023-11-12 13:24:43
1
6,125
Khant Thu Linn
77,469,040
8,120,580
Python dataclass automate ID incrementation in abstract class
<p>I want to create a unique ID incrementation for my Python subclasses using the abstract method, but I don't know how to separate each subclass's set of ID values. Here is my code:</p> <pre><code>from dataclasses import dataclass, field from itertools import count @dataclass class Basic: identifier: int = field...
<python><python-dataclasses>
2023-11-12 13:09:13
1
1,385
Alex
77,468,918
20,878,436
WinError 10060 Connection Timeout Error When Downloading 'punkt' in NLTK
<p>I'm experiencing an issue with the NLTK library in Python, specifically when trying to download the 'punkt' tokenizer models. Here's the error message I receive:</p> <p><strong>Context:</strong> I'm attempting to download the <code>punkt</code> package using the following code:</p> <pre class="lang-py prettyprint-ov...
<python><python-3.x><jupyter-notebook><nltk>
2023-11-12 12:31:09
2
368
Shounak Das
77,468,917
2,881,414
What is a reliable way to specify a minimum pip version?
<p>What is a reliable way to specify the minimum required <code>pip</code> version in a project that uses <code>pyproject.toml</code>?</p> <p>Is it:</p> <pre class="lang-ini prettyprint-override"><code>[build-system] requires = [&quot;setuptools&gt;=64.0&quot;, &quot;pip&gt;=x.y&quot;] build-backend = &quot;setuptools....
<python><pip><pyproject.toml>
2023-11-12 12:30:23
1
17,530
Bastian Venthur
77,468,647
14,823,254
the script for deleting files and folders consumes a lot of memory resources
<p>I wrote a script to delete files and folders, but it eats up all the RAM, eats up a lot of memory resources , a folder that is parsed 1tb and new files are being written to it in parallel. What can I do to make the script eat not so many resources? there are 48 GB of RAM on the server ( when the script does not work...
<python><python-3.x>
2023-11-12 10:58:36
0
341
Iceforest
77,468,274
17,569,967
How to make mutation which is inversion of one of the solution's genes when solutions are bit arrays
<p>That's what I have so far. As I see from the output, my parameters are not enough to constraint mutation to my needs. Sometimes no one gene is changed, sometimes more than one.</p> <pre><code>import pygad import numpy as np def divider(ga_instance): return np.max(np.sum(ga_instance.population, axis=1)) def o...
<python><pygad>
2023-11-12 08:37:59
1
412
Intolighter
77,468,234
12,471,420
NumPy - Check for "5 in a row" pattern in a 2d array
<p>I am trying to write a function that checks if there is at least one of &quot;five in a row&quot; of a number in a 2d array, in row, column, and diagonal directions. The array to check can be any square matrix with size &gt;= 5, but I'll most likely be working with 7x7 ones.</p> <p>For example, the following matrix ...
<python><algorithm><numpy>
2023-11-12 08:17:46
2
365
goldenotaste
77,468,224
3,322,273
Allowing multiple requests under the same socket connection with python socketserver
<p>I started a TCP server in Python and tried to send to it multiple requests using a single socket connection:</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) &gt;&gt;&gt; s.connect(('127.0.0.1', 4444)) &gt;&gt;&gt; message = b'hi' &gt;&gt;&gt; s.sendall(mes...
<python><tcpserver><socketserver>
2023-11-12 08:15:25
1
12,360
SomethingSomething
77,468,212
2,660,756
Custom error messages from queries based on data in the collection in mongodb
<p>I'm wondering if there's a way to return custom errors and/or messages from queries depending on the data in the dataset in mongodb.</p> <p>For example and clarification, consider that I have the following collection, named <code>users</code>, with data in this format:</p> <pre><code>{ &quot;_id&quot;: &quot;65...
<python><mongodb><pymongo>
2023-11-12 08:12:47
0
637
Loay
77,468,154
1,595,350
How to Chat with my Data in Python using Microsoft Azure OpenAI and Azure Cogintive Search
<p>I have written code that extracts text from a PDF document and converts it into vectors using the text-embeddings-ada-002 model from Azure OpenAI. These vectors are then stored in a Microsoft Azure Cognitive Search Index and can be queried. However, I now want to use Azure OpenAI to interact with this data and retri...
<python><azure><azure-cognitive-search><azure-openai>
2023-11-12 07:46:36
1
4,326
STORM
77,468,134
4,769,404
Truly portable executables written in python in 2023
<p>I've recently spent a lot of time figuring out how to distribute tools written in Python as standalone, self-contained executables, that will works on most of the linux distribution without special environment (including python itself). Decided to write this post to discuss my approach.</p> <p>Here are a few simple ...
<python><linux><packaging><portability><nuitka>
2023-11-12 07:41:16
0
690
Arseniy
77,467,788
22,213,065
Keep second regex lines in first regex lines matches
<p>I have high number of txt list files in <code>E:\Desktop\Linux_distro\asliiiii</code> directory that following is a sample of one of my files:</p> <pre><code>95 ROSA 139 96 Chakra 137 97 AV Linux 135 98 LibreELEC 134 99 Simplicity 131 100 Kodachi 130 20200301020449 79776361952441 </code></pre> <p>Now I need a script...
<python><regex>
2023-11-12 04:59:06
3
781
Pubg Mobile
77,467,787
806,160
why Changing in numpy array change tensor that converted from numpy?
<p>When I convert a numpy array to tensor and change the numpy in differnet ways some change the tensor and some not. it is sample:</p> <p>in this code:</p> <pre><code>array = np.arange(1., 8.) tensor = torch.from_numpy(array) array, tensor </code></pre> <p>the answer is :</p> <pre><code>(array([1., 2., 3., 4., 5., 6.,...
<python><arrays><numpy><pytorch><converters>
2023-11-12 04:57:19
1
1,423
Tavakoli
77,467,685
10,200,497
finding the first value of last streak in a column
<p>This is my dataframe:</p> <pre><code>df = pd.DataFrame({'a': [1, 0, 0, 1, 0, -1, -1, -1, 0, -1, -1, -1]}) </code></pre> <p>And this is the outcome that I want:</p> <pre><code> a b 0 1 NaN 1 0 NaN 2 0 NaN 3 1 NaN 4 0 NaN 5 -1 NaN 6 -1 NaN 7 -1 NaN 8 0 NaN 9 -1 x 10 -1 NaN 11 -1 NaN <...
<python><pandas>
2023-11-12 03:52:50
1
2,679
AmirX
77,467,422
13,086,128
RuntimeWarning: overflow encountered in scalar negative
<p>I am getting this warning when I upgrade my numpy from <code>1.23.3</code> to <code>1.25.0</code></p> <pre><code>#For 1.23.3 version import numpy as np x = np.uint64(0xffffffff) print(-x) #output 18446744069414584321 </code></pre> <hr /> <pre><code>#For 1.25.0 version import numpy as np x = np.uint64(0xffffffff) ...
<python><numpy>
2023-11-12 01:21:50
2
30,560
Talha Tayyab
77,467,361
14,256,643
Understanding and Fixing User Permissions Logic in Django
<p>I know this might be a silly question but please don't laugh at me. I am struggling to understand this simple logic. I am not understating why this logic is not working where it means if request.user is not the owner of the object or the user is not an admin user. The first part of this logic works to prevent other...
<python><python-3.x><django>
2023-11-12 00:44:57
2
1,647
boyenec
77,467,308
1,432,980
tree view scrollbars do not work properly
<p>I am trying to create a <code>tree view</code> with horizontal and vertical scrollbars. My code looks like this (I added some gibberish to build deep hierarchy).</p> <pre><code>import tkinter as tk from tkinter import ttk app = tk.Tk() app.geometry(&quot;400x400&quot;) app.title(&quot;Basic viewer&quot;) main_wind...
<python><tkinter>
2023-11-12 00:13:17
1
13,485
lapots
77,467,162
9,983,652
ImportError: cannot import name 'KoalasFrame' from 'databricks.koalas'
<p>I got below warning and error</p> <pre><code>from databricks.koalas import KoalasFrame WARNING:root:Found pyspark version &quot;3.5.0&quot; installed. The pyspark version 3.2 and above has a built-in &quot;pandas APIs on Spark&quot; module ported from Koalas. Try `import pyspark.pandas as ps` instead. WARNING:root...
<python><python-3.x><apache-spark><spark-koalas>
2023-11-11 23:01:40
2
4,338
roudan
77,467,082
9,983,652
AttributeError: module 'dask' has no attribute 'set_options' after installing dask with conda
<p>I am using annaconda and I just installed dask using below</p> <p><a href="https://anaconda.org/conda-forge/dask" rel="nofollow noreferrer">https://anaconda.org/conda-forge/dask</a></p> <pre><code>conda install -c conda-forge dask </code></pre> <p>I can use read_csv() and no error, however, I got this error . I am ...
<python><dask><dask-distributed>
2023-11-11 22:27:50
1
4,338
roudan
77,466,928
5,032,387
LLM in LLMChain ignores prompt
<p>I'm getting an incorrect output from an LLMChain that uses a prompt that contains a system and human messages. Can't figure out why. I download the gpt4all-falcon-q4_0 model from <a href="https://gpt4all.io/index.html" rel="nofollow noreferrer">here</a> to my machine.</p> <pre class="lang-py prettyprint-override">...
<python><langchain><gpt4all>
2023-11-11 21:37:25
1
3,080
matsuo_basho
77,466,728
12,904,808
mypy django models typehint
<p>I integrated mypy into my project and would like to type my django models, how would I enable the following conversions? ForeignKey to the actual model, charField and textField to str, DecimalField to Decimal...</p> <pre><code>class mymodel(models.Model): address: str = models.CharField(max_length=100) ...
<python><django><django-models><mypy>
2023-11-11 20:27:30
0
302
swaffelay
77,466,604
8,690,357
Movie cast with characters in Django
<p>So, I'm doing the classical movie app in Django (I'm loving the framework!) and I feel like I hit a stump.</p> <p>So, I have my Movie model:</p> <pre><code>class Movie(models.Model): TitlePRT = models.CharField(max_length=100) TitleORG = models.CharField(max_length=100) TitleAlt = models.CharField(max_...
<python><django><django-models><django-forms>
2023-11-11 19:45:55
1
397
O Tal Antiquado
77,466,563
3,238,679
How to implement multi-band-pass filter with scipy.signal.butter
<p>Based on the band-pass filter <a href="https://%20https://stackoverflow.com/questions/12093594/how-to-implement-band-pass-butterworth-filter-with-scipy-signal-butter" rel="nofollow noreferrer">here</a>, I am trying to make a multi-band filter using the code bellow. However, the filtered signal is close to zero which...
<python><scipy><signal-processing><digital-filter>
2023-11-11 19:34:16
2
1,041
Thoth
77,466,494
21,370,869
stdin is not being saved to file
<p>I am trying to get a better understanding how stdin works and how to specifically work with it in Python.</p> <p>I am trying to save whatever is received from stdin to a file. The file should have two lines</p> <ul> <li>Line one should be the letter count of the string</li> <li>Line two should be the string itself</...
<python><stdin>
2023-11-11 19:14:49
2
1,757
Ralf_Reddings
77,466,456
1,595,350
AttributeError: 'str' object has no attribute 'get_token' in Python when using Azure Cognitive Search Vector Search
<p>I am trying to do a Vector Search with Azure Cognitive Search in Python. This is my code:</p> <pre><code>query = &quot;What are the advantages of an open-source ai model?&quot; search_client = SearchClient(AZURE_COGNITIVE_SEARCH_SERVICE_ENDPOINT, AZURE_COGNITIVE_SEARCH_INDEX_NAME, credential=AZURE_COGNITIVE_SEARCH_A...
<python><azure><azure-cognitive-search><vector-search>
2023-11-11 19:01:43
1
4,326
STORM
77,466,432
2,304,735
How to convert string variable to float variable JSON file?
<p>I am trying to read string from JSON file and convert it to float. Other data in the file are integers, but this specific data is string.</p> <p>JSON File:</p> <pre><code>{ &quot;Valuation&quot;: { &quot;TrailingPE&quot;: 29.4035, &quot;ForwardPE&quot;: 28.66, &quot;PriceSalesTTM&quot;: 5.5067, &quot...
<python><json><python-3.x>
2023-11-11 18:55:33
1
515
Mahmoud Abdel-Rahman
77,466,107
9,195,104
Interactive server-driven Flask SQL table with option to download filtered data in .csv
<p>I am trying to download a SQLite queried table as .csv using <code>Flask</code>, <code>SQLAlchemy</code> (not <code>Flask-SQLAlchemy</code>) and <code>DataTables</code> (plug-in for jQuery) with the server-side processing option.</p> <p>Basically, I have a query that connects to a SQLite dataset, imports the data an...
<python><flask><sqlalchemy><datatables>
2023-11-11 17:27:21
1
421
roboes
77,465,672
2,589,895
Deploy python app without any web server/ framework to azure app service linux
<p>I have a custom Linux app where I am not using any framework. It is a simple app with some module which does some scheduled job. to run on local , i am using <code>python main.py arg1 arg2</code>. That's it it will use <code>schedule</code> package and schedule jobs. I do have <code>requirements.txt</code>.</p> <p>N...
<python><azure><github-actions>
2023-11-11 15:22:32
1
2,580
Mahajan344
77,465,549
203,204
ValueError: "time data %r does not match format %r"
<p>I'm trying to parse time using <code>strptime</code>:</p> <pre><code>t = datetime.strptime('2024-08-21T11:00:00 EDT', '%Y-%m-%dT%H:%M:%S %Z') </code></pre> <p>This code works for me in GMT+4, but it fails in GMT-9:</p> <pre><code>ValueError: time data '2024-08-21T11:00:00 EDT' does not match format '%Y-%m-%dT%H:%M:%...
<python><datetime><timezone><strptime>
2023-11-11 14:48:40
2
12,842
Anthony
77,465,479
6,013,016
Pygame rectangle fill with color and border with different colors
<p>I want to draw a rectangle filled with one color and border with another color. Something like this:</p> <p><a href="https://i.sstatic.net/emYwM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/emYwM.png" alt="enter image description here" /></a></p> <p>And I can draw two rectangles, one is filled with...
<python><pygame>
2023-11-11 14:33:05
2
5,926
Scott
77,465,362
14,471,688
How to access the value of a dictionary faster from a list of arrays in python?
<p>I was wondering how can I access the value of a dictionary rapidly from a list of arrays.</p> <p>Here is my toy example:</p> <pre><code>my_list = [np.array([ 1, 2, 3, 4, 5, 6, 8, 9, 10]), np.array([ 1, 3, 5, 6, 7, 10]), np.array([ 1, 2, 3, 4, 6, 8, 9, 10]), np.array([ 1, 3, 4, 7, 15]), np.array([...
<python><arrays><numpy><dictionary>
2023-11-11 14:00:34
1
381
Erwin
77,465,301
1,595,350
Trying adding embeddings in Azure Cognitive Search leads to error "The property 'content' does not exist on type 'search.documentFields'."
<p>I am extracting text from pdf documents and load it to Azure Cognitive Search for a RAG approach. Unfortunately this does not work. I am receiving the error message</p> <pre><code>HttpResponseError: () The request is invalid. Details: The property 'content' does not exist on type 'search.documentFields'. Make sure t...
<python><azure><azure-cognitive-search><langchain><azure-openai>
2023-11-11 13:44:10
1
4,326
STORM
77,465,100
3,156,300
Mirror Selected QGraphicsItems based on boundingRect center
<p>For the life of me I can not seem to figure out how to mirror the selected QGraphicsItems based on their selected center? Each attempt I've tried makes the items eventually shoot off screen. I've recreated this same setup in 3d applications and got it work but i'm missing something and can't figure out it. Any help ...
<python><pyside><qgraphicsview>
2023-11-11 12:34:54
2
6,178
JokerMartini
77,465,090
13,176,896
How to increase image resolution in openpyxl?
<p>I have some high-resolution images, but when adding them to excel using openpyxl, their resolutions becomes low. <br> My example code is here.</p> <pre><code>wb = openpyxl.Workbook() ws = wb.active img = openpyxl.drawing.image.Image('high_resolution_image.png') img.anchor = AbsoluteAnchor(pos=position, ext=size) ws...
<python><excel><openpyxl><resolution>
2023-11-11 12:31:39
0
2,642
Gilseung Ahn
77,465,049
3,259,222
How to add new value for a given dimension and coordinate in xarray?
<p>I have data with the following xarray DataSet representation:</p> <pre><code>df = pd.DataFrame({ 'var': np.random.rand(16), 'country': 4*['UK'] + 4*['US'] + 4*['FR'] + 4*['DE'], 'time_delta': 4*list(pd.timedelta_range( start='30D', periods=4, freq='30D' )), }) ds = df.set_ind...
<python><pandas><python-xarray>
2023-11-11 12:16:19
1
431
Konstantin
77,464,627
8,844,970
SQLAlchemy using both primaryjoin and secondaryjoin with association table
<p>I am trying to create a database for genomics. I have two tables, <code>Gene</code> and <code>Mutation</code> and I am trying to join them together. The genes are related to mutations if are on the same chromosome and their positions overlap. I tried using association table to try to connect them and get a join stat...
<python><sqlalchemy>
2023-11-11 09:58:45
0
369
spo
77,464,554
1,595,350
Why am i receiving "AttributeError: 'str' object has no attribute 'page_content'" when trying to add my embeddings to Azure Cognitive Search
<p>I am extracting text from pdf documents and load it to Azure Cognitive Search for a RAG approach. Unfortunately this does not work. I am receiving the error message</p> <blockquote> <p>AttributeError: 'str' object has no attribute 'page_content'</p> </blockquote> <p>What I want to do is</p> <ol> <li>Extract text fro...
<python><azure-cognitive-services><azure-cognitive-search><langchain><azure-openai>
2023-11-11 09:33:02
1
4,326
STORM
77,464,520
4,230,643
Can anyone explain when two imports of the same Python module can result in two different module objects?
<p>Last year, I wrote the following three modules in Python 3.7.2:</p> <pre class="lang-py prettyprint-override"><code># my_module.py my_counter = 0 ...
<python><python-import>
2023-11-11 09:20:33
0
2,681
Throw Away Account
77,464,293
11,353,092
Is there a way to limit Python's keyboard.add_hotkey() to trigger only once per keystroke?
<pre><code>import keyboard def on_c_pressed(): print(&quot;C key was pressed&quot;) keyboard.add_hotkey('c', on_c_pressed) </code></pre> <p>Current situation is that it fires rapidly as the keystroke is actuated and being released.</p> <p>One solution is to keep track of a global variable flag and have on_c_presse...
<python><keyboard-events><keystroke><python-keyboard>
2023-11-11 07:54:08
1
487
Anonymous
77,463,678
992,421
removing , and converting to int
<p>I am banging my head to convert the following spark RDD data using code</p> <pre><code>[('4', ('1', '2')), ('10', ('5',)), ('3', ('2',)), ('6', ('2', '5')), ('7', ('2', '5')), ('1', None), ('8', ('2', '5')), ('9', ('2', '5')), ('2', ('3',)), ('5', ('4', '2', '6')), ('11', ('5',))] def adjDang(line, tc): node, e...
<python><apache-spark><pyspark><rdd>
2023-11-11 02:17:26
1
850
Ram
77,463,403
21,370,869
My simple python program does not execute the last line
<p>I have a simple Firefox extension, I have pretty much figured out the Firefox side of things (JavaScript, DOM and starting the Python program).</p> <p>To explain how everything is supposed to work:</p> <ol> <li>A event occurs in the browser</li> <li>Firefox launches the Python program on the local system (achieved w...
<python><firefox-addon><stdin>
2023-11-11 00:03:08
0
1,757
Ralf_Reddings
77,463,264
7,530,306
tomli-w, adding arrays from a python script
<p>I have a toml file like this</p> <pre><code>[[fruits]] fruit_property =x [[fruits]] fruit_property =x [[fruits]] fruit_property =x </code></pre> <p>And I want to encode this from a python script. So far in python i have done</p> <pre><code>fruits= [ {'fruit_property':x},{'fruit_property':y}, {'fruit_property':z}...
<python><toml>
2023-11-10 23:11:55
2
665
sf8193
77,463,217
688,563
python pyroute2 move WiFi interface into network namespace
<p>I want to use python pyroute2 to discover a USB WiFi dongle on Linux and move it into a network namespace.</p> <p>I can do this with an ethernet interface but I understand that I have to use the PHY to move it with pyroute2 if it is a wifi interface. I checked the docs and do not see an example for how to do this.</...
<python><python-3.x><linux><namespaces><pyroute2>
2023-11-10 22:56:24
0
368
PhilBot
77,463,187
61,624
Show the stack trace from a stuck v2 Python.exe application in Windows
<p>I have the same question as <a href="https://stackoverflow.com/questions/132058/showing-the-stack-trace-from-a-running-python-application">Showing the stack trace from a running Python application</a> with two differences: I'm looking for answers that work on Windows 10 and Python v2.</p> <blockquote> <p>I have this...
<python><windows><python-2.7>
2023-11-10 22:46:05
1
68,373
Daniel Kaplan
77,463,153
6,396,569
Why does Tkinter lag only the first time a listbox is populated with a large number of lines?
<p>My application, written for Python 3.12.0, loads a large number (around 6,000+ lines) of text lines into a Tkinter Listbox like this:</p> <pre><code> self.listbox.delete(0,tk.END) self.listbox.insert(tk.END,*filtered_files) </code></pre> <p>Where <code>filtered_files</code> is a List of textual file names. I h...
<python><python-3.x><tkinter><listbox>
2023-11-10 22:33:10
0
2,567
the_endian
77,463,100
4,109,398
formula for nth derivative in sympy
<p>I am playing with the <strong>sympy</strong> for a while. I want sympy to derive me a formula of nth derivative for specific function. I tried:</p> <pre class="lang-py prettyprint-override"><code>import sympy as sp x = sp.symbols('x') n = sp.Symbol('n',integer=True) f = x**n dnf = f.diff((x,n)) # n times derivative ...
<python><sympy>
2023-11-10 22:17:25
1
412
lukas kiss
77,462,887
3,611,164
Order plotly figure by CategoricalDtype order
<p>The goal is to visualize boxplots for each group in order. Group is of<code>pd.CategoricalDtype</code> and ordered. I do not manage to get plotly to respect the order. Instead, it only sorts alphabetically.</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import numpy as np import plotly.expre...
<python><pandas><plotly><categorical-data>
2023-11-10 21:18:46
1
366
Fabitosh
77,462,744
6,458,245
Scikit Kmeans tutorial, n_runs and n_init different purpose?
<p><a href="https://scikit-learn.org/stable/auto_examples/text/plot_document_clustering.html" rel="nofollow noreferrer">https://scikit-learn.org/stable/auto_examples/text/plot_document_clustering.html</a></p> <p>In the above documentation, we are running KMeans. The KMeans class has an n_init parameter like so:</p> <pr...
<python><machine-learning><scikit-learn>
2023-11-10 20:40:45
0
2,356
JobHunter69
77,462,722
10,461,632
Passing **kwargs to function results in `Unexpected keyword argument` in flask app, but not test script
<p>I'm getting an unexpected keyword argument in my flask app. When I execute the same functions in a test python file, I don't get the <code>TypeError</code>.</p> <p>In my flask app, I have a worker class and a function:</p> <pre><code>import concurrent.futures as cf class Worker: &quot;&quot;&quot;Class for mul...
<python><flask>
2023-11-10 20:34:26
2
788
Simon1
77,462,367
10,721,627
How to create a persistent volume claim in the local Minikube cluster?
<p>I have installed Docker Desktop, Minikube, and Kubernetes (K8s) command line tools on Windows 10 and I am using Git bash. I created a FastAPI web service that logs some information. This is the content of the <code>requirements.txt</code> file:</p> <pre><code>fastapi[all] </code></pre> <p>And this is the content of ...
<python><docker><kubernetes><minikube>
2023-11-10 19:16:45
1
2,482
Péter Szilvási
77,462,354
1,100,107
Get the matrix-vector representation of a set of symbolic linear inequalities
<p>With Sympy, it is possible to define symbolic linear inequalities, like:</p> <p><a href="https://i.sstatic.net/LJ628.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LJ628.png" alt="enter image description here" /></a></p> <p>This system is equivalent to:</p> <p><a href="https://i.sstatic.net/Wgq7k.png...
<python><sympy>
2023-11-10 19:13:37
1
85,219
Stéphane Laurent
77,462,065
11,584,105
ValueError: could not broadcast input array from shape (3024,3024,3) into shape (3024,3024)
<p>I have this code which works fine:</p> <pre class="lang-py prettyprint-override"><code>import cv2 import matplotlib.pyplot as plt import matplotlib.image as mpimg from matplotlib import rcParams import numpy as np import os from PIL import Image from segment_anything import sam_model_registry, SamAutomaticMaskGenera...
<python><numpy><python-imaging-library>
2023-11-10 18:12:05
1
1,922
Mr. Robot
77,462,042
4,398,966
Python how to cast tuple to list and apply dot notation
<p>Why does:</p> <pre><code>x = (5,4,3) y = list(x) y.sort() </code></pre> <p>work, but</p> <pre><code>x = (5,4,3) y = list(x).sort() </code></pre> <p>not work?</p>
<python>
2023-11-10 18:07:36
3
15,782
DCR
77,461,972
754,136
Multi-indexing with tuples
<p>I have a multi-dimensional <code>np.array</code>. I know the shape of the first N dimension and of the last M dimensions. E.g.,</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; n = (3,4,5) &gt;&gt;&gt; m = (6,) &gt;&gt;&gt; a = np.ones(n + m) &gt;&gt;&gt; a.shape (3, 4, 5, 6) </code></pre> <p>Using t...
<python><numpy><indexing><multi-index>
2023-11-10 17:53:18
4
5,474
Simon
77,461,832
17,561,414
Autoloader: pass the folder names in the data source path with file notification
<p>Im using the Autolaoder to laod data incrementally and I have <strong>enabled the file notification services</strong>.</p> <p>My problem is that the logic I want to include while passing the the datasource path if its against the file notification logic or no.</p> <p>Everyday we receive the data in lake as new folde...
<python><azure><apache-spark-sql><azure-databricks><databricks-autoloader>
2023-11-10 17:28:47
1
735
Greencolor
77,461,757
610,569
Chomping left, right string by whitespace to iterate regex matches
<p>The goal is to extract the matching &quot;words&quot; (bounded by <code>\b|$|\s</code>), given the difflib <code>SequenceMatcher.get_matching_blocks()</code> output, e.g. given:</p> <blockquote> <p>s1 = &quot;HYC00 Schulrucksack Damen, Causal Travel Schultaschen 14 Zoll Laptop Rucksack für Mädchen im Teenageralter L...
<python><string><substring><difflib>
2023-11-10 17:14:40
1
123,325
alvas
77,461,668
2,297,965
Add key to dictionary within list of dictionaries based on value of another dictionary key
<p>I have a dictionary within a list of dictionaries that looks like this:</p> <pre><code>input = [{'Clause':'Text that describes clause 1', 'Source':'pdf_file', 'additional_info': {'State_Index':0, 'City_Index':0, 'Population':100}}, {'Clause':'Text that describes clause 2', 'Source':'pdf_file', 'additional_in...
<python><dictionary>
2023-11-10 16:57:31
1
484
coderX
77,461,573
6,077,457
Attribut error when using contextvar in python 3.10
<p>When running this code below I got an</p> <blockquote> <p>AttributError: <code>__enter__</code></p> </blockquote> <p>I looked around with no success.</p> <pre><code>import contextvars # Création d'une variable de contexte user_context = contextvars.ContextVar(&quot;user&quot;) # Définition de la valeur de la varia...
<python><python-contextvars>
2023-11-10 16:38:40
1
1,085
Herve Meftah
77,461,452
12,415,855
Getting no result when parsing a url with request and bs4?
<p>i try to collect some informations from a site using the attached code:</p> <pre><code>import time from bs4 import BeautifulSoup import requests if __name__ == '__main__': url = &quot;https://www.bobvila.com/articles/post-sitemap12.xml/&quot; page = requests.get(url) time.sleep(3) soup = BeautifulSoup ...
<python><python-requests>
2023-11-10 16:20:20
2
1,515
Rapid1898
77,461,362
5,213,015
Django Rest - Redirect Password Form?
<p>I recently upgraded to Django 4.0 and upgraded <code>django-allauth</code> with alongside <code>django-rest-auth</code>.</p> <p>When a user fills out the password reset form under <code>http://localhost:8000/api/dj-rest-auth/password/reset/</code> they get a link in the console that goes to: <code>http://localhost:8...
<python><django><django-rest-framework><django-serializer><django-allauth>
2023-11-10 16:03:25
1
419
spidey677
77,461,324
3,737,186
Combination of logging.config.dictConfig(logger_config) and logging.getLogger(__name__) not working
<p>To have all logs below level ERROR written to STDOUT I have tried to use a logger configuration from this <a href="https://stackoverflow.com/a/53257669/3737186">answer</a>:</p> <pre><code>class _ExcludeErrorsFilter(logging.Filter): def filter(self, record): &quot;&quot;&quot;Only lets through log message...
<python><logging>
2023-11-10 15:58:29
1
3,508
Sjoerd222888
77,461,319
5,423,080
Refactoring if statement in nested for loops
<p>I have source code like this one:</p> <pre><code>test_dict = {&quot;a&quot;: [1, 2, 3], &quot;b&quot;: [4, 5, 6]} for k, v in test_dict.items(): # something else... for i in v: if k == &quot;a&quot;: x = 100 y = i else: x = i y = 100 ...
<python><algorithm>
2023-11-10 15:58:03
4
412
cicciodevoto
77,461,291
19,694,624
FastAPI 422 Unprocessable Entity POST
<p>I have a FastAPI app with a POST method and I am trying to send a relatively large string with many words. Basically, it's a ChatGPT prompt with some text that needs to be rewritten by ChatGPT. The problem is when I send this text, I get the error:</p> <blockquote> <p>422 Unprocessable Entity</p> </blockquote> <p>Ho...
<python><python-3.x><rest><fastapi>
2023-11-10 15:53:32
1
303
syrok
77,461,286
9,157
why is GeneratorExit raised by this combination of yield & exception suppressing ContextDecorator?
<p>My goal is that instead of writing</p> <pre class="lang-py prettyprint-override"><code>for item in items: with MyCD(): ... # processing logic </code></pre> <p>I would like to have a single line</p> <pre class="lang-py prettyprint-override"><code> for item in MyCD.yield_each_item_wrapped(items): ...
<python><generator><yield><contextmanager>
2023-11-10 15:52:34
0
1,662
zsepi
77,461,175
945,511
transform json to polars dataframe
<p>i have the following json file and i would like to transform to a dataframe Polars. How can I use the pl.read_json function that have schema attribute?</p> <pre><code> { &quot;data&quot;: { &quot;names&quot;: [ &quot;A&quot;, &quot;B&quot;, &quot...
<python><json><dataframe><python-polars>
2023-11-10 15:35:48
1
693
Carlitos Overflow
77,461,174
2,386,605
How to build an asynchronous generator?
<p>When I run the code</p> <pre><code>async def main(*args, **kwargs): await sub_process1() async def sub_process1(): iter = await sub_process2() for i in iter: yield i async def sub_process2(): return [1, 2, 3] </code></pre> <p>I get</p> <pre><code> async def main(*args, **kwargs): &gt; ...
<python><python-3.x><asynchronous><async-await><generator>
2023-11-10 15:35:45
1
879
tobias
77,461,066
5,896,319
How to handle wide tables in pylatex?
<p>I want to generate a PDF using Pylatex. I can handle long table problems but I still have a wide table problem. I'm using the A4 format because it should be printable. I do not want to rotate table but I can use another solution. Do you have any recommendations for that? Here is my code block:</p> <pre><code>model =...
<python><flask><pylatex>
2023-11-10 15:20:17
1
680
edche
77,461,046
3,608,247
Working with multiple Python versions **including development header files**?
<p>I develop Python application with support for different Python versions. I use <code>pyenv</code> to have multiple Python versions on my system (Linux, if that matters) and to switch between them.</p> <p>Now I also need to build Python packages with extensions, as not all of them yet publish wheels for the recent Py...
<python><packaging><multiple-versions>
2023-11-10 15:17:46
1
2,627
Konstantin Shemyak