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,554,831
4,159,193
Django Model: unexpected keyword arguments in constructor
<p>I have a Django Model Kunde</p> <pre><code>from django.db import models class Kunde(models.Model): Kundennummer = models.IntegerField(), Vorname = models.CharField(max_length=200), Nachname = models.CharField(max_length=200) </code></pre> <p>I open the Django shell with the command <code>python manage....
<python><django><django-models>
2025-04-04 08:26:43
2
546
flori10
79,554,808
9,525,238
PySide6 QImage conversion to PyQtGraph ndarray
<p>I cannot generate a QImage with some text on it, keep it in memory, and then successfully display it on a pyqtgraph.ImageItem which needs it as an np.ndarray</p> <pre class="lang-py prettyprint-override"><code>import sys import numpy as np import pyqtgraph as pg from PySide6.QtWidgets import QApplication, QMainWindo...
<python><numpy-ndarray><pyside6><qimage>
2025-04-04 08:13:30
0
413
Andrei M.
79,554,765
110,963
Python logging when forking processes
<p>I implemented a custom <code>logging.StreamHandler</code> that stores logs on S3. It works fine in a single process, but I cannot handle scenarios where processes are forked. I'm on Linux and only need to support that platform. The general approach is this:</p> <pre><code>class S3Handler(logging.StreamHandler): ...
<python><logging><fork><luigi>
2025-04-04 07:48:20
1
15,684
Achim
79,554,450
9,597,296
How to setup supabase sever client properly
<p>In my backend(FastAPI) I'm using supabase to send OTPs, update tables. for this I have this server client.</p> <pre class="lang-py prettyprint-override"><code>from supabase import create_client, Client from app.core.config import settings class SupabaseClient: def __init__(self): supabase_url = settings...
<python><fastapi><supabase><supabase-py>
2025-04-04 04:14:58
0
4,581
Nipun Ravisara
79,554,434
11,084,338
How to replace nested for loops with apply from dataframe in python
<p>I have a dataframe and a list below.</p> <pre><code>import pandas as pd my_df = pd.DataFrame({'fruits': ['apple', 'banana', 'cherry', 'durian'], 'check': [False, False, False, False]}) my_list = ['pp', 'ana', 'ra', 'cj', 'up', 'down', 'pri'] &gt;&gt;&gt; my_df fruits check 0 apple...
<python><pandas><dataframe><for-loop>
2025-04-04 03:57:33
1
326
GH KIM
79,554,331
5,924,264
Inner join producing duplicative columns
<p>Not really well versed with python/sql joins in general, but it looks like this inner join is producing 2 identical columns of <code>my_id, mod_id</code> which have identical values?</p> <pre><code> df = ( lhs_df[LHS_COLS] .merge( rhs_df, left_on=&quot;my_id&quot;, right_on=&quot;mod_id&quot;, suffixe...
<python><pandas><inner-join>
2025-04-04 02:03:41
0
2,502
roulette01
79,554,329
5,964,034
How to create a Docker file that iterates over files in a folder and executes a particular command (mri_synthstrip)
<p>There is this program mri_synthstrip which inputs a brain MRI file and outputs the same brain MRI file excluding the skull. This is a basic initial step for preprocessing brain MRIs for research.</p> <p>The program is wonderful and the syntax to skull strip a single MRI is simple if you install the program in your c...
<python><docker>
2025-04-04 02:01:25
2
771
Ivan
79,554,216
268,581
Year comparison
<h1>Dataframe</h1> <p>Here's a dataframe which has U.S. Treasury General Account deposits from taxes (month to date).</p> <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt; df record_date transaction_mtd_amt 0 2005-10-03 18777 1 2005-10-04 21586 2 2005-10-05 ...
<python><pandas><streamlit>
2025-04-04 00:09:43
1
9,709
dharmatech
79,554,185
1,227,058
Python scraper not returning value to Excel
<p>I have a Python webscraper that pulls a specific value every 1 second. The target website it AJAXed, so I'm not hitting it with too many requests.</p> <p>This is the Python code:</p> <pre><code>import time import logging import sys from selenium import webdriver from selenium.webdriver.chrome.service import Service...
<python><excel><vba><web-scraping>
2025-04-03 23:29:58
1
1,136
Matteo
79,554,175
16,118,686
Can't interact with checkboxes and button
<p>In this URL: <a href="http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v05_template_informacoes_di.asp?str_Modulo=completo&amp;int_Idioma=2&amp;int_Titulo=6&amp;int_NivelBD=2/" rel="nofollow noreferrer">http://estatisticas.cetip.com.br/astec/series_v05/paginas/lum_web_v05_template_informacoes_di.asp...
<python><selenium-webdriver><selenium-chromedriver>
2025-04-03 23:12:19
2
11,256
NightEye
79,554,077
4,463,825
Python Resource Allocation of Devices
<p>I am looking for some optimization algorithm suggestion on resource allocation. Preferably in Python.</p> <p>I have a given number of total resources, and I have to conduct a certain number of Experiments with these resources. Each experiment takes a given set of days, and different number of resources.</p> <p>Seeki...
<python><numpy><optimization>
2025-04-03 21:48:26
0
993
Jesh Kundem
79,554,068
202,385
argo workflows: using jsonpath in when expression
<p>In the below argo workflow specification</p> <ul> <li>I am generating a list of booleans from <code>generate-booleans</code> step.</li> <li>I want to conditionally execute <code>step1</code> if the 0th element of the list is true.</li> </ul> <p>I have tried many combinations of the expression in the when but I am un...
<python><argo-workflows>
2025-04-03 21:44:37
0
396
vijayvammi
79,553,855
18,108,767
Overlaping subplots vertically stacked
<p>While reading a paper for my thesis I encountered <a href="https://www.nature.com/articles/s41467-024-45469-8/figures/5" rel="nofollow noreferrer">this graph (b)</a>: <a href="https://i.sstatic.net/mr6fNyDs.webp" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mr6fNyDs.webp" alt="Image from the paper" /></...
<python><matplotlib>
2025-04-03 19:39:20
1
351
John
79,553,686
4,721,937
How to flatten a mapping constructed from a tagged scalar using ruamel.yaml
<p>My aim is to create a YAML loader that can construct mappings from tagged scalars. Here is a stripped-down version of the loader which constructs an object containing names from a scalar tagged <code>!fullname</code>.</p> <pre class="lang-py prettyprint-override"><code>import ruamel.yaml class MyLoader(ruamel.yaml....
<python><yaml><ruamel.yaml>
2025-04-03 18:06:12
1
2,965
warownia1
79,553,578
5,722,359
How to overcome slow down seen in numpy.dot of larger input sizes during convolution?
<p>I noticed a strange phenomenon while benchmarking the performances of my <code>conv2d</code> functions that were created with <code>NumPy</code>. As the input size increases, there could be a input size threshold that would cause a step slow down to the performance of the <code>conv2d</code> function. See this diagr...
<python><numpy><runtime>
2025-04-03 17:03:20
0
8,499
Sun Bear
79,553,576
11,062,613
Ensure uniform group sizes using NumPy
<p>I have a function that ensures uniform sizes for grouped data by padding missing values with a fill_value. The function currently uses a for loop to populate the padded array.</p> <p>Is there a better way to generate the padded array and get rid of the for loop using NumPy's builtin abilities (Edit: better in regard...
<python><numpy>
2025-04-03 17:02:42
2
423
Olibarer
79,553,519
12,670,598
Optimizing K_ij-free Subgraph Detection in a Bounded-Degree Graph
<p>I am working with an undirected graph G where the maximum degree is bounded by a constant d. My goal is to check whether G contains a complete bipartite subgraph K_{i,j} as a subgraph, for small values of i, j (specifically, i, j &lt; 8).</p> <p>I currently use the following brute-force approach to detect a K_{i,j} ...
<python><algorithm><graph>
2025-04-03 16:31:04
1
439
Fabian Stiewe
79,553,487
3,542,535
Build aggregated network graph from Pandas dataframe containing a column with list of nodes for each row?
<p>I'm dipping my toes into network visualizations in Python. I have a dataframe like the following:</p> <pre><code>| user | nodes | | -----| ---------| | A | [0, 1, 3]| | B | [1, 2, 4]| | C | [0, 3] | |... | | </code></pre> <p>Is there a way to easily plot a network graph (NetworkX?) from data...
<python><python-3.x><pandas><graph><networkx>
2025-04-03 16:17:33
1
413
alpacafondue
79,553,451
12,131,013
Generating a discrete polar surface map in cartesian coordinates
<p>I would like to generate a surface plot with discrete arc-shaped cells on a 2D cartesian plane. I am able to get decent results by plotting a 3D surface plot (using <code>plot_surface</code>) and viewing it from the top, but matplotlib can be a bit finicky with 3D, so I'd prefer to do it in 2D. I can also get simila...
<python><matplotlib><polar-coordinates><cartesian-coordinates>
2025-04-03 16:02:50
1
9,583
jared
79,553,048
2,859,614
How do I get a human readable string out of a Snowpark API session object?
<p>I am writing a stored procedure with Snowflake's Snowpark API, using Python as the language. I want my procedure to log every time it executes a DML statement. When I write procedures that construct the SQL strings and then execute them via <code>session.call(SQLString)</code>, this is easy - I can log the SQL str...
<python><logging><snowflake-cloud-data-platform>
2025-04-03 13:16:02
1
3,026
MackM
79,552,893
4,596,414
Ignore all printed messages to avoid "No results. Previous SQL was not a query."
<p>I am trying to execute a SQL script on SQL Server in Python using pyodbc and the driver ODBC 18 (Windows OS). The script produces a dataset with some rows in output and, during the execution, it generates also many debug informations (with <code>PRINT</code> or <code>RAISERROR('...', 0, 1)</code>) that can't be disa...
<python><sql-server><pyodbc><ignore><raiserror>
2025-04-03 12:11:50
0
309
Armando Contestabile
79,552,806
7,991,581
Print peewee model as json with foreign_keys instead of related model
<p>I'm currently exploring peewee ORM and in order to make some tests I've defined two simple databases with three tables as follow</p> <p><a href="https://i.sstatic.net/itdrmrSj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/itdrmrSj.png" alt="enter image description here" /></a></p> <p>I then defined ...
<python><orm><relationship><peewee>
2025-04-03 11:32:12
0
924
Arkaik
79,552,738
1,875,459
Create a legend taking into account both the size and color of a scatter plot
<p>I am plotting a dataset using a scatter plot in Python, and I am encoding the data both in color and size. I'd like for the legend to represent this.</p> <p>I am aware of <a href="https://matplotlib.org/api/collections_api.html#matplotlib.collections.PathCollection.legend_elements" rel="nofollow noreferrer"><code>.l...
<python><matplotlib><legend><scatter-plot>
2025-04-03 10:59:33
1
846
MBR
79,552,701
2,179,994
Python socket server recv() hangs
<p>I want to establish a simple workflow between server and client to send and receive some - currently unknown amount of - text data:</p> <ol start="0"> <li>server is running, listening</li> <li>client starts, is set up for communication</li> <li>client sends text data to server</li> <li>server receives the message in...
<python><sockets>
2025-04-03 10:44:25
0
2,074
jake77
79,552,670
6,029,488
Convert a column containing a single value to row in python pandas
<p>Consider the following dataframe example:</p> <pre><code>maturity_date simulation simulated_price realized_price 30/06/2010 1 0.539333333 0.611 30/06/2010 2 0.544 0.611 30/06/2010 3 0.789666667 0.611 30/06/2010 4 0.190333333 0.611 3...
<python><pandas>
2025-04-03 10:28:53
1
479
Whitebeard13
79,552,668
12,493,545
Tensorflow runs out of range during fitting: Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence
<p>I have a dataset containing semantic vectors of length 384. I group them to windows each containing a 100. I batch them to batch sizes of 32. However, I get an error when fitting the model. I feel like it might be because it creates 48 32-sized batches out of 1515 windows making the last batch incomplete given that ...
<python><tensorflow><keras><tf.keras>
2025-04-03 10:28:29
1
1,133
Natan
79,552,490
2,451,238
Can I pin the 'global' conda environment in Snakemake?
<p>When injecting into the Python environment running <code>snakemake</code> using the</p> <pre class="lang-none prettyprint-override"><code>conda: &quot;envs/global.yaml&quot; </code></pre> <p>directive as described <a href="https://snakemake.readthedocs.io/en/stable/snakefiles/deployment.html#global-workflow-depend...
<python><conda><snakemake>
2025-04-03 09:14:38
0
1,894
mschilli
79,552,479
224,285
Polars out of core sorting and memory usage
<p>From what I understand this is a main use case for Polars: being able to process a dataset that is larger than RAM, using disk space if necessary. Yet I am unable to achieve this in a Kubernetes environment. To replicate locally I tried launching a docker container with a low memory limit:</p> <pre><code>docker ru...
<python><kubernetes><python-polars><cgroups><polars>
2025-04-03 09:11:11
0
1,319
Nicolas Galler
79,551,855
1,946,796
How to get attributes values from an xml file (CFDI - SAT Mexico)
<p>I have a file where i can not read the attributes since the tag, looks different than usual, i have tried to use <code>lxml</code> as follow:</p> <pre class="lang-py prettyprint-override"><code>from lxml import etree xDoc = etree.parse(xmlFile) folioFiscal = xDoc.find('tfd:TimbreFiscalDigital') print(folioFiscal) <...
<python><xml>
2025-04-03 02:03:17
3
620
Rafa Barragan
79,551,824
3,225,420
How Can I Match Percentile Results in Postgres and Pandas?
<p>I am making calculations in the database and want to validate results against <code>Pandas</code>' calculations.</p> <p>I want to calculate the 25th, 50th and 75th percentile. The end use is a statistical calculation so <code>percentile_cont()</code> is the <code>Postgres</code> function I'm using.</p> <p>My query:...
<python><pandas><postgresql><percentile><percentile-cont>
2025-04-03 01:38:09
1
1,689
Python_Learner
79,551,744
2,824,791
Problems uploading certain python packages to Azure Automation Account
<p>Certain python packages fail to upload to an Azure Automation Account.</p> <p>I am trying to upload wheels for:<br /> azure-mgmt-authorization version 3.0.0 or 4.0.0</p> <p>For 4.0.0, I checked the setup.py file and found these dependencies:</p> <pre><code>install_requires=[ &quot;isodate&lt;1.0.0,&gt;=0.6.1&quo...
<python><azure><azure-runbook>
2025-04-02 23:32:26
1
5,096
jlo-gmail
79,551,690
1,185,157
drawing from OpenCV fillConvexPoly() does not match the input polygon
<p>I'm trying to follow the solution detailed at <a href="https://stackoverflow.com/questions/30901019/extracting-polygon-given-coordinates-from-an-image-using-opencv">this question</a> to prepare a dataset to train a CRNN for HTR (Handwritten Text Recognition). I'm using eScriptorium to adjust text segmentation and tr...
<python><opencv><image-processing><computer-vision><polygon>
2025-04-02 22:27:12
1
1,187
Ricardo Palomares Martínez
79,551,521
10,461,632
How can I adjust alignment in a sphinx PDF table?
<p>I want to control the vertical and horizontal alignment of the cells in a table generated with sphinx and texlive, and I want to be able to force a new line in my csv file. I'm using <code>python==3.13.2</code> and <code>sphinx==8.2.3</code></p> <p>I was able to figure out the horizontal alignment, but I haven't bee...
<python><latex><python-sphinx><pdflatex>
2025-04-02 20:29:27
0
788
Simon1
79,551,481
13,640,372
minio object Transforms with Object Lambda The security token included in the request is invalid
<p>I want to use MinIO Object Transforms, but I got an error when trying to download a presigned URL. I followed their documentation exactly, as shown in this <a href="https://min.io/docs/minio/linux/developers/transforms-with-object-lambda.html#" rel="nofollow noreferrer">link</a>.</p> <p>I also watched this <a href="...
<python><go><amazon-s3><minio>
2025-04-02 20:07:45
0
681
mohammadmahdi Talachi
79,550,825
14,818,796
How to properly handle SIGTERM in Python when stopping an Airflow task using "Mark as Failed"?
<p>I am running a long-running Python script inside an Apache Airflow DAG using BashOperator. When I manually stop the task using &quot;Mark as Failed&quot; or &quot;Mark as Success&quot;, Airflow sends a SIGTERM signal to the process.</p> <p>However, I am unable to properly catch SIGTERM and execute cleanup logic befo...
<python><airflow><sigterm>
2025-04-02 13:49:47
0
1,001
Arud Seka Berne S
79,550,761
1,159,548
Cognite Data Fusion Python SDK - how to delete edges that lead to a node with a specific target_edge_id?
<p>I am using the <a href="https://cognite-sdk-python.readthedocs-hosted.com/en/latest/data_modeling.html#delete-instances" rel="nofollow noreferrer">Cognite Data Fusion Python SDK</a>.</p> <p>While deleting a node, e.g....</p> <pre class="lang-py prettyprint-override"><code>client.data_modeling.instances.delete(NodeId...
<python>
2025-04-02 13:25:28
2
1,561
Jan Dolejsi
79,550,724
4,451,521
Error in calculating bbox coordinate Y when uploading a background image
<p>I am writing a script that loads an image and we can draw bboxes on it by pressing the key B and then dragging the mouse. However for some reason the calculation of the bboxes coordinates (specially the Y coordinate) gets wrong.</p> <p>I have managed to get a minimal reproducible code. Here it is</p> <pre><code>impo...
<python><pyqt>
2025-04-02 13:10:53
0
10,576
KansaiRobot
79,550,639
4,247,599
pandas 2.2.3: `astype(str)` returns `np.str_`
<p>Latest pandas version casts types into <code>np</code> types. To cast a series of integer to strings I thought <code>astype(str)</code> would have been enough:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import numpy as np list_of_str = list(pd.Series([1234, 123, 345]).to_frame()[0].uni...
<python><pandas>
2025-04-02 12:36:45
2
4,299
SeF
79,550,627
3,801,839
How do I select a recursive entity in sqlalchemy
<p>I am saving a graph to a database. It has a structure like:</p> <pre class="lang-py prettyprint-override"><code>class SuperNode(Base): __tablename__ = &quot;supernodes&quot; id = Column(Integer, primary_key=True) name = Column(String, nullable=False) nodes = relationship(&quot;Node&quot;, back_popu...
<python><sqlalchemy><aiosqlite>
2025-04-02 12:28:26
1
3,223
rasmus91
79,550,255
10,202,292
Pandas - custom duplicate comparison method
<p>I have browsed multiple other related questions about Pandas, and read documentation for <code>groupby</code> and <code>duplicated</code>, but I cannot seem to find a way to fit all the pieces together in Pandas. I could do this by iterating over the rows in my CSV multiple times and doing pairwise comparison, but i...
<python><pandas>
2025-04-02 09:31:05
1
403
tigerninjaman
79,550,092
8,622,814
Time limit exceeded on Leetcode 128 even for optimal time complexity
<p>I was attempting LeetCode question <a href="https://leetcode.com/problems/longest-consecutive-sequence/description/" rel="noreferrer">128. Longest Consecutive Sequence</a>:</p> <blockquote> <p>Given an unsorted array of integers <code>nums</code>, return <em>the length of the longest consecutive elements sequence</e...
<python><python-3.x><algorithm><sorting><time-complexity>
2025-04-02 08:28:26
3
2,018
Samson
79,549,881
17,729,094
How to resample a dataset to achieve a uniform distribution
<p>I have a dataset with a schema like:</p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame( { &quot;target&quot;: [ [1.0, 1.0, 0.0], [1.0, 1.0, 0.1], [1.0, 1.0, 0.2], [1.0, 1.0, 0.8], [1.0, 1.0, 0.9], [1.0, 1.0, 1.0],...
<python><dataframe><python-polars>
2025-04-02 06:46:59
1
954
DJDuque
79,549,858
1,719,931
Mirror SQL Server to DuckDB local database with SQLAlchemy: constraint not implemented
<p>I'm trying to mirror a remote SQL Server database into a local DuckDB database.</p> <p>Here is my code:</p> <pre class="lang-py prettyprint-override"><code># Connect to remote db username = &quot;USERNAME&quot; hostip = &quot;IPADD&quot; port = &quot;PORT&quot; dbname = &quot;DBNAME&quot; user_domain = &quot;USER_DO...
<python><sql-server><sqlalchemy><duckdb><database-mirroring>
2025-04-02 06:36:27
0
5,202
robertspierre
79,549,767
1,306,020
Create a new file, moving an existing file out of the way if needed
<p>What is the best way to create a new file in Python, moving if needed an existing file with the same name to a different path?</p> <p>While you could do</p> <pre><code>if os.path.exists(name_of_file): os.move(name_of_file, backup_name) f = open(name_of_file, &quot;w&quot;) </code></pre> <p>that has TOCTOU issues ...
<python><file><unix><posix><atomic>
2025-04-02 05:40:49
2
565
James Tocknell
79,549,451
18,091,627
Problems downloading files with Selenium + Scrapy
<p>This code is supposed to download some documents it most locate within series of given links. While is does seemingly locate the link of the pdf file, its failing to download it. What might be the problem?</p> <pre><code>class DownloaderSpider(scrapy.Spider): def __init__(self, *args, **kwargs): super(...
<python><selenium-webdriver><web-scraping><scrapy>
2025-04-02 01:03:59
0
371
42WaysToAnswerThat
79,549,115
16,383,578
How to correctly implement the multiplication function used by GHASH function in AES-256-GCM?
<p>I am trying to implement AES-256-GCM in Python without using any external libraries, and I have implemented encryption and decryption in AES-256-ECB, AES-256-CBC, AES-256-CTR, and AES-256-OFB modes, and I also implemented Base64 encoding and decoding plus JSON serialization and deserialization, all are working prope...
<python><encryption><cryptography><aes>
2025-04-01 20:21:29
1
3,930
Ξένη Γήινος
79,549,110
4,907,639
Huggingface tokenizer: 'str' object has no attribute 'size'
<p>I am trying to extract the hidden states of a transformer model:</p> <pre><code>from transformers import AutoModel import torch from transformers import AutoTokenizer model_ckpt = &quot;distilbert-base-uncased&quot; device = torch.device(&quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;) tokenizer ...
<python><pytorch><huggingface-transformers>
2025-04-01 20:19:35
1
2,109
coolhand
79,548,908
7,124,155
How can I apply a JSON->PySpark nested dataframe as a mapping to another dataframe?
<p>I have a JSON like this:</p> <pre><code>{&quot;main&quot;:{&quot;honda&quot;:1,&quot;toyota&quot;:2,&quot;BMW&quot;:5,&quot;Fiat&quot;:4}} </code></pre> <p>I import into PySpark like this:</p> <pre><code>car_map = spark.read.json('s3_path/car_map.json') </code></pre> <p>Now I have a dataframe:</p> <p><a href="https:...
<python><dataframe><pyspark><databricks>
2025-04-01 18:35:49
1
1,329
Chuck
79,548,872
2,072,516
Avoiding multiple sessions in integration test
<p>I'm workgin on a FastAPI app, using SQLAlchemy for the ORM, writing tests in pytest. I've got the following integration test:</p> <pre class="lang-py prettyprint-override"><code>async def test_list_items_success(authed_client, db_session): await db_session.execute(insert(Item), [{&quot;name&quot;: &quot;test1&qu...
<python><sqlalchemy><integration-testing>
2025-04-01 18:13:37
0
3,210
Rohit
79,548,754
6,936,582
Reshape 4D array to 2D
<p>I have the array</p> <pre><code>import numpy as np a1 = [[&quot;a1&quot;, &quot;a2&quot;], [&quot;a3&quot;, &quot;a4&quot;], [&quot;a5&quot;, &quot;a6&quot;], [&quot;a7&quot;, &quot;a8&quot;]] b1 = [[&quot;b1&quot;, &quot;b2&quot;], [&quot;b3&quot;, &quot;b4&quot;], [&quot;b5&quot;, &...
<python><numpy>
2025-04-01 13:19:44
5
2,220
Bera
79,548,632
8,837,496
Transitive file dependencies break pipenv / Pipfile.lock
<p>To avoid running a private a pypi server, we store our wheels on a file server and reference them in Pipfiles using like <code>foo = { file = &quot;\\\\server\\foo-0.1.20-py3-none-any.whl&quot; }</code></p> <p>This works, but we now want to create wheels that require other local packages. To this end we have a build...
<python><setuptools><pipenv>
2025-04-01 12:26:13
0
331
sAm_vdP
79,548,517
9,473,420
How to use RedMon for generating multiple outputs? TSPL and PDF
<p>I have printer TSC TE 210. I created virtual printer on a RedMon port and installed TSC driver on it. I am able to generate printfile.prn file using redmon (redirecting output to python, that will edit the data and create .prn file), that has TSPL commands it it, e.g.:</p> <pre><code>SIZE 97.6 mm, 50 mm GAP 3 mm, 0 ...
<python><pdf><printing><tsc><redmon>
2025-04-01 11:37:39
1
387
victory
79,548,494
12,057,138
Locust distributed mode: "Unknown message type '_distributor_request' from worker.." warning halts users
<p>I am using Locus in distributed mode with 1 master and n workers to run a load test.</p> <p>I am also using the locust-plugins library to utilize its Distributor utility. My goal is to preallocate one unique resource per user (from a list of “items”) and ensure each virtual user gets a unique item during the test. H...
<python><load-testing><locust>
2025-04-01 11:25:43
1
688
PloniStacker
79,548,408
5,722,359
How to show a figure by matplotlib which is added by uv onto a tmpfs/ramdisk?
<p>I want to plot a <code>matplotlib</code> figure in a python virtual environment located in a <code>tmpfs</code> folder that was created by <code>uv</code> but can't.</p> <p>This is what I did:</p> <p>Step 1:</p> <pre><code>$ mkdir /dev/shm/test $ cd /dev/shm/test $ uv init --python 3.13 --cache-dir .cache $ uv add m...
<python><matplotlib><ramdisk><tmpfs><uv>
2025-04-01 10:47:44
2
8,499
Sun Bear
79,548,332
1,211,072
sqlAlchemy to_sql with azure function returning collation error, but work without issues if executing just the python file
<p>I have written a python method to form a pandas df and upsert it into sqlserver. This method works perfectly fine when I try to execute the python file alone. But it throws collation exception when I try to run via Azure functions.</p> <p>Here is my code:</p> <pre><code>import pandas as pd from sqlalchemy import cre...
<python><sql-server><pandas><sqlalchemy><azure-functions>
2025-04-01 10:18:02
1
1,365
Ramaraju.d
79,548,304
14,731,895
How to get the alignment in Python Codes accurately in Visual Studio
<p>I am trying to write this code in Python in Visual Studio. For some reason I cant get the code to align automatically.</p> <p>I wrote this code, based on Syntax, the code is not wrong but I cant get Python to create the <em>Secondary_Key</em> and based on my understanding its because the <code>.assign</code> doesnt ...
<python><dataframe><visual-studio>
2025-04-01 10:06:55
1
363
Mr Pool
79,548,243
1,142,881
How to do a groupby on a cxvpy Variable? is there a way using pandas?
<p>I would like to define a loss function for the CVXPy optimization that minimizes differences from the reference grouped target:</p> <pre><code>import cvxpy as cp import pandas as pd # toy example for demonstration purpose target = pd.DataFrame(data={'a': ['X', 'X', 'Y', 'Z', 'Z'], 'b': [1]*5}) w = cp.Variable(targe...
<python><pandas><cvxpy>
2025-04-01 09:39:55
1
14,469
SkyWalker
79,548,219
284,696
Using `setattr` to decorate functions from another module
<p>I'm having trouble applying a decorator to an imported function. Suppose I have the following <code>foo.py</code> module:</p> <pre class="lang-py prettyprint-override"><code># contents of foo.py def bar(): return &quot;hello&quot; </code></pre> <p>I now want to import <code>bar</code> from it and apply the <code...
<python><import><setattr>
2025-04-01 09:28:18
1
2,826
Anthony Labarre
79,548,185
1,720,199
Propagate assertion type check to caller
<p>I want to assert the type of an object in a function without having to return it, but I can't find how to do it.</p> <p>For example:</p> <pre class="lang-py prettyprint-override"><code>from typing import Optional, TypeVar T = TypeVar('T') def assert_non_null(_object: Optional[T]): assert _object is not None d...
<python><python-typing>
2025-04-01 09:14:27
0
11,323
cglacet
79,548,159
2,881,414
Proper way of building a package with tox
<p>I'm using tox and wonder what is the intended way to build my package for distribution. I see that tox is building the package as part of the <a href="https://tox.wiki/en/latest/user_guide.html#system-overview" rel="nofollow noreferrer">normal execution</a>. It even provides a <a href="https://tox.wiki/en/latest/upg...
<python><python-3.x><tox>
2025-04-01 09:03:05
0
17,530
Bastian Venthur
79,548,083
16,312,980
sqlite table does not exist within gradio blocks or GradioUI even after creating said table
<p>I am trying this out: <a href="https://huggingface.co/docs/smolagents/examples/text_to_sql" rel="nofollow noreferrer">https://huggingface.co/docs/smolagents/examples/text_to_sql</a> in my hf space as a pro user. For some reason <code>GradioUI(agent).launch()</code> can't detect the sqlite tables. even though the pri...
<python><agent><gradio>
2025-04-01 08:26:07
1
426
Ryan
79,548,070
3,053,806
Why does Python pass an instance to a class attribute that is a function?
<p>I define a class attribute and give it a function. When I call this function, the instance is passed on as the first argument (as if it's an instance function call with a <code>self</code>). I would not expect an instance to care that the attribute <code>fn</code> is a function, let alone for it to pass itself as an...
<python><python-internals>
2025-04-01 08:21:08
1
821
msrc
79,547,850
12,645,056
Why is the bounding box not aligned to the square?
<pre class="lang-py prettyprint-override"><code>import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Rectangle def generate_square_image(size, square_size, noise_level=0.0): &quot;&quot;&quot; Generates an image with a white square in the center. Args: size (int): The ...
<python><numpy><matplotlib>
2025-04-01 06:18:42
1
325
Academic
79,547,849
1,838,076
Session state is not respected when the options are not identical
<p>In the example, <code>Radio 1</code> and <code>Radio 2</code> start with <code>Option 2</code> as default value set via <code>st.session_state</code>.</p> <p>When I change the valid options (via button callback),</p> <p><code>Radio 2</code> retains the value while <code>Radio 1</code> resets itself to the first valu...
<python><streamlit>
2025-04-01 06:18:34
0
1,622
Krishna
79,547,780
6,734,243
How to add a dash component as a dash-leaflet custom control?
<p>I'm slowly discovering the <code>dash-leaflet</code> interface coming from ipyleaflet widget lib and there are still some tasks that I don't manage to achieve.</p> <p>Here I would like to add a dash componenent (in this case a dropdown select) and place it on the map as control so it fits consistently with the leafl...
<python><plotly-dash><dash-leaflet>
2025-04-01 05:36:54
1
2,670
Pierrick Rambaud
79,547,639
17,729,094
Larger-than-memory dataset with polars
<p>I have a parquet file with a dataset that looks like:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.LazyFrame( { &quot;target&quot;: [ [1.0, 2.0], [3.0, 4.0], ], &quot;point_cloud&quot;: [ [ [7.0, 8.0],...
<python><dataframe><parquet><python-polars>
2025-04-01 02:54:10
1
954
DJDuque
79,547,588
7,535,975
uv pip install fails for multiple packages
<p>I'm having some weird behavior when trying to install multiple packages with <code>uv</code> as follows</p> <pre><code>uv pip install --system spatialpandas \ easydev \ colormap \ colorcet \ duckdb \ dask_geopandas \ ...
<python><pip><uv>
2025-04-01 02:07:06
1
377
F Baig
79,547,573
1,939,638
Alteryx workflow with single python node failing
<p>I have an Alteryx Workflow that runs a notebook. When I run the notebook by itself, it works just fine. When I run the workflow, I receive this error</p> <pre><code> Python (1) Failed to run Python command. Make sure you have all the packages you need to run the command.: The system cannot find the file specifie...
<python><jupyter-notebook><alteryx>
2025-04-01 01:45:54
0
5,191
Matt Cremeens
79,547,567
1,245,659
Creating a child table record, when a new parent table record is created
<p>I have this model:</p> <pre><code>from django.db import models from django.contrib.auth.models import User from django.templatetags.static import static from simple_history.models import HistoricalRecords from treebeard.mp_tree import MP_Node from . import constants from datetime import datetime class Profile(mod...
<python><django><django-models>
2025-04-01 01:37:16
1
305
arcee123
79,547,465
5,256,563
Parallel processing with arguments to modify
<p>I need to parallelize a function that modifies values of one of the arguments. For example modify this simple code:</p> <pre><code>def Test(i, a, length): if i % 2 == 0: for x in range(0, length, 2): a[x] = 2 else: for x in range(1, length, 2): a[x] = 1 a0 = numpy.nda...
<python><python-3.x><parallel-processing><multiprocessing><joblib>
2025-04-01 00:11:13
1
5,967
FiReTiTi
79,546,867
491,605
cancel S3 Download in python
<p>I have a client app, that downloads potentially big files from S3. I want to give the user the option to cancel that download, without stopping/killing the whole app. Doing some research, that seems to be an suprisingly different task:</p> <ul> <li><code>boto3</code> does not support canceling S3 downloads :(.</li> ...
<python><amazon-web-services><amazon-s3>
2025-03-31 17:18:21
1
7,811
Nathan
79,546,809
6,275,400
Animate Google Earth Engine Image
<p>Hi StackOverflow Community,</p> <p>I have year-over-year images that I have pulled from Google Earth Image, and I want to animate them so that it's easier to analyze.</p> <p>I tried to use Folium, which has a plugin that enables the animation with a slider. (i.e. <a href="https://python-visualization.github.io/foliu...
<python><folium><google-earth-engine><folium-plugins>
2025-03-31 16:49:33
0
1,361
Fxs7576
79,546,777
1,420,553
Saving and Loading Images for Tensorflow Lite
<p>Planning on using Tensorflow Lite for image classification.</p> <p>To test the model, using Fashion-MNIST database to create the model following a Tensorflow basic example from their website. Created and saved the model and want to test it in TF Lite.</p> <p>I want to save an image from the mentioned database to pre...
<python><tensorflow><deep-learning><python-imaging-library><tensorflow-lite>
2025-03-31 16:33:41
2
369
gus
79,546,776
11,156,131
dbutils secret issue for container url
<p>I am trying to access a blob storage like this and it works</p> <pre><code>from azure.storage.blob import ContainerClient storage_account_name ='storage_account_name' storage_container_name = 'storage_container_name' sas_token = 'sv=&lt;&gt;&amp;si=&lt;&gt;&amp;sr=&lt;&gt;&amp;sig=&lt;&gt;' account_url = &quot;htt...
<python><azure-blob-storage><databricks><azure-storage><dbutils>
2025-03-31 16:32:46
1
4,376
smpa01
79,546,738
7,233,155
MyPy fails to narrow type on `isinstance`
<p>I have a large codebase which has been working successfully with <code>mypy</code> for many months. Recent additions have started to create spurious and seemingly unconnected issues.</p> <p>For example I have recently got the following error, without modifying <code>VObj</code> at all - just adding objects in the sa...
<python><python-typing><mypy>
2025-03-31 16:16:52
1
4,801
Attack68
79,546,549
18,499,990
Anaconda Python3 virtual environment unable to recognise local modules
<p>I'm reproducing a project code and trying to execute it locally.</p> <p>It uses Python 3.6 and old packages dating to 2017 and PIP struggles to install them and returned error codes which were 40 pages long.</p> <p>My friend suggested me to use Anaconda to setup a virtual environment and use conda environment to ins...
<python><python-3.x><anaconda><conda><python-module>
2025-03-31 14:51:23
1
371
SpaciousCoder78
79,546,240
6,101,024
Shuffle a dataset w.r.t a column value
<p>I have the following Dataframe, which contains, among others, UserID and rank_group as attribute:</p> <pre><code> UserID Col2 Col3 rank_group 0 1 2 3 1 1 1 5 6 1 ... 20 1 8 9 2 21 1 11 12 2 ... 45 1 14 15 3 46 1 17 18 3 47 2 2...
<python><pandas><dataframe><numpy><shuffle>
2025-03-31 12:34:27
1
697
Carlo Allocca
79,546,174
2,050,262
Fabric PySpark Notebook Parsing JSON string with double quote escape chars
<p>I am working in a PySpark notebook that gets its input parameter as a JSON String from a Pipeline and the notebook need to process the string further. Below is the example string that the notebook gets as input and example code that try to process the string and fails because the Details section has text enclosed wi...
<python><pyspark><jupyter-notebook>
2025-03-31 12:04:26
1
4,296
Prabhat
79,545,985
2,919,585
Find correct root of parametrized function given solution for one set of parameters
<p>Let's say I have a function <code>foo(x, a, b)</code> and I want to find a specific one of its (potentially multiple) roots <code>x0</code>, i.e. a value <code>x0</code> such that <code>foo(x0, a, b) == 0</code>. I know that for <code>(a, b) == (0, 0)</code> the root I want is <code>x0 == 0</code> and that the funct...
<python><scipy><numerical-methods><scipy-optimize>
2025-03-31 10:14:17
2
571
schtandard
79,545,926
4,999,991
Python pyserial can't access com0com virtual serial ports even though they appear in Device Manager and com0com GUI
<p>I've set up virtual COM ports with com0com (COM20 and COM21), but I'm having trouble accessing them through Python's pyserial.</p> <h3>What I've tried</h3> <p>I can successfully create the port pair using com0com's <code>setupc.exe</code>:</p> <pre><code>&gt; setupc.exe install PortName=COM20 PortName=COM21 </code><...
<python><windows><serial-port><pyserial><com0com>
2025-03-31 09:37:35
0
14,347
Foad S. Farimani
79,545,895
8,144,957
Image upload corruption with SeaweedFS S3 API
<h2>Problem Description</h2> <p>I'm experiencing an issue where images uploaded through Django (using boto3) to SeaweedFS's S3 API are corrupted, while uploads through S3 Browser desktop app work correctly. The uploaded files are 55 bytes larger than the original and contain a <code>Content-Encoding: aws-chunked</code>...
<python><django><boto3><seaweedfs>
2025-03-31 09:20:25
1
328
Nguyễn Anh Bình
79,545,706
3,676,517
What is the difference between an xarray Dataset and a DataArray?
<p>According to <a href="https://docs.xarray.dev/en/stable/user-guide/data-structures.html#dataarray" rel="nofollow noreferrer">the xarray documentation</a>:</p> <blockquote> <p><code>xarray.DataArray</code> is xarray’s implementation of a labeled, multi-dimensional array.</p> </blockquote> <p>To me, this means a <code...
<python><python-xarray>
2025-03-31 07:34:26
1
1,113
Jommy
79,545,545
9,078,142
Does comparing the substring of two strings create new strings in Python?
<p>If I do <code>string_a[i:i + k] == string_b[j:j + k]</code>, is this inefficient because slicing creates a new string because strings are immutable? Or does Python optimize this?</p> <p>Is it possible that using a for loop and comparing character by character could be more efficient?</p> <p>I'm not sure that stackov...
<python><algorithm>
2025-03-31 05:31:44
1
495
dan dan
79,545,452
12,096,670
SAS if-then Statement to Python Vectorized Approach - My Values are Not Matching Up
<p>I am trying to replicate some values in a dataset. The original data that I am running my code against for verification purposes has two categories across multiple groups, like so:</p> <pre><code>grp5 0 3941 1 459 grp6 0 4120 1 ...
<python><if-statement><conditional-statements><sas>
2025-03-31 03:36:44
0
845
GSA
79,545,386
327,026
Inverse groupby to assign parent dataframe?
<p>I have irregular 3D point data that looks something like this:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd xx, yy = np.meshgrid( np.linspace(-50, 50, 101), np.linspace(-50, 50, 101), ) rng = np.random.default_rng(12345) xx += rng.normal(size=101 * 101).reshape(...
<python><pandas><group-by>
2025-03-31 02:01:19
1
44,290
Mike T
79,545,334
3,423,768
How to avoid redundant manual assignment of environment variables in Django settings?
<p>In my Django project, I store configuration variables in a .env file for security and flexibility. However, every time I introduce a new environment variable, I have to define it in two places: <code>.env</code> and <code>settings.py</code>.</p> <p>As the project grows and the number of environment variables increas...
<python><python-3.x><django>
2025-03-31 00:51:45
0
2,928
Ravexina
79,545,103
2,856,552
Plotting date on x-axis from integers converted to dates
<p><a href="https://i.sstatic.net/tdu1Elyf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tdu1Elyf.png" alt="Final output" /></a>In my python code, reproduced below, where I sought assistance here <a href="https://stackoverflow.com/questions/79542474/results-of-assistance-with-a-simple-python-line-plot"...
<python>
2025-03-30 20:06:04
1
1,594
Zilore Mumba
79,545,102
2,233,683
how to properly refresh access token for google pubsub_v1.SubscriberClient
<p>In my fast api server, it subscribes to the google realtime developer notifications.</p> <p>python version 3.12.7 &quot;google-cloud-pubsub (&gt;=2.29.0,&lt;3.0.0)&quot;</p> <p>The subscriber can be successfully initialized as below:</p> <pre><code> # self.credentials is a dict from google service account...
<python><google-cloud-platform><google-play>
2025-03-30 20:06:02
0
3,090
GeauxEric
79,545,081
3,604,745
Why does YOLO download a nano v11 model (yolov11n) when given the extra larger v12 weights (yolov12x)?
<p>I run the following YOLO code with extra large v12 weights, yet it seems to download the yolov11n model for some reason and uses that. I'm trying to understand this behavior, as I don't see it in the <a href="https://docs.ultralytics.com/modes/train/#train-settings" rel="nofollow noreferrer">documentation</a>.</p> <...
<python><machine-learning><yolo><yolov11>
2025-03-30 19:43:01
0
23,531
Hack-R
79,544,866
2,648,551
How to automatically update extra column in sqlalchemy association table?
<p>I have a <a href="https://www.postgresql.org/" rel="nofollow noreferrer">postgresql database</a> setup with <a href="https://www.sqlalchemy.org/" rel="nofollow noreferrer">sqlalchemy</a>, <a href="https://docs.sqlalchemy.org/en/20/orm/inheritance.html#joined-table-inheritance" rel="nofollow noreferrer">joined table ...
<python><postgresql><sqlalchemy><many-to-many>
2025-03-30 16:23:12
2
4,850
colidyre
79,544,819
6,394,092
Conversion of model weights from old Keras version to Pytorch
<p>I want to transfer pretrained weights from an old project on github : <a href="https://github.com/ajgallego/staff-lines-removal" rel="nofollow noreferrer">https://github.com/ajgallego/staff-lines-removal</a></p> <p>The original Keras model code is:</p> <pre><code>def get_keras_autoencoder(self, input_size=256, nb_fi...
<python><machine-learning><keras><pytorch><computer-vision>
2025-03-30 15:41:21
0
373
MaxC2
79,544,458
4,061,339
Sending request from React to FastAPI causes a CORS policy error
<p>When I send a fetch request from the frontend server (React) to the backend server (FastAPI), an error occurs:</p> <blockquote> <p>localhost/:1 Access to fetch at 'http://localhost:8000/predict/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access co...
<python><reactjs><typescript><cors><fastapi>
2025-03-30 10:38:10
3
3,094
dixhom
79,544,423
3,231,250
Fastest way to search 5k rows inside of 100m row pair-wise dataframe
<p>I am not sure title is well describing the problem but I will explain it step by step.</p> <p>I have a correlation matrix of genes (10k x 10k) I convert this correlation matrix to pairwise dataframe (upper triangle) (around 100m row)</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>gene1</...
<python><pandas><numba>
2025-03-30 10:07:27
1
1,120
Yasir
79,544,253
8,157,102
Image size inconsistency between GitHub and PyPI in README.md
<p>I created some simple console games in Python(<a href="https://github.com/kamyarmg/oyna" rel="nofollow noreferrer">Oyna Project</a>) and took screenshots of each game to showcase them in the <a href="https://github.com/kamyarmg/oyna/blob/main/README.md" rel="nofollow noreferrer">README.md</a> file. I wanted to displ...
<python><html><css><pypi><markup>
2025-03-30 06:37:58
1
961
kamyarmg
79,544,085
1,204,556
Python Reactivex and OpenAI -- Stream hangs?
<p>Please see my code block below. In order to run it, I do the following. When I run the following code, things print as expected, and the process exits as expected.</p> <pre><code>stream = await client.create_completion(...) stream.subscribe(print) # works perfectly </code></pre> <p>All the <code>print</code> command...
<python><stream><observable><python-asyncio><reactivex>
2025-03-30 01:05:24
0
5,084
Monarch Wadia
79,544,072
12,156,208
Is there a way to pre-select options for certain columns in streamlit.data_editor?
<p>I am trying to render a streamlit data_editor object but in a way where the user can only select set options for each column.</p> <p>For eg:</p> <pre><code> data = pd.DataFrame(columns=[&quot;Stock&quot;, &quot;Option&quot;]) request = st.data_editor(data, num_rows=&quot;dynamic&quot;, use_container_width=True) </c...
<python><python-3.x><streamlit>
2025-03-30 00:42:57
0
1,206
r4bb1t
79,543,756
242,042
Can I use asyncio.Event.wait() instead of gRPC await server.wait_for_termination()
<p>The typical approach for gRPC AsyncIO is</p> <pre class="lang-py prettyprint-override"><code>await server.start() try: await server.wait_for_termination() except: ... </code></pre> <p>But I was wondering rather than dealing with it via a hard stop because <code>wait_for_termination</code> just blocks forever unt...
<python><python-asyncio><grpc><grpc-python>
2025-03-29 19:00:30
0
43,097
Archimedes Trajano
79,543,653
500,584
How do I use uv run with os.exec?
<p>I'm running into a problem trying to use <code>uv run</code> with Python's <code>os.exec</code> variants. Any advice on how to get this to work?</p> <p>Bash, Ubuntu WSL, <code>uv run python</code>, <code>execlp</code>, <code>uv 0.6.5</code>:</p> <pre><code>$ uv run python Python 3.12.9 (main, Feb 12 2025, 14:50:50) ...
<python><os.execl>
2025-03-29 17:38:52
1
178,002
agf
79,543,394
189,418
How to load PEP-723-style venvs in vscode automatically
<p>When writing Python scripts, I have started using the pattern from PEP-723 with uv to create self contained scripts that uv can run directly.</p> <p>For example, here's the metadata in one of my Python scripts, which instructs uv to create a venv with <code>duckdb</code> and <code>pandas</code> to run the script:</p...
<python><visual-studio-code><uv>
2025-03-29 14:39:13
1
8,426
foglerit
79,543,279
3,545,273
How to find the possible installation paths for a script from Python?
<h3>Context</h3> <p>I am working on a Python + Pyside6 application. I would like to only archive the source <code>.ui</code> files that are use to define the User Interface in Qt and have them compiled into <code>.py</code> files at build time.</p> <h3>Current research</h3> <p><code>Pyside6</code> comes with a tool tha...
<python>
2025-03-29 12:58:28
1
149,980
Serge Ballesta