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,855,653
1,167,359
Automate a running Visual Studio instance using COM to start debugging
<p>How do I use COM automation to &quot;Start Debugging&quot; and &quot;Toggle Breakpoint&quot; in Microsoft Visual Studio Community 2022 (64-bit) Version 17.3.6?</p> <p><a href="https://i.sstatic.net/waM9m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/waM9m.png" alt="enter image description here" /></...
<python><visual-studio><com>
2024-01-21 16:20:36
1
874
Adamarla
77,855,632
10,975,692
fastAPI Depends does not resolve coroutine dependency when @alru_cache is used
<p>Let's say I have a class <code>Foo</code> that need a running event loop when the constructor is called. I want to use the <a href="https://fastapi.tiangolo.com/tutorial/dependencies/" rel="nofollow noreferrer">dependency injection system of fastAPI</a> to provide the same instance of the <code>Foo</code> class to m...
<python><python-asyncio><fastapi>
2024-01-21 16:16:00
3
1,500
DarkMath
77,855,437
525,865
a bs4 script gives back a empty list
<p>I have a list with around 50 entries from centers in Germany. These centers are public institutions and are close to the economy. I want to create a list with all the centers _categories</p> <pre><code>Industry sectors: Location: Contact person: </code></pre> <p>The data - they can be found here on the overview ...
<python><web-scraping><beautifulsoup>
2024-01-21 15:23:01
1
1,223
zero
77,855,188
900,394
How to set up aws s3 with Heroku?
<p>I followed <a href="https://devcenter.heroku.com/articles/s3" rel="nofollow noreferrer">this tutorial</a> to link my aws s3 bucket with my Heroku app.</p> <p>In my s3 bucket I have a zip file called <code>model.zip</code>. I need to use this model in my app (Python). So after linking the bucket successfully accordin...
<python><amazon-s3><heroku>
2024-01-21 14:21:17
1
5,382
Alaa M.
77,855,169
12,698,762
JAX python C callbacks
<p>Numba allows to create C-callbacks directly in python with the @cfunc-decorator ( <a href="https://numba.pydata.org/numba-doc/0.42.0/user/cfunc.html" rel="nofollow noreferrer">https://numba.pydata.org/numba-doc/0.42.0/user/cfunc.html</a> ):</p> <pre><code>@cfunc(&quot;float64(float64)&quot;) def square(x): retu...
<python><numba><jax>
2024-01-21 14:15:26
1
905
Adam
77,854,931
3,285,115
How (improve) updating multiple columns of a pandas dataframe, when the columns are datetime?
<p>I have a DataFrame that has columns as datetime objects, and I would like to update specific values for a specific index based on a list of <em>days</em>.</p> <p>Here is an MRE that works:</p> <pre><code>import pandas as pd start, stop = &quot;2023-12-01&quot;, &quot;2023-12-31&quot; dates: pd.Index = pd.date_rang...
<python><pandas>
2024-01-21 13:08:10
1
3,288
erasmortg
77,854,912
5,741,205
How to install dependencies that are installed in a tox-docker container, but NOT locally?
<p>I'd like to execute unit test (configured in <code>tox.ini</code>) in a docker container using <a href="https://github.com/tox-dev/tox-docker" rel="nofollow noreferrer">tox-docker</a> plugin. The idea behind it is to be able run unit tests, that require <code>cuda-python</code> module, on a MacBook with Apple M2 Pro...
<python><docker><macos><tox>
2024-01-21 13:03:41
1
211,730
MaxU - stand with Ukraine
77,854,835
16,383,578
How to calculate the number of ways to choose Y items from at most X groups efficiently?
<p>I don't know how to describe this concisely. Say you have X groups of items, each item in the same group is identical. All the groups have infinite size.</p> <p>You want to choose Y items from the X groups completely at random, you want exactly Y items, and you can choose all from 1 group, 2 groups, 3 groups... all ...
<python><math><combinatorics>
2024-01-21 12:41:46
3
3,930
Ξένη Γήινος
77,854,629
12,200,808
How to check out tensorflow 2.15.0.post1
<p>The <code>tensorflow</code> tags only has &quot;<code>v2.15.0 --&gt; Nov 15, 2023</code>&quot;, but <code>pypi</code> has &quot;<code>tensorflow == 2.15.0.post1</code>&quot;</p> <p><a href="https://pypi.org/project/tensorflow/" rel="nofollow noreferrer">https://pypi.org/project/tensorflow/</a></p> <pre><code>tensorf...
<python><tensorflow><ubuntu><github>
2024-01-21 11:37:16
1
1,900
stackbiz
77,854,619
2,459,153
Python os.py behaves like a package. Why?
<p>The following operation works</p> <pre><code>from os.path import normcase </code></pre> <p>As far as I'm concerned it shouldn't. &quot;os.py&quot; is not a directory so not a package. os does contain path which is itself another module.</p> <p>Furthermore</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.__packa...
<python><import><module><package>
2024-01-21 11:35:38
0
326
Francis Cagney
77,854,431
1,543,290
How to set the quality of an mp3 Codec with PyAV
<p>I wrote a simple code to create a .mp3 file from any audio input, using PyAV. It's working (pasted at the end of the question). However, when using <code>ffmpeg</code> it's possible to set the quality of the .mp3 file, and I'd like to do this as well in my code. According to the <a href="https://ffmpeg.org/ffmpeg-co...
<python><ffmpeg><mp3><codec><pyav>
2024-01-21 10:32:12
1
1,722
Zvika
77,854,397
11,748,924
Pandas resample signal series with its corresponding label
<p>I have this table with these columns: <strong>Seconds, Amplitude, Labels, Metadata</strong>. Basically, it's an ECG signal.</p> <p>You can download the csv here: <a href="https://tmpfiles.org/3951223/question.csv" rel="nofollow noreferrer">https://tmpfiles.org/3951223/question.csv</a></p> <p>As you see, the second t...
<python><pandas><dataframe><numpy><pandas-resample>
2024-01-21 10:19:00
1
1,252
Muhammad Ikhwan Perwira
77,854,336
5,798,365
Why None is printed when a slice of the list is sorted
<p>The following code</p> <pre><code> L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(L[2:8].sort(reverse=True)) </code></pre> <p>prints <code>None</code> while I expect it to print <code>L = [1, 2, 8, 7, 6, 5, 4, 3, 9, 10]</code></p> <ol> <li><p>Why is it so?</p> </li> <li><p>If that's not the way to sort part of the l...
<python><sorting><slice>
2024-01-21 09:57:46
1
861
alekscooper
77,854,081
3,555,115
Filter lines based on specific event and create a dictionary
<p>I have a log file which contains timestamps and events</p> <pre><code> Mon Jan 15 22:16:46 PST 2024 /vol/vol1 Sorting file records (120 entries) Mon Jan 15 22:16:46 PST 2024 /vol/vol2 Sorting file records (120 entries) Mon Jan 15 22:16:46 PST 2024 /vol/vol1 Sorting text records (120 entries) Mo...
<python><dataframe><dictionary>
2024-01-21 08:27:02
1
750
user3555115
77,853,969
8,763,290
Why does timestamp wrap around for `libevdev` events?
<p>I've been playing around with <a href="https://python-libevdev.readthedocs.io/en/latest/" rel="nofollow noreferrer">python-libevdev</a> and noticed that event timestamps seem to wrap around. For example, when I ran the following script:</p> <pre class="lang-py prettyprint-override"><code>import libevdev as ev with ...
<python><linux><linux-kernel><keyboard><evdev>
2024-01-21 07:48:40
1
449
jth
77,853,940
8,243,936
Python socket connection was forcibly closed by the remote host, what is problem?
<p>I have some <em>GPS Tracker Devices</em> that send their states to server when I sent <strong>&quot;LOAD&quot;</strong> command, all things is good and I get response, <strong>but after 1 minute i get this error</strong> :</p> <blockquote> <p>An existing connection was forcibly closed by the remote host</p> </blockq...
<python><sockets>
2024-01-21 07:34:07
0
750
NEBEZ
77,853,853
485,330
Error while importing python-whois on AWS Lambda
<p>I'm trying to run a script that uses <strong>python-whois</strong> and I'm having an error. This was previously imported locally using &quot;pip3 install python-whois -t .&quot; and then uploaded to the zip file into AWS Lambda. I'm using Python v3.12</p> <pre><code>import json import whois def lambda_handler(even...
<python><aws-lambda><whois>
2024-01-21 06:58:06
3
704
Andre
77,853,620
7,652,266
How to make the level of subpackage up when import subpackge in main script?
<p>I want to make a subpackage level up to write the main script in a more simple path. That is, I want to write the path for sub2 in directly pack.sub2 rather than pack.sub1.sub2. Now I made a directory structure and some modules as follows.</p> <p>pack/sub1/sub2/mod.py</p> <p>pack/<strong>init</strong>.py</p> <pre><c...
<python><relative-path>
2024-01-21 04:40:26
1
563
Joonho Park
77,853,378
2,910,279
Pandas dataframe aggregation on dynamic groups
<p>I have a dataframe like this:</p> <pre><code>Date Value 2023-05-20 2 2023-05-22 4 2023-05-22 3 2023-05-24 5 </code></pre> <p>There may be missing days, and also days having multiple entries. How do I get a list of <em>all</em> days (between lowest and largest given day) cumulating the sum of values &quot;...
<python><pandas>
2024-01-21 01:59:15
1
1,451
Henning
77,853,361
7,824,238
Plotly express scatter with facet_col does not use correct colors - what I am doing wrong?
<p>The following code shows first one scatter plot with mixed positive and negative data. Negative data (around -100) on the bottom left, positive data (around +100) on the top right.</p> <p><a href="https://i.sstatic.net/bkCHa.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bkCHa.png" alt="plot with -10...
<python><plotly><plotly-express>
2024-01-21 01:52:06
1
420
7824238
77,853,347
1,667,018
Python generator yielding from nested non-generator function
<p>This is a dumb example based on a more complex thing that I want to do:</p> <pre class="lang-py prettyprint-override"><code>from typing import Generator def f() -&gt; Generator[list[int], None, None]: result = list() result.append(1) if len(result) == 2: yield result result = list() ...
<python><generator><nested-function>
2024-01-21 01:44:56
1
3,815
Vedran Šego
77,853,142
7,563,454
Conditional variable assignment with numpy array
<p>I'm migrating my Python based engine to Numpy in hopes of better performance. Previously I used my own vector3 class: With it I could use use conditional variable assignments in the following form, with <code>settings[&quot;size&quot;]</code> being the provided array if present in the settings dictionary otherwise <...
<python><numpy>
2024-01-20 23:46:29
1
1,161
MirceaKitsune
77,853,003
15,452,898
Marking the results of code inside initial dataframe in python
<p>Currently I'm performing calculations on a database that contains information on transactions. It is a big dataset consumes a lot of resources and have just faced with an issue of how to use optimize my current solution.</p> <p>My initial dataframe looks like this:</p> <pre><code>Name ID ContractDate LoanSum ...
<python><pyspark><subset><data-manipulation>
2024-01-20 22:38:10
1
333
lenpyspanacb
77,852,795
1,005,409
Cross-Environment ECDSA Signature Verification Fails Between React and Python
<p>I'm working on a project where I need to generate an ECDSA signature in a React application and then verify it in a Python backend. The signature generation and verification work within their respective environments, but the signature generated in React fails verification in Python. I'm using the elliptic library in...
<javascript><python><reactjs><cryptography><ecdsa>
2024-01-20 21:19:50
1
6,037
Muppet
77,852,757
873,650
python interpreter incompatible with packages versions in requirements.txt
<p>I have a <code>requirements.txt</code> file but my python version is not compatible with those versions required, what is the smartest way to upgrade the versions of the packages without changing too much of the original setup?</p> <p><strong>I am following a book that has those reqs and I'm afraid of new versions m...
<python><numpy>
2024-01-20 21:09:29
0
4,421
Fernando Fabreti
77,852,422
2,829,961
How to install and load polars in Python?
<p>Based on <a href="https://stackoverflow.com/a/74859637/2829961">this</a> stackoverflow answer, I installed <code>polars-lts-cpu</code> after uninstalling <code>polars</code> but I can't get it to work:</p> <p><a href="https://i.sstatic.net/3OtNa.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3OtNa.pn...
<python><python-polars>
2024-01-20 19:25:28
1
6,319
umair durrani
77,852,333
2,692,339
How to run multiple inferences in parallel on CPU?
<p>I've got some models implemented in PyTorch, where their performance is evaluated on a custom platform (wrapper around Pytorch, keeping overall interface).</p> <p>This is really slow however: testing 10k CIFAR10 takes almost 30mins on a single CPU. My cloud farm has no GPU available, but is highly CPU-oriented with ...
<python><deep-learning><pytorch><inference>
2024-01-20 19:00:19
1
8,538
edmz
77,852,211
17,889,328
Pycharm+Protocols - how to silence spurious 'Getter should return or yield something'
<pre><code>class MyProtocol(Protocol): @property def my_property(self) -&gt; str: ... class MyClass(MyProtocol): @property def my_property(self) -&gt; str: # the actual implementation is here </code></pre> <p>pycharm complains the protocol doesnt return values. because its a protocol......
<python><pycharm><protocols><static-analysis>
2024-01-20 18:27:26
1
704
prosody
77,852,152
2,363,342
Generating 8th note tuplets using music21
<p>I'm using music21 to add a given sequence of notes to arbitrary tuplet divisions. For example, given &quot;CEGBCAFD&quot; in the time signature of 2/4, I want to create measures with quintuplets (e.g., 5 over 2) that go over that sequence.</p> <p>Here's the python code I came up with to generate the tuplet:</p> <pre...
<python><music21><musicxml>
2024-01-20 18:09:44
0
1,109
Lee Hampton
77,852,109
630,556
Why does Ruff not show as many diagnostics as I expect?
<p>I have installed the Ruff extension and enabled it in VS Code, but it doesn't seem to be underlining my code at all and providing suggestions like my previous linters did.</p> <p>I did a clean install of VS Code, so most of the Python/Ruff extension settings are default. Is there an additional step I need to take to...
<python><visual-studio-code><ruff>
2024-01-20 17:54:48
5
1,363
Nick Nelson
77,852,050
11,741,232
Forever loop in Blender scripting?
<p>If you add</p> <pre class="lang-py prettyprint-override"><code>while True: print(&quot;hi&quot;) </code></pre> <p>to an otherwise functional script in Blender's scripting window and run it, Blender hangs.</p> <p>This is undesirable because I'm trying to use Redis as a pub-sub broker, such that another script can...
<python><redis><blender>
2024-01-20 17:36:26
2
694
kevinlinxc
77,852,033
182,737
Enable ruff rules only on specific files
<p>I work on a large project and I'd slowly like to enfore pydocstyle using ruff. However, many files will fail on e.g. D103 &quot;undocumented public function&quot;. I'd like to start with enforcing it on a few specific files, so I'd like to write something like</p> <pre><code>select = [&quot;D&quot;] [tool.ruff.igno...
<python><ruff>
2024-01-20 17:31:14
2
1,229
Frank Meulenaar
77,851,947
16,728,369
Could not build wheels for Pillow, typed-ast, which is required to install pyproject.toml-based projects
<p>I'm trying to run a old project here is my requirements.txt</p> <pre><code>asgiref==3.4.1 astroid==2.3.3 certifi==2019.11.28 chardet==3.0.4 Django==4.0.1 django-cleanup==5.2.0 idna==2.8 isort==4.3.21 lazy-object-proxy==1.4.3 mccabe==0.6.1 Pillow==9.0.0 requests==2.22.0 six==1.13.0 sqlparse==0.4.2 sslcommerz-python==...
<python><pip><python-imaging-library><install.packages>
2024-01-20 17:08:40
1
469
Abu RayhaN
77,851,918
11,865,149
opencv- contourArea doesn't work as expected
<p>I followed <a href="https://pyimagesearch.com/2015/04/20/sorting-contours-using-python-and-opencv/" rel="nofollow noreferrer">this opencv guide</a> to sort the contours in the first image by size.</p> <p>I calculated an edge map (the result is the middle image):</p> <pre><code># load the image and initialize the acc...
<python><opencv><computer-vision><canny-operator>
2024-01-20 17:02:26
1
393
benjamin
77,851,840
7,155,895
Frame that resizes by adding any widget inside
<p>I have a behavior that is happening, that I don't know how to find a solution to. The solution is probably right before my eyes, but I can't find it, despite my searches.</p> <p>The problem is this, I have a frame with a certain size, in which I created a grid inside. Until that, there are no problems.</p> <p><a hre...
<python><tkinter><python-3.11>
2024-01-20 16:41:09
1
579
Rebagliati Loris
77,851,795
19,672,778
CNN outputs nan Loss after first epoch
<p>I was training my CNN model with my data and after i made some adjustments (i changed sigmoid activations into relu on convolutions and added learning rate decay function) i get NAN loss and NAN mae after first epoch. can anyone tell me what should i do?</p> <pre class="lang-py prettyprint-override"><code>def schedu...
<python><tensorflow><deep-learning><conv-neural-network>
2024-01-20 16:26:19
1
319
NikoMolecule
77,851,693
10,037,034
how to change config file by using hydra?
<p>i was trying to use hydra for to manage my config files. But it wont change anything. for ex: this is my code;</p> <pre><code>from omegaconf import DictConfig, OmegaConf import hydra @hydra.main(version_base=None, config_path=&quot;.&quot;, config_name=&quot;config&quot;) def main(config: DictConfig)-&gt;None: ...
<python><config><fb-hydra>
2024-01-20 15:59:50
1
1,311
Sevval Kahraman
77,851,648
1,711,271
Given a dataframe with 3 columns, return a list of lists of all the unique values of 'C', for each distinct pair of 'A' and 'B'
<p>I have the following dataframe:</p> <pre><code> foo bar baz 0 1234_312_GCD 1234 312 1 1234_312_GCD 1234 312 2 1234_312_GCD 1234 312 3 1234_312_GCD 1234 312 4 1234_312_GCD 1234 312 5 0777_666_lcm 0777 666 6 0777_666_lcm 0777 66...
<python><pandas><string><group-by>
2024-01-20 15:50:20
2
5,726
DeltaIV
77,851,504
1,469,954
Python unable to terminate spawned child processes by terminating parent process
<p>I have a master script (Python) from where I want to spawn several child scripts. The child scripts should run independently without bothering each other (just writing to a file in a loop). What I want - when the master script is terminated, so should all the spawned child processes.</p> <p>But however, even through...
<python><subprocess><popen><sigint>
2024-01-20 15:01:29
1
5,353
NedStarkOfWinterfell
77,851,446
10,859,114
missing data when recording audio on raspberry pi pico
<p>i wanted to record audio using <code>max9814</code> and <code>raspberry pi pico</code> with <code>micropython/circuitpython</code> but when i recorded the data, some parts of it lose because it's trying to read the data and write the data into a .wav file and it can not hadle it simultaneously.</p> <p>the circuit is...
<python><audio><micropython><raspberry-pi-pico><adafruit-circuitpython>
2024-01-20 14:41:40
0
470
Alirezaarabi
77,851,436
4,701,426
Any difference between using .pickle/pkl file extension vs no extension when working with pickle files with pandas?
<p>I have noticed that all three of these seem to produce the same result (<code>df</code> is a pandas dataframe):</p> <pre><code>df.to_pickle('df') df.to_pickle('df.pkl') df.to_pickle('df.pickle') </code></pre> <p>I read <a href="https://stackoverflow.com/questions/42193963/file-extension-naming-p-vs-pkl-vs-pickle">he...
<python><pandas><pickle>
2024-01-20 14:38:38
1
2,151
Saeed
77,851,377
2,663,442
How to make a histogram based on the second column of a large matrix and then calculate the sum efficiently?
<p>The matrix is like 4000 columns x 1e8 lines. Now I need to divide the 1e8 lines into 1000 bins based on the 2nd column and sum the lines in every bin. Finally, I would get 4000 columns x 1000 lines.</p> <pre><code>aa=np.random.rand(10000000, 4000) l,r=min(aa[:,1]),max(aa[:,1]) bins=np.linspace(l,r,1001) for bn in ra...
<python><numpy><histogram>
2024-01-20 14:19:58
2
763
questionhang
77,851,371
1,028,270
Is "Type of "X" is partially unknown" a problem with this library or my own code?
<p>I'm using another users package and getting the linting warning when importing it:</p> <pre><code># Throws: Type of &quot;task&quot; is partially unknown from invoke.tasks import task </code></pre> <p>Is this an issue with the package's code or is there something I'm expected to do in my code?</p> <p><a href="https:...
<python><python-typing>
2024-01-20 14:18:49
2
32,280
red888
77,851,355
12,712,848
Routing in Azure Function in Python does not work
<p>I'm trying to modify a route name in my function. This is my code (just testing):</p> <pre class="lang-py prettyprint-override"><code>import logging import azure.functions as func from azure.cosmos import CosmosClient import json def main(req: func.HttpRequest) -&gt; func.HttpResponse: logging.info('Python HTTP...
<python><azure><azure-functions>
2024-01-20 14:14:26
1
841
OK 400
77,851,112
3,402,296
Interpolate reciprocal function from a set of points
<p>Not sure whether to post this here or on Mathematics. Anyway my problem is that I have a set of points that describe a curve like the following</p> <p><a href="https://i.sstatic.net/ecmv1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ecmv1.png" alt="enter image description here" /></a></p> <p>The po...
<python><math><polynomials>
2024-01-20 12:59:55
1
576
RDGuida
77,851,075
1,028,270
Unclear on how Pylance(reportOptionalMemberAccess) is useful
<p>I've been playing with strict type checking and there is something I don't fully understand.</p> <p>Consider the following:</p> <pre><code># mymeth() -&gt; (Result | None) aaa = derp.mymeth() # get error: &quot;some_prop&quot; is not a known member of &quot;None&quot; bbb = json.loads(aaa.some_prop) return bbb </c...
<python><python-typing>
2024-01-20 12:50:43
1
32,280
red888
77,850,728
10,013,975
Passing keyword arguments with default values in a layered call
<p>I am working on a python library where I want to give some flexibility to the user. I am facing below challenge.</p> <p>Let's say I exposed the class <code>Client</code> to the user, which is defined like below:</p> <pre><code>class Client: def __init__(self, path=None): self.file_obj = FileOpener(path =...
<python><python-3.x><design-patterns>
2024-01-20 10:53:56
2
433
Mukul Bindal
77,850,567
19,932,351
Wordpress REST API remove all posts and images (media) via Python
<p>I feel like this should be something several other people already accomplished... to write a script that removes all sample data from a dev webpage using the Wordpress Rest API. Right now I try to automate posting images and posts, which works and leads to several of hundreds posts and images blowing up my database....
<python><python-requests><wordpress-rest-api>
2024-01-20 10:08:12
1
662
Leon
77,850,507
7,862,953
webscraping python ssl certificate
<p>Trying to practice in webscrape in the command</p> <pre><code>result = requests.get(url) </code></pre> <p>I get</p> <pre><code>SSLError: HTTPSConnectionPool(host='subslikescript.com', port=443): Max retries exceeded with url: /movie/Titanic-120338 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_V...
<python><ssl><web-scraping>
2024-01-20 09:47:12
0
537
zachi
77,850,212
11,861,874
Python One Page Report Based on Output of Function
<p>I am trying to prepare a report using Python. So the first function produces some output and next, I run function 2 and get an output, at the end, I need all output one below the other saved in .pdf or .doc format at one location, with some header/title to the report. It's a kind of one-pager report with multiple ou...
<python><pandas><matplotlib><report>
2024-01-20 07:52:39
2
645
Add
77,850,040
3,555,115
Filter rows based on column value condition and merge with other dataframe
<p>I have a dataframe</p> <pre><code>df1 = vol comp sort vol1 10 20 vol2 10 20 df2 = load vol counter_name counter_value 1 vol1 bytes_read 50 1 vol1 bytes...
<python><pandas><dataframe>
2024-01-20 06:29:23
1
750
user3555115
77,850,020
8,176,763
dynamically select columns and values with sqlalchemy
<p>Say I have a table like:</p> <pre><code>product market idea A FG cool C BG sad T B super </code></pre> <p>In the frontend the user can select any value from product market or idea and also any column to filter. So for ...
<python><sqlalchemy>
2024-01-20 06:17:29
1
2,459
moth
77,850,003
10,015,739
Vector Coordinates and linear combination as an arrow will not display on the same plot
<p>I am attempting to graph the coordinates of two vectors on a plot (see Part 1 of code snippet) and the linear combination of the two vectors (see Part 2 of code snippet1) on the same plot. However, in Snippet 1, only the arrow is displaying, though I am not sure why.</p> <p>In Snippet 2, I was able to get both to p...
<python><numpy><matplotlib><linear-algebra>
2024-01-20 06:09:04
1
483
tlockhart
77,849,981
8,176,763
sqlalchemy returns instance of the class but it does not print correctly
<p>I have code like this:</p> <pre><code>from sqlalchemy import create_engine, Column, String,and_,insert,select,Integer,delete from sqlalchemy.orm import declarative_base from sqlalchemy.orm import sessionmaker # Define your model Base = declarative_base() class MyTable(Base): __tablename__ = 'my_table' id =...
<python><sqlalchemy>
2024-01-20 05:55:57
1
2,459
moth
77,849,974
12,200,808
How to show the dependency problem in the existing python environment
<p>I installed the python packages on Ubuntu by the following command:</p> <pre><code># pip install --upgrade -r r.txt </code></pre> <p><strong>Here is the console output:</strong></p> <pre><code>Installing collected packages: protobuf ERROR: pip's legacy dependency resolver does not consider dependency conflicts when...
<python><bash><ubuntu><pip>
2024-01-20 05:53:15
1
1,900
stackbiz
77,849,842
10,070,717
Python Paramiko - problems with sending "iperf -s" to Linux server
<p>I need to send the command <code>iperf -s</code> to a Linux server using a Python program. The command is not sent. The chronology of problems is as follows:</p> <ol> <li>I am sending the command <code>iperf -s</code> to the server. Nothing happens, the program freezes (I don't stop the program).</li> <li>I use the ...
<python><ssh><paramiko>
2024-01-20 04:40:34
0
355
Кирилл Химов
77,849,780
9,108,781
ChromaDB query filtering by documents
<p>Can I run a query among a supplied list of documents, for example, by adding something like &quot;where documents in supplied_doc_list&quot;? I know those documents are in the collection. I kept track of them when I added them. Alternatively, is there a way to filter based on docID. As another alternative, can I cre...
<python><chromadb>
2024-01-20 03:52:21
0
943
Victor Wang
77,849,394
18,476,381
Python SQL Alchemy Nested Object Insert
<p>I am using a Python and SQLAlchemy to perform CRUD operations on my oracle database.</p> <p>I have the below models:</p> <pre><code>class ServiceOrderModel(BaseModel): service_order_id: int | None = None service_order_number: str | None = None service_type: str service_order_items: Optional[List[Serv...
<python><sqlalchemy><pydantic>
2024-01-20 00:01:34
1
609
Masterstack8080
77,849,271
18,476,381
Pydantic init/validating model from dict is changing sub model to None
<p>I have a pydantic model like below:</p> <pre><code>class ServiceOrderModel(BaseModel): service_order_id: int | None = None service_order_number: str | None = None service_order_items: Optional[List[ServiceOrderItemModel]] = Field( None, alias=&quot;service_order_item&quot; ) class Config...
<python><sqlalchemy><pydantic>
2024-01-19 23:18:57
1
609
Masterstack8080
77,849,133
146,073
SQLAlchemy bidirectional many-to-many raising ArgumentError
<p>I've tried to establish a many-to-many relationship between two tables, User and Product, through a third table, Cart. Since the cart has additional data for each row I'm trying to use the association object pattern, but clearly there's something fundamental I'm not understanding. Here are the model declarations:</p...
<python><sqlalchemy><many-to-many><relationship>
2024-01-19 22:28:36
0
37,731
holdenweb
77,849,080
23,190,147
How to detect a mouse circling around something in python?
<p>I'm trying to detect when a user's mouse is circling around an object repeatedly, and take a screenshot of that object.</p> <p>To make this simpler, I'll split it into two parts. First of all, I want to detect the mouse circling. This is easy, there are many python libraries for this. But I don't want the screenshot...
<python><image><mouse>
2024-01-19 22:14:48
0
450
5rod
77,849,062
2,182,636
Get Playwright to Wait Until Title Contains Specific Text
<p>I'm new at playwright and I'm a little stuck. I'm scraping a site that has a lot of back and forth Javascript. I want my parsing logic to wait until the the title of the page is populated with a particular value, which would indicate that the page has loaded enough to parse.</p> <p>Here are the relevant parts of m...
<python><web-scraping><playwright><playwright-python>
2024-01-19 22:10:09
2
586
cgivre
77,849,025
4,089,351
Avoiding DeprecationWarning when extracting indices to subset vectors
<p>General idea: I want to take a slice of a 3D surface plot of a function of two variables <code>f(x,y)</code> at a given <code>x = some value</code>. The problem is that I have to know the index where <code>x</code> assumes this value after creating <code>x</code> as a vector with <code>np.linspace</code>, for instan...
<python><numpy><subset>
2024-01-19 21:59:41
1
4,851
Antoni Parellada
77,848,945
1,028,270
How do I disable D100 and or C0111 with ruff?
<p>I use sphinx and at the top of my py files I have this:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- &quot;&quot;&quot; my-module ========= Some notes about my module &quot;&quot;&quot; </code></pre> <p>These warning are incorrect in the this context:</p> <ul> <li>1 blank line required between summa...
<python><docstring><ruff>
2024-01-19 21:38:19
1
32,280
red888
77,848,932
3,555,115
Simplify dataframe by combining data from various columns together for same instance
<p>I have a dataframe after concatenting several dataframes</p> <pre><code>df1 = instance scan comp sort 0 A 23:15:12 NaN NaN 1 B 23:17:12 NaN NaN 2 C 23:16:12 NaN NaN ...
<python><pandas><dataframe>
2024-01-19 21:35:09
2
750
user3555115
77,848,763
1,182,299
Extract a text with python beautifulsoup from a TEI XML document
<p>I'm trying to extract a text from a TEI XML document, I can't figure out how to get the other tags names not just the text itself.</p> <pre><code> &lt;text&gt; &lt;body&gt; &lt;div xml:id=&quot;S00483.1&quot;&gt; &lt;div xml:id=&quot;S00483.1.1&quot;&gt; &lt;pb xml:id=&quo...
<python><python-3.x><xml><beautifulsoup><tei>
2024-01-19 20:53:48
1
1,791
bsteo
77,848,741
5,594,008
dulwich error when running in docker-compose build poetry install
<p>I'm trying to run docker-compose build the command is failing on line</p> <pre><code>RUN --mount=type=ssh poetry install $(if [ &quot;$build_env&quot; = 'production' ]; \ then echo '--only main --extras=production'; fi) --no-interaction --no-ansi </code></pre> <p>with the error message</p> <pre><code>19.57 at...
<python><docker><ssh><dulwich>
2024-01-19 20:48:58
1
2,352
Headmaster
77,848,710
788,153
How to fix a column inplace after performing groupby in pandas
<p>My data has some issue and I want to fix this as defined in the function <code>fixseq</code>. I am looking for efficient way to fix column <code>B</code>. This column can't have negative number and if does, I need to shift the number so that it starts from 0.</p> <pre><code>def fixseq(tmp): print(tmp) if tmp...
<python><pandas>
2024-01-19 20:41:53
2
2,762
learner
77,848,673
10,869,768
replicate with llama-index and streamlit - unable to find documents
<p>I am running code below on a GPU via:</p> <pre><code>streamlit run replicate_lama2.py import os import traceback import sys import streamlit as st os.environ[&quot;REPLICATE_API_TOKEN&quot;] = &quot;my_key&quot; from llama_index.llms import Replicate llama2_7b_chat = &quot;meta/llama-2-7b-chat:8e6975e5ed6174911a...
<python><streamlit><replicate><llama><llama-index>
2024-01-19 20:33:11
1
429
anikaM
77,848,436
438,223
Simple RNN with more than one layer in Pytorch for squential prediction
<p>I got sequential time series data. At each time stamp, there is only variable to observe (if my understanding is correct this means number of features = 1). I want to train a simple RNN with more than one layer to predict the next observation.</p> <p>I created training data using sliding window, with window size set...
<python><numpy><machine-learning><pytorch><recurrent-neural-network>
2024-01-19 19:36:58
3
1,596
Shew
77,848,403
11,150,561
TPOT best pipeline has no predict_proba() - how to prevent falling over?
<p>I am running 5-fold X-validation on a dataset using tpot from a Jupyter notebook:</p> <pre><code>scores = [] preds = [] actual_labels = [] # Initialise the 5-fold cross-validation kf = StratifiedKFold(n_splits=5,shuffle=True) for train_index, test_index in kf.split(X, y): # Generate the training and test partiti...
<python><loss-function><tpot><sgdclassifier>
2024-01-19 19:28:14
0
389
Reader 123
77,848,382
11,618,586
labeling segments of cyclical data based on multiple conditions
<p>This is a follow-up on a <a href="https://stackoverflow.com/questions/77842667/labeling-segments-of-data-based-on-multiple-conditions">question</a> I posted that a member graciously provided the solution for. However, I had neglected to account for periodicity in my question.</p> <p>I have a dataframe like so:</p> <...
<python><python-3.x><pandas>
2024-01-19 19:24:54
1
1,264
thentangler
77,848,348
5,672,025
Python instanceof on alias type
<p>I have the following types and type alias defined:</p> <pre class="lang-py prettyprint-override"><code>@unique class MyEnum(Enum): A = 1 B = 2 C = 3 D = 4 class A: pass class B: pass MyAlias = MyEnum | A | B MyAlias2 = MyAlias | str | int @dataclass(slots=True) class A: type: MyAlia...
<python><types>
2024-01-19 19:17:36
2
1,981
Jorayen
77,848,299
2,711,953
operator.attrgetter cannot read attributes in a dataclass
<p>I have a module that holds a dataclass:</p> <p>my_module.py</p> <pre><code>@dataclass class MyDataClass: foo: str bar: str </code></pre> <p>I want to use <code>operator.attrgetter</code> to read <code>MyDataClass.foo</code></p> <pre><code>import package.my_module from operator import attrgetter obj = attrge...
<python>
2024-01-19 19:06:29
1
318
wO_o
77,848,276
10,178,227
linear regression output are nonsensical
<p>I have a dataset and am trying to fill in the missing values by utilizing a 2d regression to get the slope of the surrounding curves to approximate the missing value. I am not sure if this is the right approach here, but am open to listen to other ideas. However, here's my example:</p> <pre><code>local_window = pd.D...
<python><regression>
2024-01-19 18:59:40
1
389
yungpadewon
77,848,197
79,125
How do I rewind subprocess's output to capture output on failure?
<p>What's a generic way that I can capture output from <code>subprocess</code> <strong>after</strong> reading its output fails?</p> <p>When I get a UnicodeDecodeError I want to see the original content to reproduce, but I'm not always able to run the command again to get the output.</p> <p>If I avoid <code>text</code>/...
<python><io><subprocess>
2024-01-19 18:43:02
0
12,232
idbrii
77,848,047
1,938,410
cannot import name '_imaging' from 'PIL' when using Pillow on AWS Lambda
<p>I uploaded Pillow package into AWS Lambda and added it as a layer, but the execution of the lambda function give the <code>cannot import name '_imaging' from 'PIL' (/opt/python/PIL/__init__.py)</code> error.</p> <p>What I have done:</p> <ol> <li><code>pip install pillow -t .</code> and put <code>PIL</code> and <code...
<python><amazon-web-services><aws-lambda><python-imaging-library>
2024-01-19 18:12:33
1
507
SamTest
77,847,983
1,397,946
Processing requests in FastAPI sequentially while staying responsive
<p>My server exposes an API for a resource-intensive rendering work. The job it does involves a GPU and as such the server can handle only a single request at a time. Clients should submit a job and receive <code>201</code> - ACCEPTED - as a response immediately after. The processing can take up to a minute and there c...
<python><concurrency><python-asyncio><fastapi>
2024-01-19 18:00:12
3
11,517
Lukasz Tracewski
77,847,952
1,711,271
Find a substring of 4 consecutive digits and a substring of 3 consecutive digits in a string
<p>I have strings of the type:</p> <pre><code>1432_ott_457_blusp 312_fooob_bork_1234 broz_901_6453 kkhas_1781_LET_GROK_234 1781_234_kkhas </code></pre> <p>etc. In other words, each string contains multiple substrings delimited by <code>_</code>. The total number of substrings is variable. I look for a substring contain...
<python><string><substring>
2024-01-19 17:51:03
3
5,726
DeltaIV
77,847,901
23,260,297
Group data from a dataframe into a separate dataframe
<p>I need to group rows in a dataframe on 3 conditions, and take each grouping and create a new dataframe. I am unfamiliar with the groupby function in pandas and all the examples I have come across have been no help. Is groupby the right approach for this kind of solution? or is there a better way to achieve this?</p>...
<python><pandas>
2024-01-19 17:41:36
1
2,185
iBeMeltin
77,847,816
13,642,459
Use dask to map over an array and return a dataframe
<p>I am using dask and zarr to operate over some very large images.</p> <p>I have a pipeline set up that performs some transformations to these images and I would then like to measure properties of the image using the regionprops and regionprops_table functions from skimage. This takes a matrix as an input and returns ...
<python><dask>
2024-01-19 17:24:26
2
456
Hugh Warden
77,847,798
1,473,517
How to find an optimal shape with sections missing
<p>Given an n by n matrix of integers, I want to find a part of the matrix that has the maximum sum with some restrictions. In the version I can solve, I am allowed to draw two lines and remove everything below and/or to the right. These can be one horizontal line and one diagonal line at 45 degrees (going up and rig...
<python><algorithm><performance><optimization>
2024-01-19 17:19:09
1
21,513
Simd
77,847,632
13,147,413
GroupBy + custom mode function in Polars
<p>I need to apply a &quot;custom&quot; mode function to a groupBy object. I'm able to groupBy and apply mode:</p> <pre><code> df.with_columns(pl.col(&quot;X&quot;).mode().over(['Y', 'Z']).name.prefix(&quot;mode_&quot;)) </code></pre> <p>and that kind of approach gives me this kind of error:</p> <pre><code> ComputeErro...
<python><dataframe><python-polars>
2024-01-19 16:49:26
1
881
Alessandro Togni
77,847,612
4,436,572
Python not recognising Pyo3 class
<p>I am new to rust and I was trying <code>pyo3</code> today. Following is my naive example:</p> <pre><code>use pyo3::prelude::*; #[pyclass] struct TestClass { symbol: i32, } #[pymethods] impl TestClass { #[new] fn new(symbol: i32) -&gt; PyResult&lt;Self&gt; { Ok(TestClass { symbol }) } #...
<python><rust><pyo3>
2024-01-19 16:46:29
0
1,288
stucash
77,847,460
1,711,271
split a column in multiple columns, but only keep two of them
<p>I have the following dataframe:</p> <pre><code>import pandas as pd df = pd.DataFrame({'AB': ['A1_B1_C1', 'A2_B2_C2']}) </code></pre> <p>I want to split the column <code>AB</code> on the first two occurrences of delimiter <code>_</code>, but only keep the first two columns. In other words, the output has to be</p> <p...
<python><pandas><split>
2024-01-19 16:20:26
1
5,726
DeltaIV
77,847,217
1,028,270
How do I properly deal with console_scripts in a docker build
<p>I have an entrypoint in my setup.cfg:</p> <pre><code>[options.entry_points] console_scripts = mycmd = my_proj.main:program.run </code></pre> <p>main.py</p> <pre><code>from invoke import Collection, Program from my_proj import jobs program = Program(namespace=Collection.from_module(jobs), version=&quot;1.2.3&quot...
<python><pip><pyinvoke>
2024-01-19 15:35:51
0
32,280
red888
77,847,091
2,343,977
MoviePy crossfaadein transition
<p>I'm trying to work with <a href="https://pypi.org/project/moviepy/" rel="nofollow noreferrer">python moviepy</a></p> <p>I find some snippet online to apply a transition when I concatenate videos, however it seems not working for me. What I'm doing wrong? This is an extraction of the code :</p> <pre><code>clip1 = Vid...
<python><moviepy>
2024-01-19 15:16:33
1
642
Alessandro Candon
77,846,959
3,585,934
How to mock a third-pary class with pytest & mock
<p>my test code:</p> <pre class="lang-py prettyprint-override"><code>from unittest.mock import patch import pytest from journalwatcher.journal import read_for_test @patch(&quot;systemd.journal.Reader&quot;) def test_read(Reader): read_for_test(this_boot_only=True) Reader.this_boot.assert_called_once() </code><...
<python><mocking><pytest>
2024-01-19 14:53:57
1
625
Horus
77,846,918
839,119
Sympy: hierarchically collect an equation with more than one factor expression?
<p>Can we collect/factor an symbolic equation using sympy with more than one factor expression (and hierarchically)? I provide the following example: a long calculation result into the expanded equation <code>f</code>. In my computation, equations are larger and more complex.</p> <pre><code>import sympy a,b,m,n = sympy...
<python><sympy>
2024-01-19 14:45:45
1
1,500
sol
77,846,901
21,244,591
Django locale .po files not showing up in locales folder
<p>I have been running into an issue setting up locales for my Django app. When I run the <code>django-admin</code>'s <code>makemessages</code> command no resulting <code>.po</code> files show up in my <code>{project_root}/locales</code> folder.</p> <p>Here are the steps I followed to setup locales:</p> <p><strong>Crea...
<python><django><locale><gettext>
2024-01-19 14:43:54
3
366
Olivier Neve
77,846,896
10,966,677
Pandas conditional groupby: aggregation over partition using predicate
<p>I have had this task several times, so that I am wondering if it is possible to aggregate in a OVER PARTITION BY style while using a predicate.</p> <p>There are dozens of examples on SO of <code>groupby</code> of window function and quite a few using a condition, but none where the condition depends on the values of...
<python><pandas><group-by>
2024-01-19 14:42:45
1
459
Domenico Spidy Tamburro
77,846,779
5,679,047
Dependent data validation without allowing arbitrary inputs when previous column is blank (Excel, xlsxwriter)
<p>I have a Python script that produces an Excel file with columns that can be used to input chapters, sections, and subsections from a book that SMEs can use to write citations. I need to be able to process these citations programmatically, so I use data validation to ensure that they enter the exact text that the pro...
<python><excel><xlsxwriter>
2024-01-19 14:23:54
1
681
Zorgoth
77,846,721
893,254
How can I implement a match or if statement based on an enum's current value in Python?
<p>I have the following enum defined in some Python code:</p> <pre><code>from enum import Enum class TestEnum(Enum): MY_VALUE=1 </code></pre> <p>I want to implement a <code>__repr__</code> function for this enum.</p> <ul> <li>Actually, it doesn't have to be <code>__repr__</code> this is just for convenience when u...
<python><enums>
2024-01-19 14:15:26
0
18,579
user2138149
77,846,715
9,251,158
Monkey-patching OpenTimelineIO adapter to import Final Cut Pro XML
<p>I have several video projects from Final Cut Pro that I want to use in KdenLive. I found the OpenTimelineIO project and it would solve all my problems. I installed with</p> <pre class="lang-bash prettyprint-override"><code>$ python3 -m pip install opentimelineio ... $ python3 -m pip show opentimelineio Name: OpenTim...
<python><python-3.x><xml><finalcut>
2024-01-19 14:14:30
2
4,642
ginjaemocoes
77,846,541
16,607,067
Tags are not being saved when using django-parler
<p>I am using <code>django-parler</code> for translation and <code>django-taggit</code> for adding tags. But when I add tags inside translation field (because of using in multiple language) tags are not being saved in admin page.<br /> <strong>models.py</strong></p> <pre class="lang-py prettyprint-override"><code>class...
<python><django><django-taggit><django-parler>
2024-01-19 13:45:02
1
439
mirodil
77,846,493
10,413,428
Best Practice to install a temporary QTranslator for subpart of QApplication
<p>I use the following code to setup translation when setting up my PySide6 application:</p> <pre class="lang-py prettyprint-override"><code>app = QApplication(sys.argv) translator_ui = QTranslator() if translator_ui.load(f&quot;lang_{config.language.ui}&quot;, &quot;translations&quot;): app.installTranslator(tra...
<python><qt><pyside6><qt6>
2024-01-19 13:37:51
1
405
sebwr
77,846,470
6,501,203
Polars pairwise sum of array column
<p>I just got started with Polars (python) so this may be an ignorant question. I have a DF like the image shows where one of the columns (series) contains a numpy array of length 18. I would like to do a groupby on the <code>group</code> column and a pairwise sum aggregation on the series column, but I can't figure ou...
<python><dataframe><python-polars>
2024-01-19 13:35:04
2
370
Alec Daling
77,846,457
1,581,090
How can I fix Python video playing on Ubuntu using multiprocessing?
<p>On <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_22.04_LTS_(Jammy_Jellyfish)" rel="nofollow noreferrer">Ubuntu 22.04</a> (Jammy Jellyfish), I am trying to play a video clip using the following code:</p> <pre><code>import sys import multiprocessing from moviepy.editor import VideoFileClip vide...
<python><video><multiprocessing>
2024-01-19 13:32:57
0
45,023
Alex
77,846,449
9,462,829
Get perimeter out of irregular group of shapes
<p>I'm working on groups of shapes (think groups of city blocks) that are almost contiguous, like this:</p> <p><a href="https://i.sstatic.net/wMY7o.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wMY7o.png" alt="enter image description here" /></a></p> <p>What I'd like to do is to get the shape of the ou...
<python><geopandas><shapely>
2024-01-19 13:32:09
3
6,148
Juan C
77,846,394
9,872,200
Python DB data pull loop
<p>I want to loop through a script that pulls data from a db 1 month at a time where I am manually updating the date parameters(input) and output file names, but I do not know how I would set up the structure to loop/iterate through the script based on a list of dates/file names. Due to the size/nature of the datapull...
<python><sql><pandas><database>
2024-01-19 13:23:50
1
513
John