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,607,373
12,349,734
How to exclude thinking steps when streaming from `google/gemini-2.5-flash-preview:thinking` via OpenRouter and OpenAI library?
<p>I am using the <a href="https://github.com/openai/openai-python" rel="nofollow noreferrer"><code>openai</code> Python library</a> to stream chat completions from the <a href="https://openrouter.ai/google/gemini-2.5-flash-preview:thinking" rel="nofollow noreferrer"><code>google/gemini-2.5-flash-preview:thinking</code...
<python><openai-api><google-gemini><openrouter>
2025-05-05 17:20:48
2
20,556
MendelG
79,607,292
6,281,366
dealing with reading/writing large files inside a k8s pod with a memory limit
<p>I have several applications that run inside a k8s pod, where the pod has a specific memory limit.</p> <p>I noticed that if i run a python script that deal with a large file, e.g: unzip a large file example.zip, the pod memory usage really spikes. As i understand, even if i use an unzip function that uses streaming, ...
<python><linux><kubernetes><out-of-memory>
2025-05-05 16:22:01
0
827
tamirg
79,607,128
525,341
PyICU import halts Python interpreter on Windows 11 23H2
<p>I was experiencing problems similar to <a href="https://stackoverflow.com/questions/68349833/pip-cant-install-pyicu">well-known issues</a> while installing <code>PyICU</code>. By following <a href="https://stackoverflow.com/a/47444689/525341">community hints</a> I was able to succeed in installing the corresponding ...
<python><python-3.x><icu>
2025-05-05 14:31:49
0
768
Olemis Lang
79,607,084
893,254
How do I create a 2-dimensional numpy array object with zero size?
<p>I want to create a 2-dimensional <code>numpy</code> array object to store image data.</p> <p>The way the image data will be constructed is by continually appending blocks of 2-dimensional data to this array.</p> <p>I tried this sequence of steps:</p> <ol> <li>Create an empty <code>numpy.array</code> with the correct...
<python><numpy>
2025-05-05 14:09:46
2
18,579
user2138149
79,607,054
2,361,979
Python not receiving UDP packets
<p>I have a Python application which wants to receive UDP packets like this:</p> <pre><code>with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.bind((ip, port)) s.settimeout(0.1) while self.shall_run: try: data, addr = s.recvfrom(1024) self.packets.append(data) except so...
<python><windows><sockets><network-programming><udp>
2025-05-05 13:50:49
0
1,193
qznc
79,606,898
4,718,423
importlib resources files -> not a package, empty module
<p>I tend to alwasy run the testers from inside the module folder, but this breaks the &quot;resources.files&quot; functionality, as it seems not to be able to find the module any more</p> <p><strong>module folder</strong></p> <pre><code>my_package/ __init__.py package.py test_package.py </code></pre> <p><s...
<python><python-unittest><python-importlib>
2025-05-05 12:19:00
0
1,446
hewi
79,606,838
774,575
QListWidget drag and drop configuration: When to use the mode instead of the drag/drop properties?
<p>I'm learning how to setup drag and drop in the <a href="https://doc.qt.io/qt-6/model-view-programming.html#the-model-view-classes" rel="nofollow noreferrer">view-model framework description</a> at Qt site. When applied to convenience views (<code>QListWidget</code>, <code>QTableWidget</code>, <code>QTreeWidget</code...
<python><c++><qt><drag-and-drop>
2025-05-05 11:35:34
1
7,768
mins
79,606,785
29,295,031
Select a range of data based on a selected value using Pandas
<p>I have a dataframe, I need to select a range of data based on a month value, but the result expected is always showing six rows where the month selected appears in the filtered data , here's the code :</p> <pre><code>import pandas as pd data = { &quot;function&quot;: [&quot;test1&quot;,&quot;test2&quot;,&quot;t...
<python><pandas><dataframe>
2025-05-05 10:52:38
1
401
user29295031
79,606,757
3,248,423
How to invoke a Gemini Fine tuned (via Vertex AI) model in Google ADK Agent
<p><strong>Problem Statement</strong>: I fine-tuned a google's gemini flash 2.0 model via GCP Vertex AI. But I am unable to invoke the endpoint of that fine-tuned model trained on my own data in the below agent.py. I have provided all the code I have so far below:-</p> <p>This is my agent.py</p> <pre><code>import os fr...
<python><artificial-intelligence><google-cloud-vertex-ai><fine-tuning>
2025-05-05 10:33:55
0
653
Seth
79,606,665
9,471,909
Extract header from the first commented line in NumPy via numpy.genfromtxt
<p>My environment:</p> <pre><code>OS: Windows 11 Python version: 3.13.2 NumPy version: 2.1.3 </code></pre> <p>According to <a href="https://numpy.org/doc/stable/user/basics.io.genfromtxt.html#the-comments-argument" rel="nofollow noreferrer">NumPy Fundementals</a> guide describing how to use <code>numpy.genfromtxt</code...
<python><numpy><genfromtxt>
2025-05-05 09:32:54
3
1,471
user17911
79,606,651
587,587
How can I use a wx.FileDialog to select a file which is locked by another process
<p>I'm trying to use the wx.FileDialog class to select the <em>name</em> of a file. I don't want to open it. This is a minimal example of what I'm trying to do:</p> <pre><code>import wx if __name__ == '__main__': app = wx.App(redirect=False) frame = wx.Frame(None) frame.Show() dlg = wx.FileDialog(pare...
<python><windows><wxpython><wxwidgets>
2025-05-05 09:26:25
2
492
Anton Lahti
79,606,646
5,197,329
Using logical operators in pytest expected results
<p>I'm trying to develop pytest for a project, and while I'm not the most familiar with pytest I feel like I have a fairly basic understanding.</p> <p>In this particular case I am testing some code that does route optimization and I wish to implement a bunch of different tests to ensure that the code performs as it sho...
<python><unit-testing><pytest>
2025-05-05 09:23:57
1
546
Tue
79,606,460
9,187,882
Wrapping a python sub process
<p>I would like to wrap an external process with a python subprocess to add a control on the input and output. I created a small wrapper program, and managed to change the input and output send to the internal process when I need it. I couldn't return output without calling the inner process - see the TODO inside my co...
<python><subprocess><python-asyncio>
2025-05-05 07:04:38
1
828
Ori N
79,606,002
356,887
How to prevent keyboard even delay in python terminal app
<p>I'm making a python game with a terminal UI, using the <a href="https://blessed.readthedocs.io/en/latest/intro.html" rel="nofollow noreferrer">blessed</a> library. When I process a key held down, I receive the first key immediately, but then there's a delay between the first and subsequent keys received. Here is my ...
<python><windows><keyboard-events>
2025-05-04 20:02:49
0
10,163
xdhmoore
79,605,930
9,626,243
How to create simple webrtc server to browser stream example in python?
<p>I'm trying to write simple python server to browser video streamer using aiortc? For simplicity the server and the browser are in one local network.</p> <p>The python code:</p> <pre><code>import asyncio from aiortc import RTCPeerConnection, RTCSessionDescription, VideoStreamTrack from av import VideoFrame import num...
<javascript><python><webrtc><aiortc>
2025-05-04 18:24:03
1
570
Vitaliy Tsirkunov
79,605,867
1,521,512
Is this a greedy algorithm and if so, why?
<p>I'm working through &quot;Competitive Programming 4&quot; by &quot;Halim et al.&quot; and in the topic &quot;Greedy algorithms&quot;, I was solving the following problem on Kattis: <a href="https://open.kattis.com/problems/fridge" rel="nofollow noreferrer">fridge</a>.</p> <blockquote> <p>The goal of the problem is, ...
<python><algorithm><greedy>
2025-05-04 17:17:31
1
427
dietervdf
79,605,674
16,563,251
Type narrowing using is for TypeVar in generic class
<p>I am working with a generic class in python. The corresponding <a href="https://docs.python.org/3/library/typing.html#typing.TypeVar" rel="nofollow noreferrer"><code>TypeVar</code></a> is restricted to a finite amount of (invariant) types. Because it is of some importance what exact type it is at runtime, I specify ...
<python><python-typing><mypy><pyright>
2025-05-04 13:50:22
0
573
502E532E
79,605,658
8,388,707
MCP Server is giving "The selected tool does not have a callable 'function'" when using via autogen
<p>This is all running MCP server and I have also validated it via cloude desktop</p> <pre><code>from typing import Dict from mcp.server.fastmcp import FastMCP # Initialize the FastMCP server with a name mcp = FastMCP(&quot;simple_weather&quot;) # Weather data for different topics WEATHER_DATA = { &quot;rain&quot...
<python><ms-autogen><model-context-protocol>
2025-05-04 13:29:29
1
1,592
Vineet
79,605,299
15,907,363
Bitunix API returns "Signature Error" (code 10007) when placing an order using aiohttp client in Python
<p>I'm trying to integrate with the Bitunix API (<a href="https://openapidoc.bitunix.com/doc/common/introduction.html" rel="nofollow noreferrer">https://openapidoc.bitunix.com/doc/common/introduction.html</a>) using Python and aiohttp. I implemented authentication and signature generation as per the documentation, but ...
<python><request><signature><aiohttp>
2025-05-04 04:57:04
0
464
Milad
79,605,214
6,686,740
Frida: How to send byte[] array from JavaScript to Python
<p>I have a Frida JS script inside a Python session, and I'm trying to pass an array of bytes (from a Bitmap image) from the JavaScript environment back to the Python environment. Here is my attempt:</p> <pre class="lang-py prettyprint-override"><code>import frida import sys import os JS_SCRIPT = ''' setTimeout(functi...
<javascript><python><android><frida>
2025-05-04 00:49:44
1
382
Jugdish
79,605,191
1,892,584
Running pdb on python uv single file scripts?
<p>So the new hotness for scripts on your path in python is to use <code>uv</code> to create single file scripts.</p> <p>These look like this:</p> <pre><code>#!/usr/bin/env -S uv run --script # -*- mode: python -*- # /// script # requires-python = &quot;&gt;=3.12&quot; # dependencies = [ # &quot;dominate&quot;, # ...
<python><pdb><uv>
2025-05-03 23:39:50
1
1,947
Att Righ
79,604,826
13,392,257
Why does the output is 4 seconds, but real time of work is less?
<p>I have a simple decorator to measure time of function in seconds</p> <pre><code>from functools import wraps from time import time def time_it(func): @wraps(func) def wrapper(*args, **kwargs): start_time = time() res = func(*args, **kwargs) print(&quot;Time: &quot;, time() - start_tim...
<python><floating-point>
2025-05-03 15:00:11
2
1,708
mascai
79,604,798
893,254
How does the Tensorflow Gradient Tape calculation work at a low level?
<p>I have just seen some code which has sparked my interest.</p> <pre class="lang-py prettyprint-override"><code>with tf.GradientTape() as g: y = f(x) dy_dx = g.gradient(y, x) </code></pre> <p>(Code loosely taken from this <a href="https://www.tensorflow.org/api_docs/python/tf/GradientTape" rel="nofollow noreferre...
<python><tensorflow><machine-learning><neural-network>
2025-05-03 14:25:25
1
18,579
user2138149
79,604,797
1,681,681
Why does PyQt6 leave large gap between dock widgets after docking them?
<p>I'm using qtpy (wrapping PyQt6) and have a window with dock widgets like so:</p> <p><a href="https://i.sstatic.net/3LCocTlDm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3LCocTlDm.png" alt="enter image description here" /></a></p> <p>However, when I drag and re-dock a dock widget, for some unknown ...
<python><qt><pyqt6><qt6><qtpy>
2025-05-03 14:25:14
0
10,346
mchen
79,604,777
1,681,681
How to fix Pycharm code inspection giving false positives with qtpy?
<p>I'm using qtpy (wrapping PyQt6) and Pycharm (plugin within Intellij), but the IDE is constantly showing me warnings about &quot;Unresolved attribute reference&quot; for Qt objects.</p> <p>This is adding noise and obfuscates real bugs (like the one highlighted in red below).</p> <p>Is there a fix for this?</p> <p><a ...
<python><qt><pycharm><qtpy>
2025-05-03 14:06:49
0
10,346
mchen
79,604,500
15,913,281
"Pop-up" Not Closing Using Normal Click Methods
<p>I am trying to close the &quot;pop-up&quot; that appears when you click on &quot;view flight details&quot; on <a href="https://www.tui.co.uk/destinations/packages?airports%5B%5D=LBA%7CMME%7CNCL%7CMAN%7CEMA&amp;units%5B%5D=000864%3ADESTINATION%7C000910%3ADESTINATION%7C002173%3ADESTINATION%7C000952%3ADESTINATION%7C001...
<python><selenium-webdriver>
2025-05-03 08:34:56
1
471
Robsmith
79,604,417
6,843,103
Apicurio Schema Registry 3.0.7 - unable to update multiple versions of schema for artifactId
<p>I have Apicurio Schema Registry 3.0.7 installed, and I'm trying to use the following code to publish a v2 of schema where GROUP = default, ARTIFACT_ID = com.versa.apicurio.confluent.Employee</p> <p>here is the code :</p> <pre><code>import requests import json import urllib.parse # ──────────────────────────────────...
<python><apache-kafka><apicurio-registry>
2025-05-03 06:32:15
1
1,101
Karan Alang
79,604,354
405,017
TypeVar with UnionType to express lambda parameter type to Pyright
<p>I have a collection of objects which all inherit from <code>Component</code>. I'm writing a function that allows one to select a subset of objects, based on type, and pass them to a lambda. The simple case shown below works, both executing correctly at runtime and also correctly inferring lambda types in VS Code/Pyr...
<python><python-typing><pyright>
2025-05-03 04:14:48
0
304,256
Phrogz
79,604,302
3,163,618
Check if Azure Blob is directory from azure.storage.blob.ContainerClient.list_blobs
<p>I am using the <a href="https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.containerclient?view=azure-python#azure-storage-blob-containerclient-list-blobs" rel="nofollow noreferrer"><code>list_blobs</code></a> function where directories are also treated as blobs. So far I have been ch...
<python><azure><directory><azure-blob-storage>
2025-05-03 02:02:56
2
11,524
qwr
79,604,283
12,980,093
Palindromes and string slicing. Performance
<p>There are a lot of ways to check if string is a palindrome. Plenty of them listed <a href="https://stackoverflow.com/questions/17331290/how-to-check-for-palindrome-using-python-logic">here</a></p> <p>This question is not about &quot;how&quot; but rather about performance.</p> <p>I was assuing that <code>is_palindrom...
<python><algorithm><performance>
2025-05-03 01:14:55
2
653
Slimboy Fat
79,604,252
3,840,940
Issue with pyflink api code for inserting data into sql
<p>I use the following development environment.</p> <ul> <li>Flink : 2.0</li> <li>MySQL : 8.0.4</li> <li>JDK : 17.0.2</li> </ul> <p>And I develop python flink API code, which inserts a simple data into MySQL.</p> <pre class="lang-python prettyprint-override"><code>from pyflink.common import Types from pyflink.datastrea...
<python><java><apache-flink><flink-streaming><pyflink>
2025-05-02 23:57:47
0
1,441
Joseph Hwang
79,604,226
13,413,858
Performance of list.extend slice vs islice
<p>It seems that even when <code>islice</code> would theoretically be better, in practice, it is slower than just using <code>slice</code>. So I am a bit puzzled by the difference in performance between the usage of <code>slice</code> and <code>islice</code> here:</p> <pre class="lang-py prettyprint-override"><code>fro...
<python><slice><python-itertools>
2025-05-02 23:11:20
2
494
Mathias Sven
79,604,129
1,614,051
How can I annotate a function that takes a union, and returns one of the types in the union?
<p>Suppose I want to annotate this function:</p> <pre><code>def add_one(value): match value: case int(): return value + 1 case str(): return value + &quot; and one more&quot; case _: raise TypeError() </code></pre> <p>I want to tell the type checker &quot;...
<python><python-typing>
2025-05-02 21:18:02
1
2,072
Filipp
79,604,001
11,515,528
pandas memory issue when apply list to groupby
<p>I am doing the below but getting memory issues.</p> <p>make frame</p> <pre><code>data = {'link': [1,2,3,4,5,6,7], 'code': ['xx', 'xx', 'xy', '', 'aa', 'ab', 'aa'], 'Name': ['Tom', 'Tom', 'Tom', 'Tom', 'nick', 'nick', 'nick'], 'Age': [20,20,20,20, 21, 21, 21]} # Create DataFrame df = pd.DataF...
<python><pandas><memory>
2025-05-02 19:15:24
2
1,865
Cam
79,603,739
638,231
pyvespa: what is efficient efficient way to retrieve all document ids
<p>I am using private Vespa server.</p> <p>Given a schema with large number of documents, what is the best way to retrieve all document IDs?</p> <p>A query to match the relevant docs would be something like:</p> <pre><code>&quot;select id from my_container where my_field contains \&quot;my_value\&quot;;&quot; </code></...
<python><vespa>
2025-05-02 16:11:20
0
15,053
pic11
79,603,730
2,687,427
How to type hint overload Callable and type differently?
<p>How to type hint overload the return type of a Callable and type differently and safely? The problem I'm having is that the <code>type</code> doesn't support <code>ParamSpec</code>, so I can't use that to enforce <code>args</code> and <code>kwargs</code>, in the same way as as <code>Callable</code>.</p> <pre class="...
<python><python-typing><mypy>
2025-05-02 16:08:02
0
3,472
Nelson Yeung
79,603,715
3,690,024
ssl socket without certificates
<p>Is it possible to establish an SSL socket between a client and server without certificates?</p> <p>The goal here is to prevent (or at least, impede) eavesdropping on the communication between two processes. Looking for encrypted communication only - not identity verification.</p> <p>Client/server processes are shor...
<python><python-3.x><sockets><ssl>
2025-05-02 16:00:10
1
8,747
AJNeufeld
79,603,699
14,589,610
How can I apply side effects to a function of an instance that is created in a function that is tested?
<p>I have a custom class in the file MyClass.py</p> <pre><code>class MyClass: def __init__(self): self.fetched_data = False def get_data(self): self.fetched_data = True return [1, 2, 3] </code></pre> <p>I import and use that class in the file <code>function_to_te...
<python><python-unittest><python-unittest.mock>
2025-05-02 15:49:00
1
530
DwightFromTheOffice
79,603,558
2,263,683
How to set index url for uv like pip configurations
<p>When using <code>pip</code> to install Python packages, we can set the configurations so that it can refer to some private repository to install packages. The usecase is for example for big companies where for security issues, they would keep all packages in their own repo and will only trust those resources. In suc...
<python><pip><uv>
2025-05-02 14:21:51
2
15,775
Ghasem
79,603,414
1,245,659
unexpected keyword in createsuperuser django
<p>I am working with BaseAbstractUser and AbstractUser, and I have a problem with a required field.</p> <p>models.py</p> <pre><code>from django.db import models from django.conf import settings from django.contrib.auth.models import User, AbstractBaseUser, BaseUserManager from django.utils.timezone import timedelta, no...
<python><django>
2025-05-02 12:49:41
2
305
arcee123
79,603,298
6,734,243
What is the oldest leap year in pandas?
<p>I'm working with a day of year column that ranges from 1 to 366 (to account for leap years). I need to convert this column into a date for a specific task and I would like to set it to a year that is very unlikely to appear in my time series.</p> <p>Is there a way to set it to the oldest leap year of pandas?</p> <pr...
<python><pandas>
2025-05-02 11:30:56
2
2,670
Pierrick Rambaud
79,603,293
1,100,561
Python Pandas Interpolate nan columns with respect to the column values
<p>I have data in Pandas, where the temperatures are the column headers and the COP values are in the matrix.</p> <p>If I interpolate using pandas interpolate function I end up with linear interpolate, not weighted to the temperature at the top.</p> <p>For example, here is my original data: <a href="https://i.sstatic.n...
<python><pandas><interpolation>
2025-05-02 11:27:25
1
445
CromeX
79,603,209
14,364,672
Privategpt listing ingested document filenames
<p>I'm new to LLMs and need to extract the file names of files that have been already ingested into PrivateGPT that the system uses to answer questions.</p> <p>I can list the doc_ids using :</p> <pre><code> from pgpt_python.client import PrivateGPTApi client = PrivateGPTApi(base_url=&quot;http://localhost:8001&...
<python><privategpt>
2025-05-02 10:32:37
1
465
steve
79,602,705
1,838,076
Why is DecisionTree using same feature and same condition twice
<p>When trying to fit <code>scikit-learn DecisionTreeClassifier</code> on my data, I am observing some weird behavior.</p> <p><code>x[54]</code> (a boolan feature) is used to break the <code>19</code> samples into <code>2</code> and <code>17</code> on top left node. Then again, the same feature with exact same conditio...
<python><machine-learning><scikit-learn><classification><decision-tree>
2025-05-02 01:14:10
0
1,622
Krishna
79,602,585
2,153,235
Why doesn't exec() create objects in local/global scope?
<p>I'm trying to find an IPython counterpart to Spyder's <code>runfile</code>. According to <a href="https://realpython.com/python-exec" rel="nofollow noreferrer">this page</a>, &quot;exec() will execute the input code in the current scope&quot; by default. Therefore, I expect the following to create objects <code>Te...
<python><ipython>
2025-05-01 21:53:44
2
1,265
user2153235
79,602,247
2,465,116
How to call a SymForce auto-generated function with a user defined type?
<p>Suppose I have a Python function <code>Foo()</code> that I'm auto-generating to C++ with SymForce's codegen functionality. It's a complicated function with a lot of parameters, so I want to pass in a <code>Params</code> struct instead of 20+ individual scalar arguments. I would further like to use the existing <code...
<python><c++><code-generation>
2025-05-01 16:59:55
1
488
user2465116
79,602,223
16,569,183
Long import time of pybind11 extension
<p>I have a C++ library with a Python interface, generated using pybind11 on a mac with intel processor. The library is compiled into a single shared object <code>kernel.so</code>, with 29MB of size. Importing the module from a Python script takes about 7 seconds, which makes using it annoying.</p> <p>I am assuming tha...
<python><macos><shared-libraries><pybind11>
2025-05-01 16:47:43
1
313
alfonsoSR
79,602,019
1,719,931
Can't see color in Visual Studio Code
<p>I'm following &quot;Hands on Large Language Models&quot; by Alammar.</p> <p>One of the examples is:</p> <pre class="lang-py prettyprint-override"><code>from transformers import AutoModelForCausalLM, AutoTokenizer colors_list = [ '102;194;165', '252;141;98', '141;160;203', '231;138;195', '166;216;84', '255;2...
<python><visual-studio-code><colors><ansi-colors>
2025-05-01 14:29:31
1
5,202
robertspierre
79,602,017
16,845
Correct type annotations for generator function that yields slices of the given sequence?
<p>I'm using Python 3.13 and have this function:</p> <pre><code>def chunk(data, chunk_size: int): yield from (data[i : i + chunk_size] for i in range(0, len(data), chunk_size)) </code></pre> <p>I want to give it type annotations to indicate that it can work with <code>bytes</code>, <code>bytearray</code>, or a gene...
<python><python-typing>
2025-05-01 14:28:00
1
1,216
Charles Nicholson
79,601,906
10,006,183
How can I integrate LangSmith for observability in a multi-agent Autogen (AG2) GroupChat setup?
<p>I'm working on a document analysis service using Autogen (AG2). The service has two main agents: a reader and an analyzer. The reader splits the document into chunks and sends them to the analyzer, who takes notes. This coordination is done using a multi-agent GroupChat.</p> <p>I came to know that AG2 natively suppo...
<python><openai-api><langchain><observability><langsmith>
2025-05-01 13:09:38
0
2,257
the cosmic introvert dude
79,601,886
6,029,488
Produce a heatmap plot using seaborn with specific color mapping for values within and outside a given range
<p>Consider the following basic dataframe example:</p> <pre><code> min mean max ALU -0.008 0.000 0.034 BRENT -0.017 0.000 0.023 CU -0.011 0.000 0.013 DTD_BRENT -0.011 0.000 0.019 GASOIL -0.009 0.000 0.035 GOLD -0.008 0.000 0.009 HH -0.033 ...
<python><pandas><seaborn><heatmap>
2025-05-01 12:54:45
1
479
Whitebeard13
79,601,832
1,709,413
How to properly import python module from another python file using importlib.import_module?
<p>I'm working on Alembic migration github action and need to import base metadata class inside python migration script which locates in another directory. I can't import it directly inside python migration script like as it's normally do like <code>from src.databse.models import BaseModel</code> because it's dynamical...
<python><python-os><python-importlib>
2025-05-01 12:14:39
0
1,197
andrey
79,601,234
1,245,659
ensure Customuser is being used in Django App
<p>I have a problem with implementing CustomUser in a Django App.</p> <p>My project is called &quot;VendorManagement&quot;.</p> <p>My app is &quot;VMP&quot;.</p> <p>In settings, I have <code>AUTH_USER_MODEL = 'VMP.CustomUser'</code> set.</p> <p>Here is my CustomUser Model:</p> <pre><code>from django.db import models fr...
<python><django>
2025-04-30 23:52:28
2
305
arcee123
79,601,104
2,153,235
How to quietly exit a runfile script?
<p>I am using Spyder 6 console to invoke a Python script via the <code>runfile</code> command. After a recent Anaconda update, I found that <code>sys.exit()</code> no longer exits the script quietly. It prints:</p> <pre><code>An exception has occurred, use %tb to see the full traceback. SystemExit: 0 C:\Users\User....
<python><exit>
2025-04-30 21:12:40
1
1,265
user2153235
79,601,098
1,264,589
How to make my AWS Bedrock RAG AI Assistant ask which product the user is asking about
<p>I added a RAG AI assistant using AWS Bedrock to our website so customers can ask questions and get answers about the four products we sell. Each product has the same two documents, like: product_A_user_guide.pdf, product_A_specs.pdf, product_B_user_guide.pdf, product_B_specs.pdf, etc.</p> <p>The products offer simil...
<python><amazon-web-services><artificial-intelligence><amazon-bedrock>
2025-04-30 21:07:43
1
1,305
hugo
79,600,924
4,913,660
Explode nested JSON to Dataframe
<p>There are loads of answers on this topic, but for the life of me, I cannot find a solution to my issue.</p> <p>Say I have a JSON like</p> <pre><code>json_2_explode = [ { &quot;scalar&quot;: &quot;43&quot;, &quot;units&quot;: &quot;m&quot;, &quot;parameter&quot;: [{&quot;no_1&quot;: &quot;...
<python><json><pandas>
2025-04-30 18:39:52
5
414
user37292
79,600,521
9,165,100
issue with hdbscan installation
<p>I try to install hdbscan:</p> <p>pip install hdbscan</p> <p>All goes well until the message</p> <pre><code>running build_ext building 'hdbscan._hdbscan_tree' extension creating build/temp.linux-x86_64-cpython-312/hdbscan x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -I/ho...
<python><pip><hdbscan>
2025-04-30 14:22:16
1
431
user9165100
79,600,488
1,234,721
Square API for invoice attachments 'Received multiple request parts. Please only supply zero or one `parts` of type application/json.'
<p>The new square api versions 42+ have breaking changes. Im trying to upgrade to ver v42, and I am testing in a local dev environment.</p> <p>I keep getting the following error: <code>*** square.core.api_error.ApiError: status_code: 400, body: {'errors': [{'category': 'INVALID_REQUEST_ERROR', 'code': 'INVALID_CONTENT...
<python><square>
2025-04-30 14:07:14
1
19,295
chris Frisina
79,600,418
29,295,031
How to select a range of data in a pandas dataframe
<p>I have this pandas dataframe : df :</p> <pre><code>import pandas as pd data = { &quot;function&quot;: [&quot;test1&quot;,&quot;test2&quot;,&quot;test3&quot;,&quot;test4&quot;,&quot;test5&quot;,&quot;test6&quot;,&quot;test7&quot;,&quot;test8&quot;,&quot;test9&quot;,&quot;test10&quot;,&quot;test11&quot;,&quot;test...
<python><pandas><dataframe>
2025-04-30 13:27:29
2
401
user29295031
79,600,185
4,398,952
Shrink tkinter Text widget to text dimension
<p>I'm trying to shrink a <em>Text</em> widget to the size of the text inside. In fact, if you run the following example code:</p> <pre><code>import tkinter as tk root = tk.Tk() testText = tk.Text(master=root) testText.insert(index=&quot;1.0&quot;, chars=&quot;short string&quot;) testText.tag_configure(tagName=&quot;...
<python><tkinter><text-widget>
2025-04-30 11:01:12
1
401
ela
79,600,103
10,715,700
SQLModel session handling when my read and updates are in seperate parts of the code flow
<p>I have a script that needs to query some data, process it, and then update some columns in the row I read.</p> <p>My code looks like this:</p> <pre class="lang-py prettyprint-override"><code>def query_data(param1): with Session(engine) as session: statement = select( FreddyInsightsInfo).where...
<python><sqlalchemy><sqlmodel>
2025-04-30 10:17:06
1
430
BBloggsbott
79,600,062
5,599,028
Set default value for date field in portal odoo18
<p>In Odoo18, I created template for a portal user which inherit another template, In my custom template, I want a date fields 'birthday' to be auto filled</p> <pre><code>&lt;t t-set=&quot;last_app&quot; t-value=&quot;request.env['hr.applicant'].search([ ('partner_id', '=', partner.id), '|', ('active', '...
<python><xpath><portal><qweb><odoo-18>
2025-04-30 09:53:52
1
3,832
khelili miliana
79,600,043
893,254
How do I read a `.arrow` (Apache Arrow aka Feather V2 format) file with Python Pandas?
<p>I'm trying to read an <code>.arrow</code> format file with Python pandas.</p> <p><code>pandas</code> does not have a <code>read_arrow</code> function. However, it does have <code>read_csv</code>, <code>read_parquet</code>, and other similarly named functions.</p> <p>How can I read an Apache Arrow format file?</p> <p...
<python><pandas><apache-arrow>
2025-04-30 09:46:13
1
18,579
user2138149
79,600,015
3,402,296
Worker cannot find external file in Apache Beam
<p>I have a simple function that reads from Mongo using Apache Beam</p> <pre class="lang-py prettyprint-override"><code>def create_mongo_pipeline(p: beam.Pipeline, mongo_uri: str, db: str, coll: str, cert_file: str, gcs_bucket: str) -&gt; None: # Read from MongoDB docs = p | 'ReadMyFile' &gt;&gt; beam.io.mongod...
<python><google-cloud-platform><google-cloud-dataflow><apache-beam><apache-beam-io>
2025-04-30 09:28:13
2
576
RDGuida
79,599,972
4,062,352
When switching from pyenv to venv, what replaces pyenv's version management?
<p>The native Python package <code>venv</code> is &quot;recommended for creating virtual environments&quot;. I read that as saying that the Python Foundation wants users to switch from third party solutions like <code>pyenv</code> to native, &quot;official&quot; functionality. Comments <a href="https://stackoverflow.co...
<python><python-3.x><python-venv><pyenv>
2025-04-30 09:11:23
1
646
Roofus
79,599,726
305,043
QuerySet returns empty in django
<p>I am trying to get the book list with 3 conditions:</p> <ol> <li>Accession number (character varying,10)</li> <li>Physical location (character varying,20)</li> <li>Book status</li> </ol> <p>Based on the user input:</p> <ol> <li>Accession number should be present in the list provided by the user</li> <li>Physical loc...
<python><django><django-models><django-queryset><django-q>
2025-04-30 07:09:21
1
1,731
PM.
79,599,624
988,279
FastAPI application with nginx - StaticFiles not working
<p>I've a simple FastAPI project. It is running correctly in pycharm and in the docker container. When running via nginx, the <code>StaticFiles</code> are not delivered.</p> <p>Structure is like this:</p> <pre><code>├── app │   ├── main.py │   ├── static_stuff │   │   └── styles.css │   └── templates │   └── item.h...
<python><nginx><fastapi>
2025-04-30 05:49:26
2
522
saromba
79,599,437
395,857
Import onnxruntime then load_dataset "causes ImportError: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found": why + how to fix?
<p>Running</p> <pre class="lang-py prettyprint-override"><code>import onnxruntime as ort from datasets import load_dataset </code></pre> <p>yields the error:</p> <pre><code>(env-312) dernoncourt@pc:~/test$ python SE--test_importpb.py Traceback (most recent call last): File &quot;/home/dernoncourt/test/SE--test_impor...
<python><ubuntu><libstdc++><onnxruntime><huggingface-datasets>
2025-04-30 02:13:46
1
84,585
Franck Dernoncourt
79,599,360
14,802,285
What is the equivalent of torch.nn.Parameter(...) in julia's flux?
<p>In <code>pytorch</code> I can create a custom module as follows (this code example is taken from <a href="https://discuss.pytorch.org/t/practical-usage-of-nn-variable-and-nn-parameter/148644/2" rel="nofollow noreferrer">here</a>):</p> <pre><code>from torch import nn class MyModel(nn.Module): def __init__(self):...
<python><pytorch><julia><flux.jl>
2025-04-30 00:27:31
2
3,364
bird
79,599,232
1,609,514
Why is the numerator coefficient array returned by scipy.signal.cont2discrete two dimensional?
<p>I'm converting a continuous-time dynamical system to discrete time using the function <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cont2discrete.html" rel="nofollow noreferrer"><code>cont2discrete</code></a> from Scipy's signal processing library.</p> <pre class="lang-py prettyprint-ove...
<python><scipy><signal-processing><transfer-function>
2025-04-29 21:34:11
1
11,755
Bill
79,599,188
1,264,589
Python pg8000 query params...syntax error at or near \”$2\"
<p>Hi…I’m trying to add a parameter to my query but I get this error:</p> <pre><code>&quot;errorMessage&quot;: &quot;{'S': 'ERROR', 'V': 'ERROR', 'C': '42601', 'M': 'syntax error at or near \”$2\&quot;', 'P': '3793', 'F': 'scan.l', 'L': '1146', 'R': 'scanner_yyerror'}&quot; </code></pre> <p>This works:</p> <pre><code>i...
<python><postgresql><pg8000>
2025-04-29 20:50:34
1
1,305
hugo
79,599,115
20,591,261
How to Filter All Columns in a Polars DataFrame by expression?
<p>I have this example Polars DataFrame:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({ &quot;id&quot;: [1, 2, 3, 4, 5], &quot;variable1&quot;: [15, None, 5, 10, 20], &quot;variable2&quot;: [40, 30, 50, 10, None], }) </code></pre> <p>I'm trying to filter all c...
<python><dataframe><python-polars>
2025-04-29 19:49:22
3
1,195
Simon
79,598,876
243,031
python 3.8 package installed but pkg_resources not able to found
<p>Using old python version <code>3.8.6</code>.</p> <p>I created virtual environment in <code>/var/virtualenvs/myvenv</code> and installed <code>mypkg.bouncer.client</code> but when we import that, it gives below error.</p> <pre><code>Traceback (most recent call last): File &quot;/var/virtualenvs/myvenv/lib/python3.8...
<python><import><package><python-3.8>
2025-04-29 17:12:02
0
21,411
NPatel
79,598,793
4,706,711
How I can realtime update the Ui when I receive a request upon FastAPI?
<p>I have this simple script:</p> <pre class="lang-py prettyprint-override"><code>import os import gradio as gr from fastapi import FastAPI, Request import uvicorn import threading from typing import List from datetime import datetime api = FastAPI() # Shared logs class Log(): def __init__(self): self._l...
<python><fastapi><gradio>
2025-04-29 16:08:50
2
10,444
Dimitrios Desyllas
79,598,781
8,753,169
How to set up docker compose with django and pdm
<p>I have a django project with pdm and docker compose and I set up the codebase volume to enable django hot reload and debugging in the container. Building with the compose config works fine but when I try to run the server with <code>docker compose up -d</code> I hit a python error as if the libs were not picked up p...
<python><django><docker><docker-compose><pdm>
2025-04-29 16:01:55
2
1,043
Martin Faucheux
79,598,738
2,072,516
Joined loads across multiple tables
<p>I'm stuck with joined loads over multiple models. I have a FastAPI project, and I'm using Jinja to serve some HTML pages. In said page, I need to access content joined from other tables (looks like doing the access at time of doesn't work while in the Jinja template? I keep getting greenlet errors). Because I'll def...
<python><sqlalchemy>
2025-04-29 15:33:35
1
3,210
Rohit
79,598,735
893,254
How to convert from Python pandas Timestamp to repeated google.protobuf.Timestamp? (Python + Google Protocol Buffers)
<p>I am trying to write some code which converts the contents of a <code>pandas.DataFrame</code> to a protobuf object which can be serialized and written to a file.</p> <p>Here is my protobuf definition.</p> <pre class="lang-none prettyprint-override"><code>syntax = &quot;proto3&quot;; import &quot;google/protobuf/tim...
<python><pandas><protocol-buffers>
2025-04-29 15:32:54
0
18,579
user2138149
79,598,423
497,649
How to select certain row(s) by code in a DataGrid table in Python-Shiny?
<p>I created a table (&quot;DataGrid&quot;) using:</p> <pre><code>ui.output_data_frame(&quot;grid&quot;) </code></pre> <p>which I filled using</p> <pre><code>@render.data_frame def grid(): df = ... return render.DataGrid(df, selection_mode=&quot;row&quot;) </code></pre> <p>Now, I want to change the selection...
<python><datatable><datagrid><reactive-programming><py-shiny>
2025-04-29 12:58:48
1
640
lambruscoAcido
79,598,267
3,332,023
Typehints for dicts in Python including the default values
<p>I have a function that calls a bunch of other functions like this:</p> <pre><code>import inspect def get_default_args(func): # obtained from: https://stackoverflow.com/questions/12627118/get-a-function-arguments-default-value signature = inspect.signature(func) return { k: v.default for k...
<python><python-typing>
2025-04-29 11:34:50
0
467
axel_ande
79,598,199
15,638,204
Chaining multiple GPT-4 Turbo API calls with function calling and dynamic memory/context injection
<p>I'm working on a modular pipeline using OpenAI's GPT-4 Turbo (via <code>/v1/chat/completions</code>) that involves multi-step prompt chains. Each step has a specific role (e.g., intent detection → function execution → summarization → natural language response). I'm running into architectural questions:</p> <p>Each s...
<python><artificial-intelligence><openai-api>
2025-04-29 11:01:55
1
956
avocadoLambda
79,597,670
2,284,570
Lattice attack against single signature : how to modify the b1 and c1 constants in order to get the script working against smaller leaks?
<p>The following script I found <a href="https://github.com/AMOSSYS/challenges/blob/main/CRY-ME/break_schnorr.py" rel="nofollow noreferrer">here</a>. The idea <a href="https://www.amossys.fr/insights/blog-technique/cry-me-private-key-recovery-with-a-single-signature/" rel="nofollow noreferrer">explained here</a> is tha...
<python><cryptography><digital-signature><elliptic-curve><mathematical-lattices>
2025-04-29 05:39:51
1
3,119
user2284570
79,597,604
13,396,497
Merge more than 2 dataframes if they exist and initialised
<p>I am trying to merge three dataframes using intersection(). How can we check that all dataframes exists/initialised before running the intersection() without multiple if-else check blocks. If any dataframe is not assigned, then don't take it while doing the intersection(). Sometimes I am getting error - <strong>Unbo...
<python><pandas><dataframe>
2025-04-29 04:26:20
2
347
RKIDEV
79,597,461
7,519,434
Incompatible type hints for AST node subclasses
<p>I am writing a script to perform obfuscation using the <code>ast</code> module. A decorator is used to define obfuscation functions for each AST node type. The decorator adds the functions to a dictionary, <code>Obfuscator.obfuscators</code>, which maps <code>type(node)</code> to a function that takes the node and <...
<python><python-typing>
2025-04-29 01:19:00
0
3,989
Henry
79,597,415
1,084,684
How to create menus in GTK 4 with pygi?
<p>I've googled about this quite a bit. I've put a number of examples of what I tried <a href="https://stromberg.dnsalias.org/svn/gtk-4-menu/trunk" rel="nofollow noreferrer">https://stromberg.dnsalias.org/svn/gtk-4-menu/trunk</a> - I'm going to quote the closest one immediately below in case of link rot:</p> <pre><cod...
<python><gtk4><pygi>
2025-04-28 23:57:55
1
7,243
dstromberg
79,597,235
5,796,711
Jinja template not populating in python
<p>I am trying to get up and running with a very simple jinja example using Python.</p> <p>My folder structure looks like this:</p> <pre><code>jinja-testing/ templates/ common/ sample_values.sql queries/ sample_query.sql build_queries.ipynb </code></pre> <p>sample_values.sql is:</p...
<python><jinja2>
2025-04-28 20:22:31
0
523
krock
79,597,213
219,153
How to compute elementwise dot product of two 2D NumPy arrays
<p>This script:</p> <pre><code>import numpy as np a = np.array([[0, 1], [1, 1], [1, 0]]) b = np.array([[1, 0], [1, 1], [1, -1]]) dot = a[:, 0]*b[:, 0] + a[:, 1]*b[:, 1] print(dot) </code></pre> <p>produces elementwise dot product of <code>a</code> and <code>b</code>:</p> <pre><code>[0 2 1] </code></pre> <p>There must ...
<python><arrays><numpy>
2025-04-28 20:03:50
1
8,585
Paul Jurczak
79,597,050
1,938,096
Open Excel workbook in smaller proportions
<p>I'm using this code (adjusted example I found somewhere) to generate an excel file. It works as expected, with just one problem which is that when opening the file it always opens full screen which is very annoying to the end user. Is there a way to adjust the settings of the file?</p> <pre><code>jsreport = filtered...
<python><excel>
2025-04-28 17:57:39
0
579
Gabrie
79,596,918
12,608,619
Python asyncio aiopg exception for correct combination of host and database
<p>I have a list of 155 host + databases and I want to create a simple app in jupyter notebook that runs some query on them. Example looks as follows:</p> <pre><code>SQL = &quot;&quot;&quot; SELECT 1 &quot;&quot;&quot; import asyncio import aiopg import nest_asyncio nest_asyncio.apply() loop = asyncio.new_event_loop()...
<python><postgresql><python-asyncio><aiopg>
2025-04-28 16:36:26
0
371
Lidbey
79,596,720
13,055,818
pkgs.dev.azure.com pip install SSL Error in WSL and Docker
<p>This problem has been addressed countless times and yet I do not think there is a magic solution at least that worked for me.</p> <p>I perfectly was able to publish some private python packages to the Azure Artifacts so I can use them to build a bigger project but no, Azure decided that I won't be allowed to work on...
<python><azure-devops><pip><azure-artifacts>
2025-04-28 14:45:58
0
519
Maxime Debarbat
79,596,690
11,720,193
Identify existence of tables in BigQuery
<p>I have a text file with BigQuery tablenames. My requirement is to iterate through the list and search every dataset available in every Project environment (i.e. Project 'my-project-dev/test/prod') to check for the table's existence in each Project/DataSet, and output the results in a text file in the format shown be...
<python><google-bigquery><pybigquery>
2025-04-28 14:26:39
0
895
marie20
79,596,647
1,450,343
'Incompatible types in assignment' when assigning from multiple inheritance in MyPy
<p>Here is a sample:</p> <pre><code>class A: pass class B: pass class X(A, B): pass class Y(A, B): pass z: B = Y() if temp else X() # MyPy error </code></pre> <p>The error is <em>Incompatible types in assignment (expression has type &quot;A&quot;, variable has type &quot;B&quot;)</em>.</p> <p>I could write my me...
<python><python-typing><mypy>
2025-04-28 14:08:15
1
816
ModdyFire
79,596,631
29,295,031
Convert month abbreviation to full name
<p>I have this function which converts an English month to a French month:</p> <pre><code>def changeMonth(month): global CurrentMonth match month: case &quot;Jan&quot;: return &quot;Janvier&quot; case &quot;Feb&quot;: return &quot;Février&quot; case &quot;Mar&quot...
<python><pandas>
2025-04-28 14:00:43
3
401
user29295031
79,596,546
1,490,418
How can I properly test swagger_auto_schema for methods, request_body, and responses in drf-yasg with pytest?
<p>I’m working on testing a Django REST Framework (DRF) CartViewSet using pytest, and I need to verify the swagger_auto_schema properties like the HTTP method, request body, and responses for different actions (e.g., add, remove, clear).</p> <p>I have the following code in my CartViewSet:</p> <pre><code>class CartViewS...
<python><django><django-rest-framework><drf-yasg>
2025-04-28 13:07:59
2
770
Shervin Gharib
79,596,508
1,980,208
Why is day_size set to 32 in temporal embedding code?
<p>I am trying to understand the code for temporal embedding inside autoformer implementation using pytorch.</p> <p><a href="https://github.com/thuml/Autoformer/blob/main/layers/Embed.py" rel="nofollow noreferrer">https://github.com/thuml/Autoformer/blob/main/layers/Embed.py</a></p> <pre><code>class TemporalEmbedding(n...
<python><pytorch><transformer-model>
2025-04-28 12:45:59
0
439
prem
79,596,493
8,721,169
Generate RTDB key without creating node
<p>I'm trying to create a Python function that generates a valid key in my Firebase Realtime Database (using the same logic as other keys, ensuring no collision and chronological order).</p> <p>Something like this:</p> <pre class="lang-py prettyprint-override"><code>def get_new_key() -&gt; str: return db.reference(...
<python><firebase><firebase-realtime-database>
2025-04-28 12:36:43
1
447
XGeffrier
79,596,399
2,276,054
How to log/display app name, host and port upon startup
<p>In my simple Flask app, I've created the following <code>.flaskenv</code> file:</p> <pre><code>FLASK_APP=simpleflask.app FLASK_RUN_HOST=127.0.0.1 FLASK_RUN_PORT=60210 </code></pre> <p>Now, I would like my app to log the following message upon startup:</p> <pre><code>Running my.flask.app on http://127.0.0.1:60210 ......
<python><flask>
2025-04-28 11:40:22
2
681
Leszek Pachura
79,596,231
7,959,614
Create all possible outcomes from numpy matrices that show disjoints and subsets
<p>Let's assume there is an event and within this event there are multiple outcomes that can co-exist. An example would be a tennis game where A plays against B and B serves. A couple of possible outcomes are possible:</p> <ul> <li>A wins</li> <li>B wins</li> <li>A wins with 60-0</li> <li>A wins with 60-15</li> <li>B ...
<python><numpy><matrix><python-itertools>
2025-04-28 10:17:26
1
406
HJA24
79,596,178
11,720,193
Checking for Table Existence in BigQuery using Python or BQ CLI (shell-script)
<p>I have a simple text file containing a list of BigQuery tables (TableA, TableB etc), for each of which the following is required -</p> <ul> <li>Search the table in all datasets present in all envs (projects)</li> <li>If a table is present in Prod (determined by the project-name) in any dataset, and is also present (...
<python><google-bigquery>
2025-04-28 09:48:11
0
895
marie20
79,596,162
8,020,900
Dash loading component: how to have spinner appear in the correct place on initial load
<p>On initial load, the spinner is very high up on the page (I guess because no figure has been created yet). On subsequent loads (whenever a new option is selected from the dropdown), the spinner is in the correct place where the figure should be displayed. Any idea how I can make it also be in the correct place on in...
<python><plotly-dash><mantine>
2025-04-28 09:37:02
1
3,539
Free Palestine
79,596,151
8,020,900
How to add text to Dash Loading (dcc.Loading) component
<p>I'd like to use one of the built-in spinners in <code>dcc.Loading</code> but add some text underneath the spinner/loader while it's active.</p> <pre><code>import time import plotly.express as px import dash_mantine_components as dmc import dash from dash import dcc, callback, Output, Input dash.register_page(module...
<python><plotly-dash><mantine>
2025-04-28 09:29:59
1
3,539
Free Palestine