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
79,738,656
2,416,984
Accessing SharedMemory in a Gitlab runner
<p>I'm writing a pytest that should communicate to Docker containers through shared memory. Locally, that's pretty easy to achieve using something like this:</p> <pre class="lang-py prettyprint-override"><code># Create a shared memory block shm: SharedMemory = SharedMemory(create=True, name=shm_name, size=1e6) # Create...
<python><gitlab-ci><docker-in-docker>
2025-08-18 11:43:19
1
973
user2416984
79,738,518
270,043
PySpark program stuck at adding broadcast piece
<p>I'm trying to write a PySpark program that filters for records in a very large dataframe (1-2B records) that matches some conditions on another smaller reference dataframe. This is done using a left join between the 2 dataframes, and then writing the results to a parquet file. When the reference dataframe is empty, ...
<python><apache-spark><pyspark>
2025-08-18 09:32:29
1
15,187
Rayne
79,738,395
219,153
How to reduce horizontal padding in this matplotlib plot?
<p>I'm trying to eliminate horizontal padding of a Matplotlib plot. Here is the script:</p> <pre><code>import numpy as np, matplotlib.pyplot as plt a = np.random.rand(100) plt.figure(figsize=(12, 6), dpi=100) plt.tight_layout() plt.plot(a) plt.show() </code></pre> <p>The result contains a lot of horizontal padding bet...
<python><matplotlib>
2025-08-18 07:40:13
1
8,585
Paul Jurczak
79,738,197
11,168,635
Python: How to add variable in run statement?
<p>My vs code looks like this:</p> <pre><code>import requests import json import os os.environ = &quot;website.abc.com&quot; header={&quot;Accept&quot;:application/json&quot;, &quot;Authorization&quot;: f&quot;Bearer {os.environ['MY_API_KEY']}&quot; #then a parameter list={} #other code... </code></pre> <p>I am using...
<python><windows><visual-studio-code><environment-variables>
2025-08-18 00:41:55
1
323
ithoughtso
79,738,189
3,934,049
Spire.XLS with pyinstaller
<p>I am using spire.xls in my python script. When script executed from VS code evetything works as expected. I have created executable using pyinstaller. Added specific dlls.</p> <pre><code>pyinstaller --noconfirm --onefile --console --add-data &quot;I:\_DEV\Scripts\venv\Lib\site-packages\spire\xls\lib\Spire.Xls.Base.d...
<python><pyinstaller><spire.xls>
2025-08-18 00:15:29
1
1,491
goryef
79,738,129
11,499,270
Cannot access R or Python objects in R and Python Quarto Document
<p>I am using Quarto and VSCode to try to run Python and R together. I'd like to be able to access R objects in python or python objects in R. If I render the document below, it works as expected. However, if I am running in interactive mode, i.e., running each chunk / developing the code, I cannot access objects from ...
<python><r><quarto>
2025-08-17 21:54:39
0
759
acircleda
79,738,112
3,745,908
Open3D - memory usage increase on showing webcam stream
<p>I am trying to visualize a webcam feed on a plane in Open3D (testable Code below). After I run the script, the memory usage starts increasing after 3-5minutes non stop. When I comment the line modify_geometry_material, it works fine (no memory increase is noticed), although the texture is not updated until I move th...
<python><opencv><open3d>
2025-08-17 21:20:19
1
1,290
Mben.
79,737,751
905,845
Static type for "any SQLAlchemy ORM class with an integer field named 'id'"
<p>How can I give a static type to a function that should accept &quot;any SQLAlchemy ORM class with an integer field named 'id'&quot;?</p> <p>Below are my attempts, commented with the <code>mypy</code> errors I got. I had to resort to <code>id: Any</code> but I still hope I can do better.</p> <p>I can't modify the ORM...
<python><sqlalchemy><python-typing>
2025-08-17 09:41:27
1
668
jacquev6
79,737,733
18,349,319
Upload a large file to Minio from Minio objects
<p>I have the next case:</p> <pre><code>Get a certain count of N objects from Minio and create zip archive and upload it zip to Minio as one object. </code></pre> <p>Problem:</p> <ol> <li>I have many objects, that are up to 40gb in size</li> <li>I can't load all objects bytes in memory - server memory size is 4gb</li> ...
<python><large-files><minio><large-file-upload>
2025-08-17 09:04:01
1
345
TASK
79,737,582
1,940,534
Using SeleniumBase to wait for an image to become visible
<p>I have a table header element:</p> <pre><code>&lt;th&gt;&lt;input type=&quot;image&quot; src=&quot;../../..//images/icons/cell_state_header_icon.png&quot; onclick=&quot;javascript:__doPostBack('ctl00$left_pane$gvSelectedFeatures','Sort$Status')&quot; style=&quot;border-width:0px;&quot;&gt;&lt;/th&gt; </code></pre> <...
<python><selector><seleniumbase>
2025-08-17 01:19:02
1
1,217
robm
79,737,525
13,968,392
Connection string to read and write database with different engines
<p>In polars, there are the engines <code>connextorx</code> and <code>adbc</code> for <code>pl.read_database_uri</code> and <code>sqlalchemy</code> and <code>adbc</code> for <code>pl.write_database</code>. In the case of a postgresql database: Is it possible to use the same connection string for these engines when the ...
<python><database><postgresql><python-polars><adbc>
2025-08-16 22:30:05
3
2,117
mouwsy
79,737,395
2,654,773
Correct input for OpenAI embeddings API?
<p>I'm using the OpenAi text-embedding-3-small model to create embeddings for each product category in a file. In total it's about 6000 product categories and they look like this:</p> <pre><code>Vehicles &amp; Parts &gt; Vehicle Parts &amp; Accessories &gt; Vehicle Safety &amp; Security &gt; Off-Road &amp; All-Terrain ...
<python><artificial-intelligence><openai-api><azure-openai><openaiembeddings>
2025-08-16 18:16:52
0
3,873
eztam
79,737,165
9,669,142
Starting server to get Cesium terrain height only works one time
<p>I have multiple datasets with coordinates in them and I want to plot these points in Cesium for Unreal. For me to do that, I need to correct terrain heights and I want to have them in Python (since I'm doing some other stuff as well). Here I'm a bit stuck.</p> <p>There is no API for Cesium that seems to be available...
<python><flask>
2025-08-16 11:49:52
0
567
Fish1996
79,736,635
6,068,731
Post a local video file as a REEL using Instagram API in Python
<p>I am able to post a video from a public URL as a REEL:</p> <pre class="lang-py prettyprint-override"><code>import requests token = &quot;...&quot; api_version=&quot;v23.0&quot; headers = { &quot;Content-Type&quot;: &quot;application/json&quot;, &quot;Authorization&quot;: f&quot;Bearer {token}&quot; } # Ge...
<python><facebook-graph-api><python-requests><instagram-api><instagram-graph-api>
2025-08-15 16:25:43
0
728
Physics_Student
79,736,447
6,930,340
polars map_batches return_dtype argument for arrays
<p>I am applying a user defined function (UDF) to a <code>polars</code> dataframe using the <code>map_batches</code> function (c.p. <a href="https://docs.pola.rs/user-guide/expressions/user-defined-python-functions/#combining-multiple-column-values" rel="nofollow noreferrer">https://docs.pola.rs/user-guide/expressions/...
<python><dataframe><user-defined-functions><python-polars>
2025-08-15 13:00:49
1
5,167
Andi
79,736,262
3,179,698
Clear output then lose control of IPython debugger in jupyterhub notebook
<p>So I import a module:</p> <pre><code>from IPython.core.debugger import Pdb </code></pre> <p>Then I initiate an object for debugging:</p> <pre><code>ipdb = Pdb() </code></pre> <p>I define a function to test debug mode:</p> <pre><code>def f(a=1): ipdb.set_trace() print(a) </code></pre> <p>After I run the funct...
<python><jupyter-notebook><jupyterhub>
2025-08-15 08:52:13
0
1,504
cloudscomputes
79,735,957
1,747,834
How to make setup.py invoke C++ compiler instead of C?
<p>I have no problem building native modules when using Python 3.11 on my FreeBSD desktop – invoking <code>distutils.core.Extension</code> with <code>language = 'c++'</code> is enough to have the C++ compiler invoked.</p> <p>However, on the RHEL7 servers Python is much older – 3.6 – and the included <code>distutils</co...
<python><python-3.6><distutils>
2025-08-14 22:43:19
1
4,246
Mikhail T.
79,735,939
1,747,834
How to combine PyVarObject_HEAD_INIT and designated initializers?
<p>In my own &quot;native&quot; Python module I declare a new type this way:</p> <pre class="lang-c prettyprint-override"><code>PyTypeObject calculatorType = { PyVarObject_HEAD_INIT(NULL, 0) .tp_name = &quot;My.Calculator&quot;, .tp_basicsize = sizeof(PyMyCalculator), .tp_itemsize = 0, .tp_dealloc =...
<python><python-3.x><g++><clang++>
2025-08-14 22:15:54
0
4,246
Mikhail T.
79,735,835
1,747,834
How to add/subtract time in Python C API?
<p>There are many tutorials and examples out there on how to perform date-arithmetic from Python. But I cannot find anything for the Python C API...</p> <p>My C function, callable from Python, operates on two dates: <code>start</code> and <code>finish</code>. If <code>start</code> is not explicitly specified, it must b...
<python><c><python-3.x>
2025-08-14 19:35:28
1
4,246
Mikhail T.
79,735,667
785,404
Why isn't dict[str, str] assignable to Mapping[str | int, str] (Mapping key type isn't covariant)?
<p>Given this code:</p> <pre class="lang-py prettyprint-override"><code>from collections.abc import Mapping def my_fn(m: Mapping[str | int, str]): print(m) d = {&quot;a&quot;: &quot;b&quot;} my_fn(d) </code></pre> <p>both <code>mypy</code> 1.16.0 and <code>pyright</code> 1.1.400 report that it is invalid to assig...
<python><python-typing><mypy><pyright>
2025-08-14 16:04:33
2
2,085
Kerrick Staley
79,735,543
148,423
How to send multipart text and form parts with FastAPI TestClient?
<p>I'm working against an API specification outside my control. It expects to POST <code>multipart/form-data</code> to my server. Some parts are sent as files, some are sent as text.</p> <p>I want to write a test using <code>TestClient</code> that sends both a file and text parts.</p> <p>I don't have access to the exac...
<python><fastapi><multipartform-data><starlette>
2025-08-14 14:29:26
1
47,989
Joe
79,735,449
11,328,614
Conversion to int with Unicode strings
<p>I recognized that <code>int(unicode_string)</code> sometimes gives obscure results. E.g. <code>int('᪐᭒') == 2</code>.</p> <pre><code>&gt;&gt;&gt; bytes('᪐᭒', 'utf-8') b'\xe1\xaa\x90\xe1\xad\x92' &gt;&gt;&gt; [f'U+{ord(c):04X}' for c in '᪐᭒'] ['U+1A90', 'U+1B52'] </code></pre> <p>My expectation would be it fails, bec...
<python><string><unicode><integer>
2025-08-14 13:11:52
1
1,132
Wör Du Schnaffzig
79,735,272
735,926
How to avoid repeating type hints when overriding a parent method?
<p>I have this code:</p> <pre class="lang-py prettyprint-override"><code>class A: def f(self, a: int) -&gt; int: raise NotImplementedError class B(A): def f(self, a): return a </code></pre> <p>However <code>mypy --strict</code> tells me that <code>B.f</code> &quot;is missing a type annotation&q...
<python><python-typing><mypy>
2025-08-14 10:31:02
0
21,226
bfontaine
79,735,257
5,810,060
asyncio.run() cannot be called from a running event loop
<p>I have looked at previous answers and none of them seem to solve my issue. I am running the below code</p> <pre><code>from pyracing.client import Client import asyncio username = 'My Email Address' password = 'My Password' # Authentication is automated and will be initiated on first request ir = Client(username, p...
<python><python-3.x><runtime>
2025-08-14 10:13:21
1
906
Raul Gonzales
79,735,236
305,865
pypi caching in Artifactory
<p>we're evaluating using Artifactory as a proxy for pypi.org so we can whitelist packages for our developers, and prevent things like typosquatting.</p> <p>I was pleasantly surprised when inital setup of the repository cache (as described in <a href="https://jfrog.com/help/r/jfrog-artifactory-documentation/remote-repo...
<python><pip><artifactory><pypi>
2025-08-14 09:59:08
1
784
Zak
79,734,823
5,429,268
I'm trying to get two functions to run at the same time
<p>I'm trying to get my script to run two functions at the same time. But what happens is function2 will not start until function1 finishes.</p> <pre><code> import multiprocessing process1 = multiprocessing.Process(target=function1()) process1.start() process2 = multiprocessing.Process(target=function2()...
<python><python-3.x>
2025-08-13 23:29:13
1
563
BioRod
79,734,575
10,082,415
Retrieve per-class gradients without create_graph=True and retain_graph=True
<p>I am trying to keep track of the per-class gradients of 10k+ classes. Having <code>retain_graph=True</code> allows to access them but uses significant amount of memory. However, I am trying to figure out a way where I could have both <code>create_graph=False</code> and <code>retain_graph=True</code> while having acc...
<python><pytorch>
2025-08-13 17:29:40
0
1,003
M. Al Jumaily
79,734,526
857,741
Combining unittest with ddt.idata
<p>My tests are using an <code>@idata</code> decorator from the ddt package. I want to run only one of decorated test methods (<code>test01_...</code>) in the test class, not all of them. It conflicts with unittest notation of selecting tests: no approach <a href="https://stackoverflow.com/questions/15971735">listed th...
<python><unit-testing>
2025-08-13 16:16:41
0
6,914
LetMeSOThat4U
79,734,461
509,977
Why does Gmail API override the Date header even with internalDateSource: 'dateHeader' and deleted: true in users.messages.insert?
<p>I am working on a Python tool to migrate emails into Gmail while preserving the original Date header. My goal is simply to build a cli tool that allows to copy email from gmail account a to gmail account b, preserving all data and metadata (including date and time).</p> <p>I am using the Gmail API's users.messages.i...
<python><email><gmail-api>
2025-08-13 15:13:44
1
8,679
Pitto
79,734,370
3,909,202
How can I remove all legends from a matplotlib axes with multiple legends?
<p>Given a matplotlib plot with more than one legend, I would like to be able to remove all legends from the plot.</p> <p>Here is a simple example code to produce a plot with two legends:</p> <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt fig, ax = plt.subplots() # Plot some dummy dat...
<python><matplotlib>
2025-08-13 13:55:34
2
1,379
BernhardWebstudio
79,734,301
3,385,382
PettingZoo + Ray RLlib card game
<p>I created a simple card game for 2 players with PettingZoo and agents are trained with Ray RLlib (PPO). Game rules are:</p> <ul> <li>2 players, 32 cards (7 to ace)</li> <li>each trick both players play one card on table, higher card takes and that player plays next</li> <li>both players have 10 cards and after each ...
<python><artificial-intelligence><ray><pettingzoo>
2025-08-13 12:57:57
0
408
GMarco24
79,734,200
1,797,912
How to test the concrete method of an abstract class without manual subclassing?
<p>I have an abstract Python class with a concrete method:</p> <pre><code>class AbstractFoo(abc.ABC): def append_something(self, text: str) -&gt; str: return text + self.create_something(len(text)) @abc.abstractmethod def create_something(self, number: int) -&gt; str: raise NotImplementedEr...
<python><abstract-class>
2025-08-13 10:54:29
2
16,550
Chriki
79,734,128
15,980,284
using pydantic.logfire sending data to grafana-otel-container
<p>I am using lofgire to send traces, logs and metrics to grafana-otel container. However, in the grafana UI (reachable unter http://localhost:3000 and login is pw: admin &amp; user: admin), only traces and metrics but no logs are shown in the Drilldown menu.</p> <p>Here is my docker-compose to set up grafana-otel:</p>...
<python><grafana><pydantic><open-telemetry>
2025-08-13 09:38:56
0
1,303
JKupzig
79,733,788
11,462,274
How to rename and keep the window name fixed without updating when refreshing webpage? (Like Name window function in Chrome and Edge Browser)
<p>My current code opens the desired URL and rename the window to the string I prefer, but just update the page that is open to the browser and with that my personalized name is lost and the web page title is again:</p> <pre class="lang-python prettyprint-override"><code>import pygetwindow as gw import subprocess impor...
<python><window><rename><chromium><windows-11>
2025-08-13 02:05:32
0
2,222
Digital Farmer
79,733,777
3,163,618
Spelling Bee optimal word set search
<p>The NYT Spelling Bee game is a word game, where given 7 letters including 1 &quot;center letter&quot;, you find words at least 4 letters long that must use the &quot;center letter&quot;. The scoring is as follows: 4-letter words get 1 point, &gt;4-letter words get their length in points, and pangrams (using all 7 le...
<python><algorithm><search><a-star><discrete-optimization>
2025-08-13 01:25:30
1
11,524
qwr
79,733,745
5,631,449
How Do I Open A File in a Subclass of BufferedIOBase in Python
<p>I want to create my own reader class that is derived from BufferedIOBase. I'd like to have multiple 'open' class methods with differing parameters to create class instances, like this:</p> <pre><code>from __future__ import annotations import io class MyReader(io.BufferedIOBase): @classmethod def open1(c...
<python><io>
2025-08-13 00:27:05
0
1,006
BoCoKeith
79,733,680
388,520
`add_geometries` - how to automatically update extent of axis to include the geometry
<p>I want to draw shapes on a cartopy <code>GeoAxis</code> and have the extent of the plot automatically update so that all of the shapes are fully visible. Simply calling <code>ax.add_geometries([shapes], crs, ...)</code> does not update the plot extent to include the shape. What do I need to do to get the plot exte...
<python><cartopy>
2025-08-12 21:40:33
3
142,389
zwol
79,733,411
639,361
Azure Cache for Redis randomly throws WRONGPASS
<p>I have a Django website running as an Azure Web App, which is uzing Azure Cache for Redis.</p> <p>We use a Managed Identity to connect to Azure Cache for Redis so we do not need to use access keys.</p> <p>The application itself is running in gunicorn so as multiple threads.</p> <p>There is a health check, being call...
<python><azure><redis>
2025-08-12 15:44:36
0
475
Maarten Ureel
79,733,367
7,995,302
rpy2 on Windows prints “Error importing in API mode … only ABI” — how to force ABI mode and suppress the message across Flask and pytest?
<p>I’m developing a Flask app on Windows that calls R via rpy2. On every run or during pytest collection I see this message:</p> <pre><code>Error importing in API mode: ImportError('On Windows, cffi mode &quot;ANY&quot; is only &quot;ABI&quot;.') Trying to import in ABI mode. </code></pre> <p>I understand this isn’t a ...
<python><windows><flask><rpy2><cffi>
2025-08-12 15:06:41
0
961
Naser Nikzad
79,733,202
2,413,767
Trying to use Autofac in python 3.12 is triggering cannot be converted to type error
<p>I'm tasked with converting some legacy python code to Python 3.12.Before it was using .DotNet to import .net dlls, not due to version contraints I'm using clr. However where the old code worked i'm having trouble resolving a SimpleJsonSerializer.</p> <p>This is the error:</p> <pre><code>&quot;Object of type 'System....
<python><autofac><clr>
2025-08-12 12:45:56
0
1,011
John
79,733,200
6,386,155
How do I load joblib file on spark?
<p>I have following Code. It reads a pre-existing file for a ML model. I am trying to run it on databricks on multiple cases</p> <pre><code>import numpy as np import joblib class WeightedEnsembleRegressor: &quot;&quot;&quot; Holds models, their weights, scaler and feature order for prediction &amp; persistence....
<python><pyspark><databricks><pickle><user-defined-functions>
2025-08-12 12:40:48
1
885
user6386155
79,733,185
1,136,807
Add prefix to all URLs while using Blueprint
<p>I am trying to prefix all endpoints with <code>/api/</code>, but I am getting 404 in return if not providing directly in the URL or while registering <code>blueprint</code>.</p> <p>main.py</p> <pre class="lang-py prettyprint-override"><code>from init import app from modules.User import User app.register_blueprint(...
<python><flask><endpoint><prefix><blueprint>
2025-08-12 12:33:27
1
2,035
Mr.Singh
79,732,697
1,162,409
CORS issue with Google ADK runnning as server and consuming from react app
<p>I’m working on a React application that needs to interact with the Google ADK. Since the ADK enables agent invocation via the API server, I’ll be following the instructions outlined in the documentation here: - <a href="https://google.github.io/adk-docs/get-started/testing/#run-agent-single-response" rel="nofollow n...
<python><google-gemini><google-agent-development-kit>
2025-08-12 04:20:36
2
17,406
San Jaisy
79,732,475
11,159,734
Is there an issue with starting a FastAPI backend within Docker using uv run main.py?
<p>I'm setting up a FastAPI backend with Docker on my machine (will be deployed to Azure later as well) right now. All examples I have seen including the <a href="https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile" rel="nofollow noreferrer">official uv docker example</a> start the backend like this in ...
<python><docker><fastapi><uv>
2025-08-11 20:14:14
1
1,025
Daniel
79,732,371
850,781
Column level alignment in pandas DataFrame printing
<p>When a pandas <code>DataFrame</code> is printed, the <code>MultiIndex</code> column levels are aligned with the 1st (left most) column instead of the last (right most) column:</p> <pre><code>import numpy as np import pandas as pd df = pd.DataFrame( [np.arange(6), np.arange(6)+5], columns=pd.MultiIndex.from_...
<python><pandas><dataframe><printing>
2025-08-11 18:26:30
0
60,468
sds
79,732,064
3,909,202
How can I have a matplotlib legend span the plot areas of the subplots?
<p>I want to have the shared legend of multiple subplots take the width of the plot areas of the subplots.</p> <p>Here is an illustration:</p> <p><a href="https://i.sstatic.net/E4M2mxaZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/E4M2mxaZ.png" alt="Illustration of where the legend shall be" /></a></p...
<python><matplotlib>
2025-08-11 12:48:13
2
1,379
BernhardWebstudio
79,732,011
3,938,402
Convert XML to JSON using xmltodict package
<p>I'm trying to convert the below XML file to JSON using <code>xmltodict</code> package but getting Expat syntax error</p> <p><code>abc.xml</code>:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;testsuites tests=&quot;1&quot; failures=&quot;0&q...
<python><xmltodict><xml-to-json>
2025-08-11 11:42:53
2
4,026
Harry
79,731,908
5,197,329
Type hinting returned array shape using class attributes
<p>I am trying to create the following type hints in Python, but I have thus far been unable to find a way to actively use my class attributes as type hints:</p> <pre><code>@dataclass class MyClass: x: int y: int def my_method(self) -&gt; np.ndarray([tuple[self.x, self.y], np.float32]): pass </code>...
<python><numpy><python-typing>
2025-08-11 09:53:24
1
546
Tue
79,731,839
13,944,524
UV package manager cannot find my workspace member
<p>I intended to use <code>git submodule</code> to bring my other source code(<code>backend</code>) into <code>my-app</code>. Then I wanted utilize <a href="https://docs.astral.sh/uv/concepts/projects/workspaces/" rel="nofollow noreferrer"><code>uv</code>'s workspace</a> so that it manages the dependencies of both <cod...
<python><uv>
2025-08-11 08:41:43
0
17,004
S.B
79,731,713
2,828,086
AttributeError: module 'igl' has no attribute 'tet_tet_adjacency'
<p>When I try to run the <code>example.py</code> <a href="https://github.com/sgsellan/fracture-modes/blob/main/scripts/example.py" rel="nofollow noreferrer">script</a> from <a href="https://github.com/sgsellan/fracture-modes" rel="nofollow noreferrer">this repo</a>, I get the error <code>AttributeError: module 'igl' ha...
<python><attributeerror><libigl>
2025-08-11 06:26:16
1
6,724
albusdemens
79,731,634
3,179,698
No way to quit IPython debugger's interactive mode in jupyterhub notebook
<p>So I import a module:</p> <pre><code>from IPython.core.debugger import Pdb </code></pre> <p>Then I initiate an object for debugging:</p> <pre><code>ipdb = Pdb() </code></pre> <p>I define a function to test debug mode:</p> <pre><code>def f(a=1): ipdb.set_trace() print(a) </code></pre> <p>After I run the funct...
<python><jupyter-notebook><jupyterhub>
2025-08-11 03:26:42
1
1,504
cloudscomputes
79,731,614
3,822,232
ValueError: variable agent_scratchpad should be a list of base messages, got of type <class 'str'>
<p>This is a very basic example how I am trying to use langchain to invoke a llm and find the tool to use:</p> <pre><code>import asyncio import json from langchain.agents import AgentExecutor, create_structured_chat_agent, Tool from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_co...
<python><langchain><valueerror><py-langchain><langchain-agents>
2025-08-11 02:04:39
2
389
hitesh
79,731,607
852,795
plt.imshow() causes Jupyter notebook kernel to crash
<p>I'm following Karpathy's Makemore tutorial step by step. When I get to the <a href="https://youtu.be/PaCmpygFfXo?si=l7XEFpOyZrPN6lSB&amp;t=1117" rel="nofollow noreferrer">part</a> where he uses plt.imshow(N) to create a plot inside the notebook, my kernel crashes. I've been troubleshooting this for half the day, inc...
<python><matplotlib><jupyter-notebook>
2025-08-11 01:43:40
0
2,904
Mark Cramer
79,731,600
344,286
Why does my Django models.Manager return all objects on a relationship?
<p>I don't particularly understand what's going on here, but it seems that <code>super().get_queryset()</code> doesn't do what I think it does?</p> <p>I have 1:N relationship, and the default FK reverse lookup works:</p> <pre><code>&gt;&gt;&gt; for thing in this.thing_set.all(): ... print(thing.this) </code></pre> <p...
<python><django><foreign-keys>
2025-08-11 01:27:34
3
52,263
Wayne Werner
79,731,216
3,144,092
Function call with OpenAI Agent SDK with Ollama fails
<p>I'm having trouble getting function call working with OpenAI Agent SDK and Ollama. Suggestions/Solutions would be of great help. Thank you.</p> <p>Using UV, python-12 and added <code>&quot;openai&gt;=1.68.2&quot;</code> and <code>&quot;openai-agents&gt;=0.0.15&quot;</code> dependencies to the project.</p> <p>Below i...
<python><openai-api><agent><openai-agents>
2025-08-10 12:41:28
1
391
Dileep17
79,731,196
3,938,402
Generate XML file using ElementTree API
<p>I'm trying to generate the below XML file using the data populated in a list:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;testsuites tests=&quot;65&quot; failures=&quot;0&quot; disabled=&quot;0&quot; errors=&quot;0&quot; name=&quot;AllTest...
<python><xml><elementtree>
2025-08-10 11:54:47
1
4,026
Harry
79,730,861
530,160
What coordinate transform does scipy.integrate.quad use for infinite bounds?
<p>In SciPy's quad function, it is possible to integrate over an integral with infinite bounds.</p> <pre><code>import scipy import numpy as np def normal_distribution_pdf(x): return np.exp(-x**2 / 2) / np.sqrt(2 * np.pi) result, eps, info = scipy.integrate.quad(normal_distribution_pdf, 0, np.inf, full_output=True...
<python><scipy><quad>
2025-08-09 20:12:03
1
27,892
Nick ODell
79,730,688
11,462,274
Using Python, how to continue opening new URLs in a specific Edge window even if another Edge window is in the foreground?
<p>Using this default model, if I separate one of these URLs in a new window and use it for reading, the next URL open will open in the window I've separated for reading, obviously hindering my reading.</p> <p>Is there a way to set a specific window as the primary one that will open all new tabs, and the ones I separat...
<python><tabs><microsoft-edge><windows-11><python-webbrowser>
2025-08-09 14:52:57
2
2,222
Digital Farmer
79,730,585
237,105
sympy unable to take simple integral
<p>I'm trying to take the following integral using sympy and it won't take it:</p> <pre><code>&gt;&gt;&gt; from sympy import * &gt;&gt;&gt; integrate(x*exp(-(x-x0)**2), (x, 0, k)) </code></pre> <img src="https://i.sstatic.net/VvnI8lth.png" width="200"/> <p>If I 'help' it by adding and subtracting the same expression, i...
<python><sympy><symbolic-math><integral>
2025-08-09 11:33:48
1
34,425
Antony Hatchkins
79,730,533
19,130,803
Version unsupported imbalanced-learn
<p>I am trying to install <code>scikit-learn</code> and <code>imbalanced-learn</code> for ML project using <code>poetry</code>.</p> <pre><code># File pyproject.toml [project] name = &quot;hello&quot; version = &quot;0.1.0&quot; description = &quot;&quot; authors = [ {name = &quot;&quot;,email = &quot;&quot;} ] rea...
<python><scikit-learn>
2025-08-09 09:48:38
2
962
winter
79,729,951
4,613,734
How to make a python package that can have two different version of a dependency?
<p>It is now not uncommon to have a python package that is distributed in a multitude of different &quot;flavors&quot;. This happens often with machine learning packages, e.g. <code>onnxruntime</code> has many &quot;flavors&quot; <code>onnxruntime</code>, <code>onnxruntime-gpu</code>, <code>onnxruntime-directml</code>,...
<python><dependencies><xgboost><packaging><onnxruntime>
2025-08-08 15:17:59
1
385
MajorTom
79,729,734
967,330
While installing pytorch, got missing file that exists
<p>I am running Ubuntu 22.04 and I've backed python back to 3.10.12 so I can install audio X. I've never worked much with python.</p> <p>I ran the command <code>pip install aeiou</code> and, after doing a bunch of things, it gets to torch and says.</p> <pre><code> ... many moving lines omitted ... Moving to /home/th...
<python><pip><pytorch>
2025-08-08 11:59:23
1
15,310
Thom
79,729,500
13,392,257
Sqlalchemy delete on table "tasks" violates foreign key constraint for cascade mode
<p>I have the following postgres table</p> <pre><code>dbname=# \d+ tasks Table &quot;public.tasks&quot; Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------------------+--------------------...
<python><postgresql><sqlalchemy>
2025-08-08 08:24:50
0
1,708
mascai
79,729,416
13,184,183
How to filter values from struct by field in pyspark?
<p>I wonder how I can filter out objects from struct by condition that their id is in list presented in other column.</p> <p>Suppose I have dataframe <code>df</code> with columns <code>event</code> which has the type of list of <code>Struct</code> with fields <code>id</code> and <code>time</code>. There is another colu...
<python><pyspark>
2025-08-08 06:52:40
1
956
Nourless
79,729,226
9,541,464
How to release memory of intermediate Python-Polars DataFrames in a large dependency graph?
<p>I am performing operations on a <em>directed acyclic graph</em> (DAG) of DataFrames using <strong>Polars</strong> (eager API).</p> <p>Here’s a simplified example of my workflow:</p> <ol> <li>Read parquet files into <code>df1</code>.</li> <li>Use <code>df1</code> to create <code>df2</code> and <code>df3</code>.</li> ...
<python><garbage-collection><out-of-memory><python-polars><memory-optimization>
2025-08-08 00:27:18
2
1,022
Deep Ghodasara
79,729,174
6,197,439
Preventing unexpected trigger of setModelData and setData in QTableView with QComboBox?
<p>The code below mostly does what I want: I start out with data of 2D table (list of lists), where 1st and 3rd column start out as random numbers, but 2nd column starts with <code>None</code>. This data is used for a table model of a QTableView, which for the cells in the 2nd <code>None</code> column, displays QComboB...
<python><pyqt5><qt5><qtableview>
2025-08-07 22:19:23
1
5,938
sdbbs
79,729,089
356,011
A generated protobuf python file is unable to locate another protobuf module it generated
<p>I have a project set up like this with <code>protos/</code> as a top level directory and the project that actually builds it under <code>services/common-py</code>.</p> <pre class="lang-none prettyprint-override"><code>├── protos │   ├── common.proto │   ├── doodad.proto └── services └── common-py ├── my_...
<python><protocol-buffers><protobuf-python>
2025-08-07 20:02:29
0
8,429
Paul C
79,729,083
199,818
Unable to install our Poetry plugin: pip says there is no matching distribution found
<p>I wrote a Poetry plugin and have it stored on a company PyPI repo. I am working on a Python project using Poetry and want to use my plugin. I though specifying the company repo with <code>tool.poetry.source</code> and then adding a line to</p> <pre class="lang-toml prettyprint-override"><code>[tool.poetry.requires-p...
<python><pip><python-poetry>
2025-08-07 19:57:02
0
857
Ian Leslie
79,729,078
9,397,585
How to correctly pass float4 vector to kernel using PyCUDA?
<p>I am trying to pass a float4 as argument to my cuda kernel (by value) using PyCUDA’s <code>make_float4()</code>. But there seems to be some misalignment when the data is transferred to the kernel. If I read the output for an input (1,2,3,4) I instead get (3,4,0,0). This happens with <code>int4</code> as well, but <c...
<python><cuda><gpu><nvidia><pycuda>
2025-08-07 19:49:21
1
308
Dodilei
79,728,808
458,738
Does peewee ORM have a native way to include table/columns descriptions/comments?
<p>Does <a href="https://pypi.org/project/peewee" rel="nofollow noreferrer">peewee ORM</a> have a native way to include table/columns descriptions/comments?</p> <p>If not, what would be the preferred way to add comments to db objects?</p> <p>Thank you for your help.</p>
<python><orm><peewee>
2025-08-07 15:25:01
0
579
cytochrome
79,728,690
11,063,709
How is the execution of Jax and non-Jax parts interleaved in a Python program and when does an abstract value become concrete?
<p>I have the following code:</p> <pre><code>def non_jitted_setup(): print(&quot;This code runs once at the beginning of the program.&quot;) return jnp.array([1.0, 2.0, 3.0]) class A: @partial(jax.jit, static_argnums=0) def my_jitted_function(self, x): print(&quot;This code runs once during ...
<python><jax>
2025-08-07 13:58:00
1
1,442
Warm_Duscher
79,728,678
2,307,934
How to make a left join in an update with sqlalchemy and mysql?
<p>I am trying to craft a query with SQLAlchemy 2.5. My main goal is to do an update while :</p> <ul> <li>doing a join on a &quot;parent&quot; table</li> <li>and doing a left join between the &quot;parent&quot; table and a third table</li> </ul> <p>I can't seem to make this work : I am always having either errors or Ca...
<python><mysql><sqlalchemy>
2025-08-07 13:47:41
1
1,240
edg
79,728,412
8,290,689
Add autocomplete for tcsh shell in python script using click
<p>I want to add autocomplete for tcsh on naval example of click: <a href="https://github.com/pallets/click/tree/main/examples/naval" rel="nofollow noreferrer">https://github.com/pallets/click/tree/main/examples/naval</a></p> <p>I started to add this:</p> <pre class="lang-py prettyprint-override"><code>_tcsh_source = &...
<python><command-line-interface><click>
2025-08-07 10:26:54
0
312
Tradjincal
79,728,399
1,719,931
Undocumented pandas DataFrame shuffle()
<p>The following seems to work:</p> <pre><code>import pandas as pd import sklearn df = sklearn.datasets.load_iris() df = pd.DataFrame(df.data, columns=df.feature_names) df.shuffle() </code></pre> <p>However this <code>shuffle</code> function seems <a href="https://pandas.pydata.org/docs/search.html?q=shuffle" rel="nofo...
<python><pandas><dataframe><shuffle>
2025-08-07 10:18:13
2
5,202
robertspierre
79,728,364
15,993,687
python standalone builds causes problem with pillow tkinter
<p>I am trying to embed python standalone builds to my electron app. I downloaded standalone from <a href="https://github.com/astral-sh/python-build-standalone" rel="nofollow noreferrer">https://github.com/astral-sh/python-build-standalone</a></p> <p>Everything seems to work fine until pillow is installed. While the in...
<python><tkinter><electron><python-imaging-library>
2025-08-07 09:35:24
1
3,141
Art
79,728,358
5,232,323
Selenium can't get performance log in iframe of google spreadsheets
<p>Environment: ChromeDriver 138.0.7204.168 Chrome 138.0.7204.184 Selenium 4.34.2 Windows 11</p> <p>I shared a spreadsheet by iframe, and embeded it to a web page a.html:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;iframe src=&quot;https://docs.google.com/spreadsheets/d/e/2PACX-1vQ...
<python><google-chrome><selenium-webdriver><iframe>
2025-08-07 09:25:11
1
2,471
tinyhare
79,728,153
9,223,023
What is the length of a python bytecode instruction in CPython?
<p>Python docs on the dis module state that the length of a python bytecode instruction in CPython is 2 bytes (<a href="https://docs.python.org/3/library/dis.html" rel="nofollow noreferrer">https://docs.python.org/3/library/dis.html</a>)</p> <p>However, when I disassemble a function and look at the actual bytecode, I s...
<python><bytecode><python-internals>
2025-08-07 06:46:31
1
1,203
Petras Purlys
79,728,136
11,640,299
Issue with running training on multigpu using DDP
<p>I am training a classifier model but since it is taking far too long I want to use multigpu for the training. The current code is</p> <pre><code>rank = int(os.environ[&quot;RANK&quot;]) world_size = int(os.environ[&quot;WORLD_SIZE&quot;]) local_rank = int(os.environ[&quot;LOCAL_RANK&quot;]) torch.cuda.set_device(lo...
<python><multi-gpu><ddp>
2025-08-07 06:25:00
0
342
Shlok Sharma
79,727,981
1,977,587
Cartesian product for both keys and values of a dictionary?
<p>I need to get the Cartesian product of a dictionary <code>{str: Fraction}</code> with itself, but currently need to &quot;loop&quot; through the dict twice, once for the keys and once for the values.</p> <p>The difference is that a tuple output works well for the keys, but for the values I actually need the regular ...
<python><for-loop><python-itertools>
2025-08-07 01:27:20
4
1,770
Ameya
79,727,814
10,663,096
python+asyncpg+PostgreSQL returns jsonb column as a string instead of an object
<p>I'm new to python and just came to a problem: i've set up a simple program to fetch some data from PostgreSQL database. They say that asyncpg library automatically converts JSONB data to Python objects (dicts/lists) by default. This doesn't happen in my case when I select data from a table. I've made synthetic examp...
<python><postgresql><jsonb><asyncpg>
2025-08-06 20:25:08
2
310
CoderFF
79,727,651
11,160,879
Reading an IBM PIC S9(09) COMP data from file in python
<p>I was given sample data by the mainframe engineer, for which the COPYBOOK looks like below:</p> <pre><code>01 CCS001-DETAIL-RECORD. 05 CCS001-REC-TYPE PIC X(01). Should be '1' 05 CCS001-MEMB-NUM PIC S9(09) COMP. 05 CCS001-PR-CAT PIC X(03). 05 CCS001-C...
<python><db2><endianness><cobol><copybook>
2025-08-06 17:33:11
1
323
dijeah
79,727,612
4,200,997
Setting os.environ["TMP"] works in the code but not in pytest tests
<p>I have the following python code:</p> <pre class="lang-py prettyprint-override"><code>import tempfile import os def test_paul_confused(): os.environ[&quot;TMP&quot;] = &quot;/home/fedora&quot; assert tempfile.gettempdir() == &quot;/home/fedora&quot; print(tempfile.gettempdir()) test_paul_confused() </c...
<python><pytest><temporary-files>
2025-08-06 16:57:37
1
3,796
Paul Dejean
79,727,568
186,202
How to expose Enum to FastAPI OpenAPI schema?
<p>We are using Pydantic's BaseModel to define a discriminated configuration for our provider by type.</p> <pre class="lang-py prettyprint-override"><code>class Provider(StrEnum): ANTHROPIC = &quot;anthropic&quot; GROQ = &quot;groq&quot; OPENAI = &quot;openai&quot; class BaseConfig(BaseModel): provide...
<python><enums><fastapi><openapi>
2025-08-06 16:12:49
1
18,222
Natim
79,727,531
12,461,032
TypeError: PPOTrainer.__init__() got an unexpected keyword argument 'config'
<p>I am trying to initialize a <code>PPO_trainer</code> but have issues.</p> <pre><code>from trl import PPOTrainer, PPOConfig ppo_config = PPOConfig( batch_size=4, learning_rate=1e-5, mini_batch_size=2, use_cpu=True ) ppo_trainer = PPOTrainer( config=ppo_config, model=model, tokenizer=toke...
<python><large-language-model><huggingface>
2025-08-06 15:43:07
0
472
m0ss
79,727,484
13,392,257
How to obtain familysearch.com token without entering login and password
<p>I am using the following code to obtain FamilySearch API token (according to the documentation <a href="https://developers.familysearch.org/main/docs/authentication" rel="nofollow noreferrer">https://developers.familysearch.org/main/docs/authentication</a> )</p> <p>During authentication I have to manually enter logi...
<python><oauth-2.0><familysearch-api>
2025-08-06 15:04:44
0
1,708
mascai
79,727,284
4,691,830
Restrict date selection from calendar to specific dates
<p>I'd like to let the user pick one out of a list of dates from my calendar but prevent her from selecting any other date.</p> <p>Based on <a href="https://stackoverflow.com/a/60203462/4691830">this answer</a> I managed to restrict the date range that can be selected but I couldn't exclude days in between.</p> <pre cl...
<python><tkinter><tkcalendar>
2025-08-06 12:34:56
2
4,145
Joooeey
79,727,218
240,976
simplest jinja2 template loading for one-file python script
<p>I'm using Python only for simple scripts and every time I look into Python packaging, there is a new standard or technologie.</p> <p>Now when I develop a small one-file tool and want to load a jinja2 template, I don't know how.</p> <p>I could use <a href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.FileS...
<python><jinja2><python-packaging>
2025-08-06 11:38:12
1
2,941
Thomas Koch
79,727,190
7,475,838
adjust plotnine legend (swap order)
<p>I'm trying to recreate the following graph with <a href="https://plotnine.org/" rel="nofollow noreferrer">plotnine</a>:</p> <p><a href="https://i.sstatic.net/AJxZTtZ8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AJxZTtZ8.png" alt="enter image description here" /></a></p> <p>And... I'm almost there:...
<python><ggplot2><python-polars><plotnine>
2025-08-06 11:07:39
2
4,919
René
79,726,988
3,447,369
FastAPI endpoint stream LLM output word for word
<p>I have a FastAPI endpoint (<code>/generateStreamer</code>) that generates responses from an LLM model. I want to stream the output so users can see the text as it’s being generated, rather than waiting for the full response. Currently, I'm using TextIteratorStreamer from the transformers library and FastAPI's Stream...
<python><fastapi><huggingface-transformers><large-language-model>
2025-08-06 08:05:27
3
1,490
sander
79,726,980
11,173,364
undefined symbol: PyObject_SelfIter while using CPython C API
<p>I want to use CPython C API but still got this</p> <pre><code>[component_container-1] Traceback (most recent call last): [component_container-1] File &quot;/usr/local/lib/python3.10/dist-packages/numpy/core/__init__.py&quot;, line 24, in &lt;module&gt; [component_container-1] from . import multiarray [componen...
<python><c++><cmake><cpython><pyobject>
2025-08-06 07:49:11
0
769
user900476
79,726,783
19,459,262
How to modify the colors of individual input_slider?
<p>I have sliders in my app and I want to change the colors individually. How can I do this? I'm using custom CSS to hack my way around for checkboxes and radio buttons, but I haven't been able to do this for sliders.</p> <p>Sliders:</p> <pre><code>ui.input_slider(&quot;red&quot;, &quot;red&quot;, value=0, min=0, max=5...
<python><css><py-shiny>
2025-08-06 03:31:14
1
784
Redz
79,726,701
2,552,290
user-defined lazy mpmath constants
<p>Can I define my own lazy mpmath constants, just like <a href="https://mpmath.org/doc/0.19/functions/constants.html" rel="nofollow noreferrer">mpmath.pi and the others documented here</a>?</p> <p>In other words, can I define a constant whose value is an mpf or mpc computed (or retrieved from memo cache) to the curren...
<python><lazy-evaluation><mpmath>
2025-08-06 00:35:52
0
5,611
Don Hatch
79,726,698
4,539,999
Extract White Input Boxes from pdf
<p>Some of the Adobe XFA form fields are missing when the <code>/PageItemUIDToLocationDataMap</code> is extracted from some pdf files as shown on the image below where only fields identified with black dots for pages 1 and 3 (Click image to open pdf) are shown. How can the missing XFA form fields be extracted without u...
<python><pdf><pymupdf><pikepdf>
2025-08-06 00:29:01
1
1,435
flywire
79,726,627
2,471,211
Lambda container - Pyarrow and numpy
<p>I have difficulties from this: <a href="https://github.com/aws/aws-cdk/issues/34685" rel="nofollow noreferrer">(aws-lambda-python-alpha): Failed to install numpy 2.3.0 with Python 3.11 or lower</a></p> <p>My Dockerfile:</p> <pre class="lang-none prettyprint-override"><code>FROM public.ecr.aws/lambda/python:3.11 # I...
<python><numpy><aws-lambda><pyarrow>
2025-08-05 21:37:23
1
485
Flo
79,726,616
1,604,008
cant find element with Selenium
<p><a href="https://i.sstatic.net/tCKqgUFy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tCKqgUFy.png" alt="screen shot" /></a></p> <p>I'm getting the following</p> <pre><code>An error occurred: Message: Stacktrace: RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8 WebDriverError@chrom...
<python><selenium-webdriver>
2025-08-05 21:06:48
2
1,159
user1604008
79,726,515
25,874,132
What's wrong with this Python assignment on signal processing - mostly Fourier series and transform
<p>In this assignment I created the basic rect signal <code>a[n]</code> such that over the domain [-1000, 1000] it's 1 only at |n|&lt;100, meaning it's an array (complex one with zero in the imaginary part) that looks like this [0, 0, ... 0, 0, 1, 1, ... 1, 1, 0, ... 0, 0, 0] where there are exactly 199 ones, 99 on pos...
<python><numpy><signal-processing><fft>
2025-08-05 18:31:08
2
314
Nate3384
79,726,327
850,781
How to reclaim horizontal space made available by removing labels and ticks?
<p>I have a row of subplots which start with a histogram and the rest are some <a href="https://www.statsmodels.org/stable/generated/statsmodels.graphics.gofplots.qqplot.html" rel="nofollow noreferrer"><code>qqplot</code></a>s:</p> <p><a href="https://i.sstatic.net/kj4U3hb8.png" rel="nofollow noreferrer"><img src="http...
<python><matplotlib><whitespace><subplot>
2025-08-05 15:22:19
1
60,468
sds
79,726,242
25,413,271
python gmsh: build 3D mesh from solid-split stl surface for openFOAM
<p>I have a simple task- I have a closed stl-surface, the whole surface is split into solids. I need to use python gmsh pack to build 3D mesh (tetra or hexa) with named-selections (lets call it this way) for BC patches according to solids from STL. I need to use this for openFOAM calculation. I am very new in gmsh.</p>...
<python><stl><gmsh>
2025-08-05 14:10:15
0
439
IzaeDA
79,726,067
11,160,879
Convert an integer to IBM PIC S9(09) COMP. type in python
<p>I have the following three values in a CSV file:</p> <pre><code>1683199814 2087175640 1348771152 </code></pre> <p>I need to write them into a flat file using a python program, which will be loaded into Mainframe DB2 using a COBOL program.</p> <p>The copybook says that it is of type <code>PIC S9(09) COMP</code>. Th...
<python><db2><endianness><cobol>
2025-08-05 11:51:40
0
323
dijeah
79,726,058
13,933,721
pydantic model validator raise ValueError to field
<p>I am trying to do a validation on passwords where if they dont match, return an error. But I want to assign the error to field.</p> <pre><code>class RequestFile( BaseModel ): password: str = Field(..., min_length=8, max_length=128) confirm_password: str = Field(..., min_length=8, max_length=128) @fi...
<python><pydantic><pydantic-v2>
2025-08-05 11:46:46
2
1,047
Mr. Kenneth