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,795,029
4,256,387
Cython memoryviews of Python object members with fused types
<p>I am writing cython code with cython v3.1.5.</p> <p>I have defined these fused types:</p> <pre><code>ctypedef fused index_t: int32_t int64_t ctypedef fused value_t: double double complex </code></pre> <p>and am trying to use this code to initialize my <code>UMFFactor</code> object with a <code>scipy...
<python><cython><suitesparse>
2025-10-20 15:10:49
1
404
Bernie Roesler
79,794,971
14,586,554
Fast vectorized maximal independent set greedy algorithm
<p>I need a really fast vectorized maximal independent set algorithm implemented in <code>pytorch</code>, so I can use it for tasks with thousands of nodes in reasonable time.</p> <p>I cannot use <code>networkx</code>, it is way too slow for my needs.</p> <p>I don't need an exact algorithm, a rough greedy approximation...
<python><algorithm><pytorch>
2025-10-20 13:58:38
1
620
Kemsikov
79,794,935
110,963
Isolation of a custom multiprocessing manager and how to update internal state
<p>I try to use a <a href="https://docs.python.org/3/library/multiprocessing.html#customized-managers" rel="nofollow noreferrer">custom multiprocessing manager</a>, mostly following the example from the docs. The main difference is that my class updates internal state. It looks like this:</p> <pre><code>class IdIndex: ...
<python><multiprocessing><python-multiprocessing>
2025-10-20 13:13:08
1
15,684
Achim
79,794,914
1,783,801
Are GTK2 default translations accessible from Python
<p>When using GTK2 with Python, there are some things like <code>'gtk-yes'</code>, <code>'gtk-open'</code> which help in getting e.g. button names translated to the according user language.</p> <p>What I am searching for are more of these: especially the string 'recently used', like in the file open dialog, and strings...
<python><python-2.7><gtk><gtk2>
2025-10-20 12:50:03
1
670
Jaleks
79,794,882
1,446,710
Tkinter: treeview inner lines' styling
<p>I managed to style a treeview control to this nice gridview:</p> <p><a href="https://i.sstatic.net/Jp5eYoL2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jp5eYoL2.png" alt="enter image description here" /></a></p> <pre><code>container = tk.Frame(self, relief='sunken', borderwidth=1, bg='white') cont...
<python><tkinter>
2025-10-20 12:17:23
0
2,725
Daniel
79,794,872
9,740,712
How to specify the name while concurrently removing indexes from database
<p>I have some field in my table for which i need to remove indexing. In the django application, i saw that i could do this using the migrations.RemoveIndexConcurrently() method. However im having confusions on how to specify the name attribute with it. The previously said indexed fields were added during the time of c...
<python><django><postgresql><indexing>
2025-10-20 11:59:50
0
499
p.ry
79,794,657
8,936,561
How to build a single-file namespace library with uv?
<p>I have a project structured like this:</p> <pre class="lang-none prettyprint-override"><code>&lt;project-root&gt; ├── pyproject.toml └── src └── a_namespace └── a_module.py </code></pre> <p>With Poetry, I can install and package this project using the following settings:</p> <pre class="lan...
<python><uv>
2025-10-20 06:45:56
1
988
Nattōsai Mitō
79,794,605
1,446,710
How can I set 25-25-50 ratio between grid children?
<p>In tkinter I wish to achieve the above goal.</p> <p>I can perfectly get 50-50, and 25-25-25-25. But tried everything to get 25-25-50 without success:</p> <pre><code>import tkinter as tk root = tk.Tk() root.geometry(&quot;900x300&quot;) frame = tk.Frame(root) frame.pack(fill=&quot;both&quot;, expand=True) # 25%, 2...
<python><tkinter>
2025-10-20 04:40:11
1
2,725
Daniel
79,794,169
835,073
Can we preserve the ordering of polynomial terms with sympy?
<p>I want to render <code>y - x^2</code> rather than <code>-x^2 +y</code> below.</p> <pre class="lang-py prettyprint-override"><code>def f(x, y): return y - x**2 # this expression will be changed later on # so the rendered output must respect it! </code></pre> <p><a href="https://i.sstatic.net/AXsFta8J.png" rel="no...
<python><sympy>
2025-10-19 08:26:56
1
880
D G
79,793,948
5,709,144
Problem installing jupyter-book 2 with the uv package manager
<p>I am attempting to create a jupyter book 2.0 (<a href="https://next.jupyterbook.org/" rel="nofollow noreferrer">https://next.jupyterbook.org/</a>) project in a virtual envinoment managed by the <code>uv</code> package manager (<a href="https://docs.astral.sh/uv/" rel="nofollow noreferrer">https://docs.astral.sh/uv/<...
<python><uv><jupyterbook>
2025-10-18 20:11:56
3
1,216
amunnelly
79,793,899
1,232,087
pip uninstall fails for databricks-dlt library
<p>In Databricks, I had installed Databricks dlt library from <a href="https://pypi.org/project/databricks-dlt/" rel="nofollow noreferrer">here</a> using the command <code>pip install databricks-dlt</code>. But now when I try to uninstall using the command <code>pip uninstall databricks-dlt</code>, I get the following ...
<python><pip><databricks>
2025-10-18 18:02:14
1
24,239
nam
79,793,878
3,741,030
Combining Identically Indexed and Column Dataframes into 3d Dataframe
<p>I have 3 2D DataFrames, all with identical indexes (datetime range) and column names, but different data for these labels. I would like to combine these three 2D dataframes into 1 3D DataFrame with an additional index.</p> <p>Brief example, suppose I have 3 2D DataFrames <code>a, b, c</code> where <code>a['name']['i...
<python><pandas><dataframe><numpy>
2025-10-18 17:14:12
2
1,599
cma0014
79,793,610
1,867,328
Calculating mean for a column of arrays in pandas
<p>I have below <code>pandas</code> dataframe</p> <pre><code>import pandas as pd import numpy as np dat = pd.DataFrame({ 'A': [1,2,3], 'B': [[[np.nan, 0.0, 0.0, 0.0, 0.0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]], [[0.32894736842105265, 0.039473684210526314, 0.00986842105263...
<python><pandas>
2025-10-18 06:51:08
1
3,832
Bogaso
79,793,500
1,604,008
How do I import a base class into derived classes?
<p>Forgive me, I'm new to python. I hope I'm missing something.</p> <p>Consider the following directory structure:</p> <pre><code>dev baseClass SomeApplication main1 DerivedClassA_usedInMain1 SomeOtherApp main2 DerivedClassB_usedInMain2 </code></pre> <p>I don't see any 'reali...
<python><class><oop><import>
2025-10-17 23:59:15
0
1,159
user1604008
79,793,455
219,153
Is there a Pythonic way to get a value of a variable in a "case" statement?
<p>Python match statement creates problems with constants, e.g. this script will not compile:</p> <pre><code>A, B = 13, 42 x = A match x: case A: print('a') # case int(A): print('a') # case 13: print('a') case B: print('b') </code></pre> <p>unless one of commented out lines is used instead. Is there a mor...
<python><structural-pattern-matching>
2025-10-17 21:51:42
0
8,585
Paul Jurczak
79,793,436
984,003
Stripe checkout.Session.create : if/else for parameters for Python
<p>I have the following call to make a checkout session.</p> <pre><code> session = stripe.checkout.Session.create( success_url=success_url, cancel_url=cancel_url, mode='payment', line_items=[{ 'price': price_id, 'quantity': 1 }], payment_intent_dat...
<python><stripe-payments>
2025-10-17 21:18:30
1
29,851
user984003
79,793,423
13,785,011
PyCharm autoformatter aggressively wraps SQL keywords inside Python triple-quoted strings
<p>I’m writing SQL inside Python using triple-quoted strings, like this:</p> <pre><code>schema = &quot;&quot;&quot; CREATE TABLE IF NOT EXISTS peers ( id INTEGER PRIMARY KEY AUTOINCREMENT, host TEXT NOT NULL, port INTEGER NOT NULL, UNIQUE (host, port) ) &quot;&quot;&quot; </code>...
<python><pycharm><formatting>
2025-10-17 20:46:14
1
469
Unlucky
79,793,380
1,232,087
Unable to import pyspark.pipelines module
<p>What could be a cause of the following error of my code in a Databricks notebook, and how can we fix the error?</p> <pre class="lang-none prettyprint-override"><code>ImportError: cannot import name 'pipelines' from 'pyspark' (/databricks/python/lib/python3.12/site-packages/pyspark/__init__.py) </code></pre> <p>This ...
<python><pyspark><databricks>
2025-10-17 19:09:26
1
24,239
nam
79,793,348
388,520
cartopy - round polar projections for just the polar regions?
<p>I am trying to draw a pair of round polar projections centered on the north and south (celestial) poles as an adjunct to a more conventional star map. These should only cover about 20 degrees of latitude each.</p> <p>I can get cartopy to draw reasonable-looking polar projections of <em>the entire celestial sphere</...
<python><matplotlib><cartopy>
2025-10-17 18:29:16
1
142,389
zwol
79,793,337
11,091,255
Transferring large file over CAN with Python canopen library unexpectedly aborts early
<p>We are attempting to implement firmware updates with CANopenNode. It would seem that to do this the new firmware image needs to be sent to object dictionary entry 0x1F50:1. When we try this, the process exits early, and not always after sending the same number of bytes. At times, it could fail after sending a few ...
<python><canopen>
2025-10-17 18:11:14
0
305
Christopher Theriault
79,793,215
1,708,977
Significant import discrepancy in Python CDK v2 when enabling API Gateway logging
<p>I have been modifying an AWS CDK v2 stack (Python) to generate an API Gateway v2 stage with logging enabled. Sounds simple, there are countless examples on the internet, and countless agentic coding tools willing to generate it. Yet, not one of them works for me.</p> <p>My existing CDK snippet looks like:</p> <pre c...
<python><aws-api-gateway><aws-cdk>
2025-10-17 15:29:00
1
725
Bit Fracture
79,792,858
11,571,390
How to drop rows with a boolean mask in xarray/dask without .compute() blowing up memory?
<p>I’m trying to subset a large <code>xarray.Dataset</code> backed by <code>Dask</code> and save it back to Zarr, but I’m running into a major memory problem when attempting to drop rows with a boolean mask.</p> <p>Here’s a minimal working example that matches my real-world setup:</p> <pre><code>import numpy as np impo...
<python><dask><python-xarray>
2025-10-17 07:41:49
0
595
Gary Frewin
79,792,772
3,433,802
How do I represent relationships? I get errors anyway I try
<p>I have a sqlmodel defined database and I'm having issues with how to use sqlmodel. This is a two-table reduction of my DB.</p> <pre><code>from __future__ import annotations import uuid from datetime import datetime from sqlalchemy import ( Column, DateTime, ForeignKey, String, Text, UniqueC...
<python><sqlalchemy><pydantic><sqlmodel>
2025-10-17 05:42:26
0
1,982
mmachenry
79,792,709
395,857
How can I serve OpenGVLab/InternVL3-1B with vLLM? Getting "ValueError: Failed to apply InternVLProcessor" error upon initialization
<p>How can I serve OpenGVLab/InternVL3-1B with vLLM?</p> <p>I tried running:</p> <pre><code>conda create -y -n vllm312 python=3.12 conda activate vllm312 pip install vllm vllm serve OpenGVLab/InternVL3-1B --trust_remote_code </code></pre> <p>but I get the &quot;ValueError: Failed to apply InternVLProcessor&quot; error ...
<python><vllm>
2025-10-17 03:14:33
0
84,585
Franck Dernoncourt
79,792,670
395,857
How can I run the inference on the HunyuanImage-3.0 model?
<p>I follow the instructions on <a href="https://github.com/Tencent-Hunyuan/HunyuanImage-3.0" rel="nofollow noreferrer">https://github.com/Tencent-Hunyuan/HunyuanImage-3.0</a>:</p> <pre><code>conda create -y -n hunyuan312 python=3.12 conda activate hunyuan312 # 1. First install PyTorch (CUDA 12.8 Version) pip install ...
<python><artificial-intelligence><image-generation><tencent>
2025-10-17 00:58:16
0
84,585
Franck Dernoncourt
79,792,257
12,415,855
Creating EMA using TA_Lib with python?
<p>i try to create an EMA calculation for a stock using talib with the following code:</p> <pre><code>import yfinance as yf from datetime import datetime, timedelta import talib tday = datetime.today() startDay = tday - timedelta(days=365) df = yf.download(&quot;AAPL&quot;, start=startDay, end=tday) tmpErgSe...
<python><yfinance><ta-lib>
2025-10-16 14:18:09
1
1,515
Rapid1898
79,792,241
696,836
Watching for changes on an array of a document in a Mongo collection only triggers on the second push, not the first
<p>Say I have a document in a Mongo collection that looks like the following:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;_id&quot;: &quot;01:550204&quot;, &quot;somefield1&quot;: &quot;someValue1&quot;, &quot;somefield2&quot;: &quot;someValue2&quot;, &quot;homeTime&quot;: { &quot;homeTime...
<python><mongodb><mongodb-query>
2025-10-16 14:07:30
0
2,798
djsumdog
79,792,205
577,288
threading.Thread cannot catch a PyCharm "stop" button termination event
<p>I am using Pycharm. When I click the &quot;stop&quot; button, the <code>subprocess.Popen</code> deletes the left over <code>.bat</code> files. But after putting the <code>subprocess.Popen</code> inside a <code>threading.Thread</code> function, the <code>.bat</code> files are no longer deleted.</p> <p>Here is some ex...
<python><subprocess><python-multithreading>
2025-10-16 13:35:07
2
5,408
Rhys
79,792,087
12,415,855
ScrollDown using Selenium
<p>i try to scrolldown on a website using selenium with the following code: (i would like to scroll down on the left side of the website where you can see the entries)</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Servic...
<python><selenium-webdriver>
2025-10-16 11:29:28
2
1,515
Rapid1898
79,791,803
3,617,866
How do I disable autocommit and make a batch of put operations atomic?
<p>I’m using GridDB Cloud (Free) with the Python client, and I need to write a batch of rows to a TimeSeries container atomically (all-or-nothing). I'm having trouble figuring out how to turn autocommit off and commit/rollback explicitly.</p> <p><strong>Minimal repro:</strong></p> <pre><code>import griddb_python as gri...
<python><transactions><time-series><griddb>
2025-10-16 05:41:00
0
907
Badhon Ashfaq
79,791,649
17,472,988
Linker error when trying to install FFCV on Python/Windows
<p>I am trying to <code>pip install</code> <a href="https://github.com/libffcv/ffcv" rel="nofollow noreferrer">FFCV</a> on Python 3.11 / Windows 10 following instructions in their README's Windows section. I initially had MSBuild detection <a href="https://stackoverflow.com/q/79789580">issues</a>, which I resolved and ...
<python><windows><pip><setuptools>
2025-10-15 22:12:50
1
1,859
PChemGuy
79,791,314
2,955,583
Inheritance of decorated classes
<p>I'm using Python decorators to implement common functionality across multiple classes. The problem comes when I want the decorated classes to inherit from each other: <code>super()</code> doesn't seem to delegate to the base class. The following is an MRE:</p> <pre class="lang-py prettyprint-override"><code>def deco...
<python><inheritance><decorator><python-decorators>
2025-10-15 15:00:08
3
452
jezza
79,791,237
17,441,006
Weaviate Langchain gets stuck on document upload
<p>Trying to upload documents to a local Weaviate client. However, it gets stuck on <code>add_document</code>.</p> <p>Here's my simple stripped down function.</p> <pre><code>from langchain_weaviate import WeaviateVectorStore from langchain.schema import Document from langchain_openai import OpenAIEmbeddings def upload...
<python><langchain><weaviate>
2025-10-15 13:52:24
1
543
Coder
79,791,112
1,230,477
How to make Playwright to connect to existing/opened Camoufox browser at certain port
<p><strong><a href="https://deepwiki.com/daijro/camoufox" rel="nofollow noreferrer">Camoufox</a></strong></p> <p>Given: the code <strong>opens Camoufox server and launches a browser at a certain port</strong>:</p> <pre><code>def automate_browser(server_url, browser_name): try: print(f&quot;Connecting to {br...
<python><browser><server><playwright><camoufox>
2025-10-15 11:26:51
0
6,351
Igor Savinkin
79,791,079
1,725,553
twine error with recent setuptools build but previous ones fine "InvalidDistribution: Metadata is missing required fields: Name, Version"
<p>I'm trying to upload the python module I maintain to pypi (as I have done every few months for the last twelve years) but when I run twine check I get:</p> <pre class="lang-bash prettyprint-override"><code>$ twine check dist/pi3d-2.55* Checking dist/pi3d-2.55-py3-none-any.whl: ERROR InvalidDistribution: Metadata ...
<python><setuptools><pypi>
2025-10-15 10:52:20
1
2,277
paddyg
79,791,017
17,902,018
Cannot get token logprobs while using langchain structured output
<p>I am using langchain to call an LLM and I want to get the logprobs for each token. I want to get them after doing this:</p> <pre><code>from langchain_openai import ChatOpenAI from pydantic import BaseModel class ResponseFormat(BaseModel): question_index: int answer: str short_answer: str llm = ChatOpen...
<python><openai-api><langchain><large-language-model><litellm>
2025-10-15 09:53:09
1
2,128
rikyeah
79,790,995
14,566,295
Failing to fill empty date values with numpy nan
<p>I have below code</p> <pre><code>import pandas as pd import numpy as np dat = pd.DataFrame({'A' : [1,2,3,4,5], 'B' : ['2002-01-01', '2003-01-01', '2004-01-01', '2004-01-01', '2005-01-01']}) dat['B'] = pd.to_datetime(dat['B']) dat['A'] = np.where( dat['A'].isin([1,2]), (dat['...
<python><pandas>
2025-10-15 09:28:03
2
1,679
Brian Smith
79,790,744
3,735,871
Unable to use Airflow variable with function in Jinja template
<p>I'm trying to pass Airflow <code>logical_date</code> to dbt model so that I can use it in the model (sql). I'm using Airflow 2.11.0. I'm doing below, but the dag couldn't get constructed, with an error says:</p> <blockquote> <p>'logical_date' is undefined.</p> </blockquote> <p>However it works if I remove the <code...
<python><templates><airflow><jinja2><dbt>
2025-10-15 02:14:32
1
367
user3735871
79,790,732
395,857
How to fix “Expected all tensors to be on the same device” when running inference with Qwen3-VL-4B-Instruct?
<p>I am trying to run the <a href="https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct" rel="nofollow noreferrer">code example</a> for run some inference on the model <a href="https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct" rel="nofollow noreferrer">Qwen/Qwen3-VL-4B-Instruct</a> model:</p> <pre><code>from transformers i...
<python><huggingface-transformers>
2025-10-15 01:28:45
2
84,585
Franck Dernoncourt
79,790,594
1,318,266
How to resolve python's "Import `ofxparse` could not be resolved"
<p>I'm trying to build a small script in Python 3.14 but am hung up at &quot;Import <code>ofxparse</code> could not be resolved&quot;. The script is built in Visual Studio Code on Windows 11.</p> <p>So far:</p> <ul> <li><code>pip install ofxparse</code> is successful</li> <li>First line of script is <code>from ofxparse...
<python><windows><powershell>
2025-10-14 20:18:06
1
4,728
geoB
79,790,533
10,006,534
How to write a pandas-compatible, non-elementary expression in narwhals
<p>I'm working with the <a href="https://narwhals-dev.github.io/narwhals/" rel="nofollow noreferrer">narwhals</a> package and I'm trying to write an expression that is:</p> <ol> <li>applied over groups using .over()</li> <li>Non-elementary/chained (longer than a single operation)</li> <li>Works when the native df is pa...
<python><pandas><dataframe><python-polars><python-narwhals>
2025-10-14 19:07:36
1
581
Slash
79,790,517
13,132,728
Create an incremental suffix for values in a pandas column that have duplicate values in another column
<h1>Setup</h1> <p>I have a dataframe, <code>df</code></p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame( { 'Name':['foo','foo','foo','bar','bar','bar','baz','baz','baz'], 'Color':['red','blue','red','green','green','blue','yellow','orange','red'] } ) </co...
<python><pandas><dataframe>
2025-10-14 18:49:22
4
1,645
bismo
79,790,512
5,044,950
Is the exclude-newer setting in uv sufficient for determinism and reproducibility without a lockfile?
<p>The Python package management tool uv has an <a href="https://docs.astral.sh/uv/reference/settings/#exclude-newer" rel="nofollow noreferrer"><code>exclude-newer</code></a> setting, documented as follows:</p> <blockquote> <p>Limit candidate packages to those that were uploaded prior to a given point in time.</p> <p>A...
<python><pypi><uv>
2025-10-14 18:37:09
0
13,402
Sam Estep
79,790,457
9,801,811
Mixture Model of genextreme in Scipy
<p>I'm trying to develop a mixture of <code>genextreme</code> distributions in Scipy using the following code.</p> <pre><code>from scipy.stats import genextreme from scipy.stats import Mixture eva_1 = {'c': -0.48, 'loc': 38.82, 'scale': 17.18} eva_2 = {'c': -0.57, 'loc': 26.44, 'scale': 4.69} gev_1 = genextreme(**eva...
<python><scipy><mixture-model>
2025-10-14 17:30:10
1
447
PPR
79,790,431
8,522,013
How do I print to application output window when debugging python in Qt Creator IDE?
<p>I'm debugging a python project (<code>pyproject</code>) in Qt Creator using built-in debugger.</p> <p>Python <code>print()</code> outputs only to <code>Debugger Log</code> window, where it's mixed with a lot of actual debugger output making it very hard to find the output.</p> <p>Is that behavior expected or there's...
<python><qt-creator><pdb><qtpy>
2025-10-14 16:56:42
0
928
Jack White
79,790,417
8,245,400
transformation logic for real-time inference service
<p>I have developed an XGBoost model, the data transformations where done using Pandas for training the model. For real-time inference the data comes from the HTTP request single object/record that should be transformed using the same logic that was used on Pandas dataframe for training and then model is invoked to sco...
<python><pandas><numpy><machine-learning>
2025-10-14 16:42:14
0
417
Raj
79,790,365
4,503,546
Index in to two specific dates on Pandas dataframe
<p>I have a pandas dataframe where the index is datetime. I learned that I can index in to a specific date using this code:</p> <pre><code>selected_date_df = df.loc['yyyy-mm-dd'] </code></pre> <p>I can also find data between two dates with this code:</p> <pre><code>date_range_df = df.loc['yyyy-mm-dd':'yyyy-mm-dd'] </co...
<python><pandas>
2025-10-14 15:47:14
1
407
GC123
79,790,303
5,552,507
pip install private package from Gitlab private pypi, in conda install environment, inside docker
<p>My internal packages are stored in a Gitlab private pypi simple.</p> <p>I use conda env with <code>environment.yml</code> definition, in which some are install with pip:</p> <pre class="lang-yaml prettyprint-override"><code># environment.yml name: test_project channels: - conda-forge - defaults dependencies: -...
<python><docker><pip><conda>
2025-10-14 14:41:56
0
307
PiWi
79,790,296
11,530,571
Dependency Hell in Google Colab
<p>I was trying to train a NN in Google Colab with Pytorch and then convert it to TFlite. It seems that everything works only with Python 3.11. I was able to find a &quot;switch&quot; that returns Colab to Python 3.11, so it seemed good... until I tried to install anything. I cannot install anything without triggering ...
<python><machine-learning><google-colaboratory>
2025-10-14 14:37:16
0
456
guest
79,790,263
12,945,785
How to read a Microsoft SQL Data with Polars
<p>I would like to read a database with Polars and benefit from his speed vs Pandas. Now I use this function to read db with pandas. So my question is simple how to convert it with polars and get something rapid (my database has millions of rows).</p> <pre><code>def lecture_bdd(DATABASE, table=None, colonnes=None, cond...
<python><sql-server><dataframe><python-polars>
2025-10-14 14:12:02
1
315
Jacques Tebeka
79,790,153
162,684
How to change names of pandas MultiIndex using Styler
<p>Let's assume we have the following:</p> <pre class="lang-py prettyprint-override"><code>midx = pd.MultiIndex.from_product( [[0, 1], [0, 1], [0, 1]], names=['L1', 'L2', 'L3']) df = pd.DataFrame({&quot;col&quot;: list(range(8))}, index=midx) </code></pre> <p>Now, for visualization purposes, I want the names of...
<python><pandas>
2025-10-14 12:17:13
2
13,583
MarcoS
79,789,768
14,566,295
Increase the date by number of months in pandas
<p>I have below <code>pandas</code> data frame</p> <pre><code>import pandas as pd import numpy as np dat = pd.DataFrame({'A' : [1,2,3,4,5], 'B' : ['2002-01-01', '2003-01-01', '2004-01-01', '2004-01-01', '2005-01-01']}) dat['A'] = dat['A'].astype('Int64') </code></pre> <p>Now I want to create another date column from co...
<python><pandas><dataframe>
2025-10-14 02:44:22
1
1,679
Brian Smith
79,789,608
2,751,573
How to exclude empty array with to_json
<p>Is there any way to exclude null arrays/structs when using to_json? I'm getting something like this coming back: <code>{&quot;arrayColumn&quot;:[{}]}</code></p> <p>Here's a really crude example:</p> <pre><code> from pyspark.sql.functions import to_json, struct,array,lit somedata = &quot;&quot;&quot; co...
<python><dataframe><pyspark>
2025-10-13 20:09:19
1
8,893
Andrew
79,789,580
17,472,988
Python 'pip install' fails to detect activated MSVC Build Tools
<p>When trying to install a package with pip on Windows 10 (Python=3.11.13, pip=25.2, setuptools=80.9.0) via</p> <pre class="lang-none prettyprint-override"><code>pip install --no-binary :all: pycryptodome </code></pre> <p>I get apparently infamous error with not particularly insightful message:</p> <pre><code> Te...
<python><windows><visual-c++><pip><setuptools>
2025-10-13 19:26:23
1
1,859
PChemGuy
79,789,573
5,972,531
List value options for widget configure keys
<p>How can I get the <em>value</em> options for config attributes? Especially those that take set values, i.e. anchor, relief, etc.</p> <p>Call the <code>configure</code> method on some widget, say a label:</p> <pre><code>label = tk.Label(root, text=&quot;Hello World!&quot;) label.configure() </code></pre> <p>We get th...
<python><tkinter>
2025-10-13 19:06:57
1
970
Mote Zart
79,789,445
11,485,896
Jupyter/VSCode does not recognize pip from .venv despite being properly installed
<p>EDIT: the issue is resolved (kinda). Check GitHub <a href="https://github.com/ipython/ipykernel/issues/1441" rel="nofollow noreferrer">discussion</a>. It turns out that there are possibly two problematic factors. First (my case), the newest version of Jupyter extension. When I switched back to 2025.8.0 I could final...
<python><visual-studio-code><jupyter-notebook><pip><python-venv>
2025-10-13 15:55:31
0
382
Soren V. Raben
79,789,430
131,433
Defining a pydantic dynamic model field in terms of another pydantic dynamic model
<p>If I create a dynamic model:</p> <pre><code>BarModel = create_model( 'BarModel', apple=(str, 'russet'), banana=(str, 'yellow') </code></pre> <p>And then I want to create another dynamic model with a field of type 'BarModel', do I just use 'BarModel' as the field type? What is the namespace of these thing...
<python><pydantic><pydantic-v2>
2025-10-13 15:35:51
0
100,613
bmargulies
79,789,334
18,108,367
How to test the calling sequence of methods of a class?
<p>Sometimes when I develop by TDD (Test Driven Development) I need to test the calling order of some class methods. In general I write Python code so I'll show the last test case that I have just written.</p> <h3>Production code</h3> <p>I have a class with 3 methods (in the file <code>mount_manager.py</code>):</p> <pr...
<python><tdd><python-unittest><python-mock>
2025-10-13 13:49:38
1
2,658
User051209
79,789,322
589,165
Does RDFLib offer static/semantic validation for SPARQL (beyond parseQuery)?
<p><code>parseQuery</code> in RDFLib catches syntax errors, but I can not find a way to make RDFLib flag <em>semantic/static</em> issues (e.g., GROUP BY mismatches) before execution on a remote endpoint. <code>translateQuery</code> was suggested as a stricter check, but it does not seem to raise in cases I would expect...
<python><sparql><rdflib>
2025-10-13 13:32:55
1
6,884
Finn Årup Nielsen
79,789,192
3,584,765
Cannot calculate confusion matrix utilizing supervision from roboflow for Yolov8 model
<p>I am trying to calculate the confusion matrix for my yolov8 (or yolov11) model utilizing <a href="https://github.com/roboflow/supervision" rel="nofollow noreferrer">supervision</a> from roboflow. I found some instructions but they do not seem to be crystal clear. For example <a href="https://roboflow.com/how-to-crea...
<python><machine-learning><object-detection><confusion-matrix><yolov8>
2025-10-13 10:50:21
1
5,743
Eypros
79,789,132
801,924
How to deploy a file to the system from a wheel?
<p>For given project:</p> <pre class="lang-none prettyprint-override"><code>. ├── demo │ └── __init__.py ├── demo.bin └── setup.py </code></pre> <p><code>demo/__init__.py</code>:</p> <pre class="lang-py prettyprint-override"><code>if __name__ == &quot;__main__&quot;: print(&quot;You're in demo&quot;) </code></pre...
<python><python-wheel>
2025-10-13 09:46:41
1
7,711
bux
79,789,087
2,695,990
How to add Unicode emoji to python script in IntelliJ
<p>I have a script which I have created couple of months ago with an older version of Intellij + Python plugin. I had to migrate to new windows and also new IntelliJ Currently I am using :</p> <ul> <li>IntelliJ IDEA 2025.2.1 (Ultimate Edition)</li> <li>Windows 11</li> <li>Python plugin of version: 252.25557.131</li> </...
<python><intellij-idea><console><emoji>
2025-10-13 08:59:24
2
3,174
fascynacja
79,788,981
13,579,159
SQLAlchemy session initialization in Command pattern
<p>A question on consideration for <em>case/approach</em> choice.</p> <p>Let's say we have an app that has an ORM model and also uses simple realisation of the Command pattern. Inside of each command we need to instantiate and manipulate our models and send varying queries to the database, hence we need a session. I su...
<python><session><design-patterns><sqlalchemy><command-pattern>
2025-10-13 06:34:29
1
341
Gennadiy
79,788,694
3,732,793
Simpy not showing other process name
<p>I am trying to work my self into simpy. Which uses python generators to create sim steps.</p> <p>From the documentation for simpy state access.</p> <pre><code>import simpy def subfunc(env): print(env.active_process.name) # will print &quot;my_proc&quot; def my_proc(env): while True: print(env.act...
<python><simpy>
2025-10-12 17:46:29
2
1,990
user3732793
79,788,676
2,894,535
How do I change argparse positional argument destination name?
<p>I am having trouble using <code>add_argument</code>'s <code>dest</code> parameter with positional arguments. The reason I want this is that I use <code>nargs='*'</code> and it makes sense to me to have the argument name be singular so that its help is printed as <code>[target ...]</code>, but the destination to be p...
<python><argparse>
2025-10-12 16:59:43
1
3,116
Dominik Kaszewski
79,788,575
7,240,233
More than basic form validation with Django
<p>I'm learning Django with a small app allowing people to book houses for lodging. I have two models, describing a house and a booking (I'm currently working without a &quot;Customer&quot; model):</p> <pre class="lang-py prettyprint-override"><code># models.py from django.db import models class Housing(models.Model)...
<python><django><forms><validation>
2025-10-12 13:19:59
0
721
Micawber
79,788,427
7,556,091
Why OpenCV does not utilize multithreading for acceleration?
<p>My system and OpenCV version information, source code, and runtime results are as follows: From this, it appears that multithreading is not functioning.</p> <pre class="lang-bash prettyprint-override"><code>~$ mamba list | grep opencv libopencv 4.12.0 qt6_py312h322f462_605 ...
<python><multithreading><opencv>
2025-10-12 07:31:14
1
1,896
progquester
79,788,321
2,604,247
Angle Embedder in Python Messing Up Logging Config
<p>I wrote another question on this earlier, but could not pinpoint the issue on my side, here, I am giving a minimal reproducible code.</p> <h5>System</h5> <p>Angle version 0.5.6</p> <p>UV 0.8.22</p> <p>Python 3.12</p> <p>Ubuntu 24.04</p> <p>I have used the python <code>logging</code> library for sometime, and recentl...
<python><nlp><python-logging><text-embedding-ada-002>
2025-10-12 01:03:16
1
1,720
Della
79,788,256
2,252,948
Invoking Enter-VsDevShell with pytest prints both sucessful AND failed output...?
<p>I've created a python script <code>foo.py</code> which contains a simple pytest test that invokes a powershell script, <code>tmp.ps1</code>. <code>tmp.ps1</code> obtains the Visual Studio installation path, then sources a powershell script within Visual Studio, <code>Launch-VsDevShell.ps1</code>, to setup the enviro...
<python><powershell><visual-studio><pytest>
2025-10-11 22:11:38
0
1,412
adentinger
79,788,168
552,683
How to efficiently denormalize a SQL DB to produce Parquet files
<p>I'm trying to create a parquet file from a heavily normalized SQL database with a snowflake schema. Some of the dimensions have very long text attributes so that a simply running a big set of joins to denormalize the data that's fed to PyArrow takes a while even with a smallish dataset (10s of thousands of facts), a...
<python><pandas><parquet><pyarrow>
2025-10-11 18:19:44
0
1,140
Davor Cubranic
79,788,108
4,518,341
How do I calculate a relative time delta in Pandas?
<p>I have a column of datetimes and I want to get the difference between values in terms of years, months, etc, instead of timedeltas that only provide days. How do I do this in Pandas?</p> <p>Pandas provides <a href="https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.DateOffset.html" rel="nofollow nor...
<python><pandas><datetime>
2025-10-11 15:59:56
2
33,775
wjandrea
79,787,931
8,522,463
Removing gridlines from scanned forms
<p>I am trying to remove gridlines from a form snippet as a preprocess step for OCR.</p> <p>However, this turned out quite challenging when texts overlap with the gridlines.</p> <p>Sample Images<br /> <img src="https://i.sstatic.net/nSV9S1hP.png" alt="Sample images" /></p> <p>I am very new to open cv and this is What I...
<python><opencv><image-processing><ocr><scikit-image>
2025-10-11 09:20:19
0
2,158
Julkar9
79,787,848
1,581,090
How to make sure I set the correct Python interpreter in PyCharm as in the terminal?
<p>I open a PyCharm project (Windows 11) and inside PyCharm I run the terminal to install some requirements:</p> <pre><code>pip install -r requirements.txt </code></pre> <p>However, when opening a Python file from the same project in the same folder all the modules that should be imported are marked in &quot;red&quot;,...
<python><windows><pycharm>
2025-10-11 06:25:38
1
45,023
Alex
79,787,709
5,269,892
Excel incorrectly processes formulas cross-referencing each other
<p>I have generated an Excel file, with the following columns (cf. minimal code below):</p> <ul> <li><strong>ID (col. A):</strong> set via hardcoded values (i.e. not via Excel formula)</li> <li><strong>Manually-set resolved (col. B):</strong> a column that should either be left blank or set <code>TRUE</code> by the use...
<python><excel><excel-formula><openpyxl><maxifs>
2025-10-10 21:58:37
2
1,314
silence_of_the_lambdas
79,787,610
179,583
Find first matching array index in Python, but using lambda helper function
<p>I have a data structure like</p> <pre class="lang-py prettyprint-override"><code>arr = [ (2014, 0.21, 0.27), (2015, 0.23, 0.27), (2016, 0.25, None), (2017, 0.25, None), (2018, 0.27, None), ] </code></pre> <p>where I want to find the index of the first tuple that does not have data in its third sl...
<python><list>
2025-10-10 18:14:04
0
18,149
natevw
79,787,552
6,101,024
Relative Import With Parent Package
<p>src</p> <ul> <li><p>testing</p> <ul> <li>test.py</li> </ul> </li> <li><p>utils_dataset</p> <ul> <li>px_chol.py</li> <li>another_file.py</li> </ul> </li> <li><p>test.py ---&gt; is calling a class declared in px_chol.py. therefore, it has <code>from utils_dataset.px_chol import CLASS_NAME</code> declaration</p> </li>...
<python><package>
2025-10-10 16:49:49
3
697
Carlo Allocca
79,787,529
8,800,836
Subtlety in initializing attributes with methods in modules from the `equinox` `jax` library
<p>I have the following code that defines an abstract class and its final subclasse. The two classes are both subclasses of the <a href="https://docs.kidger.site/equinox/api/module/module/" rel="nofollow noreferrer"><code>equinox.Module</code></a> class, which registers class attributes as the leaves of a PyTree contai...
<python><class><constructor><jax>
2025-10-10 16:18:47
2
539
Ben
79,787,507
1,060,339
Changing the owner of .venv created by uv inside Docker
<p>I have a Django app build by uv running inside Docker. I mount the local filesystem as a volume in the container using Docker Compose so that edits to the source code locally trigger reloading of the app in the container. It <em>almost</em> works.</p> <p>The issue is that the <code>.venv</code> directory built by ...
<python><django><docker><docker-compose><uv>
2025-10-10 15:47:42
1
4,586
trubliphone
79,787,097
17,580,381
Type hints for concurrent.futures.Executor subclasses
<p>I have the following code developed in VSCode that runs without error:</p> <pre><code>import random import time from concurrent.futures import ( InterpreterPoolExecutor, ProcessPoolExecutor, ThreadPoolExecutor, Executor, ) from os import process_cpu_count def cpus() -&gt; int: &quot;&quot;&quot;...
<python><pylance>
2025-10-10 07:38:28
1
28,997
Ramrab
79,787,051
2,123,706
python plotly scatter ols trendline has a kink in it
<p>I am using plotly express to model some data, and wanted to add a <code>trendline = 'ols'</code> to it.</p> <p>when I do, I obtain a kink in the result</p> <p><a href="https://i.sstatic.net/v8YNlpMo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v8YNlpMo.png" alt="enter image description here" /></a>...
<python><pandas><plotly><trendline>
2025-10-10 06:30:11
1
3,810
frank
79,786,917
8,800,836
Why must classes be defined in order of appearance in python module?
<p>Let's say I have a python file <code>test.py</code> that looks like this:</p> <pre class="lang-py prettyprint-override"><code>class MyFirstClass(): prop=3 class MySecondClass(): prop1 = 0. prop2 = MyFirstClass() </code></pre> <p>Then I can run this and it works:</p> <pre class="lang-py prettyprint-overr...
<python><class><attributes>
2025-10-10 00:04:29
4
539
Ben
79,786,710
6,829,655
Memory leak in aioboto3 (aiohttp) after upgrading to Python 3.13
<p>I’m seeing a steady memory increase in my ECS containers after upgrading Python and dependency versions. The memory growth stops when I stop incoming gRPC requests, but it never drops back down afterward — suggesting some retained references or unclosed aiohttp sessions.</p> <p><strong>Setup</strong></p> <p>I have a...
<python><boto3><aiohttp><python-3.13><aiobotocore>
2025-10-09 17:48:51
0
651
datahack
79,786,435
1,309,443
attrs subclass from non-attrs class not respecting initializer arguments
<p>I get the following error:</p> <pre><code>$ python attrs_subclass_test.py Traceback (most recent call last): File &quot;attrs_subclass_test.py&quot;, line 23, in &lt;module&gt; attrs_sub = AttrsSub(name='attrs_sub') TypeError: __init__() got an unexpected keyword argument 'name' </code></pre> <p>when running ...
<python><python-attrs>
2025-10-09 12:50:05
1
771
BrendanSimon
79,786,399
6,288,756
Does this code indicate a mistake in Wikipedia's example on the "QR Code" page?
<p>I am doing some work with QR codes, and to test my code, I was comparing it against the example QR code at the top of <a href="https://en.wikipedia.org/wiki/QR_code" rel="nofollow noreferrer">the Wikipedia page</a> for QR codes:</p> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/QR_code_for_mobi...
<python><qr-code>
2025-10-09 12:24:57
1
323
TJM
79,786,387
13,392,257
How to add aiokafka producer to FastAPI properly?
<p>I am creating FastAPI and aiokafka endpoint. How to add aiokafka producer properly?</p> <pre><code>from aiokafka import AIOKafkaProducer. The function is woking, but too long. Found out that the problem deals with `producer` function argument (function works fast without producer). @my_router.post(&quot;/{data_ty...
<python><fastapi><aiokafka>
2025-10-09 12:12:05
1
1,708
mascai
79,786,362
10,982,755
UV Docker Cache behaviour issues
<p>I have checked out <a href="https://docs.astral.sh/uv/guides/integration/docker/#caching" rel="nofollow noreferrer">Docker Caching</a> and the <a href="https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile" rel="nofollow noreferrer">uv docker example</a>. Both of them fail to clarify on the behaviour o...
<python><docker><jenkins><uv>
2025-10-09 11:48:34
0
617
Vaibhav
79,786,206
988,279
confluent-kafka receive messages from last x days
<p>I've a topic in kafka (only 1 partition) and want do receive the messages within the last <em>x</em> days. How does this work?</p> <p>Working consumer code for fetching all messages:</p> <pre><code>from confluent_kafka import Consumer import json config = { 'bootstrap.servers': '0.0.0.0:9092', 'group.id': '...
<python><apache-kafka>
2025-10-09 09:03:02
0
522
saromba
79,786,115
9,338,724
How to ignore certain exceptions in VSCode Debugger, when "Uncaught Exceptions" breakpoint turned on
<p>While working with Pyhthon debugger on VSCode, I would like to ignore &quot;HTTPException&quot; from triggering a breakpoint in debug mode, while &quot;Uncaught Exceptions&quot; is turned on.</p>
<python><visual-studio-code>
2025-10-09 07:07:06
0
427
abyesilyurt
79,785,999
3,294,994
Type hint a decorator to enforce matching signature as the decorated function
<p>How can I implement <code>DecoratorFactory</code> such that it type-checks as follows:</p> <pre class="lang-py prettyprint-override"><code>def accepts_foo(foo: int): ... def accepts_bar(bar: int): ... decorator_foo = DecoratorFactory(foo=1) decorator_foo(accepts_foo) # okay because they both accept foo decorator_...
<python><python-typing><pyright>
2025-10-09 02:56:54
1
846
obk
79,785,937
1,447,953
Why doesn't Pandas concat do a copy when one of the dataframes is empty?
<p>Consider this example:</p> <pre><code>import pandas as pd df_part1 = pd.DataFrame() df_part2 = pd.DataFrame({'A': [1,1], 'B': [3,4]}) df_concat_out = pd.concat([df_part1, df_part2]) print(&quot;id(df_part2.values) == id(df_concat_out.values):&quot;, id(df_part2.values) == id(df_concat_out.values)) df_part2.B *= -1 ...
<python><pandas><dataframe>
2025-10-08 23:57:00
2
2,974
Ben Farmer
79,785,799
9,890,009
How to search by multiple fields on django_opensearch_dsl
<p>I have an opensearch server in which I want to search items and apply some filters to the search:</p> <pre><code>search = Item.search().query(&quot;match&quot;, name=&quot;test&quot;) </code></pre> <p>I need to search items by multiple filters, like name, date, location, etc. For this I will need some other kind of ...
<python><django><opensearch>
2025-10-08 19:19:34
1
792
Paul Miranda
79,785,678
1,574,952
Shape of sliced array from shape of array and slice
<p>If I know the shape of a numpy array like <code>(1000, 50)</code>, and I have an arbitrary selection expressed as an <code>IndexExpression</code>, let's say <code>np.s_[:200, :]</code>, how can I evaluate the shape of the sliced array (in this example <code>(200, 50)</code>), without actually constructing the array,...
<python><numpy><numpy-slicing>
2025-10-08 16:19:51
1
364
Kyle
79,785,634
14,649,310
How to get headers from a request in Streamlit
<p>Hello we have a Streamlit app deployed in Azure and we want to do the azure authentication. Part of it is that we receive the users info after authorization in these headers:</p> <pre><code>X-MS-CLIENT-PRINCIPAL-NAME: User's name/email X-MS-CLIENT-PRINCIPAL-ID: User's unique ID </code></pre> <p>as described <a href=...
<python><azure><streamlit><azure-authentication>
2025-10-08 15:38:33
1
4,999
KZiovas
79,785,601
577,288
Cannot start a ThreadPoolExecutor inside a threading.Thread function
<p>In this example, Tkinter GUI starts <code>ThreadPoolExecutor</code>. But <code>ThreadPoolExecutor</code> is inside a <code>threading.Thread</code> function. The thread function says it's finished before <code>ThreadPoolExecutor</code> has started ... and returns this error.</p> <pre><code>RuntimeError: can't registe...
<python><multithreading><threadpool><python-multithreading>
2025-10-08 15:11:51
1
5,408
Rhys
79,785,579
4,047,679
How to identify system/external dependencies of installed python packages
<p>We're trying to offload checking if our python environment can install on our server to a GitHub action. What I would like to know is if there's a way of knowing which python packages in the environment require external/system dependencies (for example, gdal) so we could specify them in the image to use for the acti...
<python><pip><github-actions><dependency-management>
2025-10-08 14:51:02
1
2,869
raphael
79,785,530
8,297,745
Closing file after SFTP upload still makes client retry the same upload in `close` sftp_response from paramiko
<p>I run a custom SFTP Server using Paramiko that receives video files from NVR cameras and uploads it to a cloud storage. The flow is simple: The client (NVR) connects and authenticates, we write the incoming file locally, then push it to Google Cloud Storage, and remove the local copy. After that the connection shoul...
<python><ssh><sftp><paramiko>
2025-10-08 13:52:32
1
849
Raul Chiarella
79,785,458
10,975,692
Why does multiprocess with "fork" fail under Python 3.14 but work in 3.13 (works only with "spawn" and "forkserver")?
<p>The following code works fine on <strong>Python 3.13</strong>, but fails on <strong>Python 3.14</strong> with a <code>RuntimeError</code> related to asyncio tasks.</p> <p>If I switch the multiprocessing start method from <code>&quot;fork&quot;</code> to <code>&quot;spawn&quot;</code>, the code works again — but <cod...
<python><python-3.x><python-asyncio><multiprocess><python-3.14>
2025-10-08 12:36:47
2
1,500
DarkMath
79,785,397
13,806,869
Why does Pandas not recognise my sqlalchemy connection engine?
<p>I'm trying to connect to an IBM DB2 database from Python. I'm using Python 3.12.10, SQLAlchemy 1.4.54, and Pandas 2.3.2. This is what my code looks like:</p> <pre><code>import os import sqlalchemy import pandas as pd from keyring import get_credential if os.name == &quot;nt&quot;: os.add_dll_directory(os.path.j...
<python><pandas><sqlalchemy><db2>
2025-10-08 11:19:04
1
521
SRJCoding
79,785,354
2,276,054
Injecting build date automatically when building WHL with setuptools?
<p>I have a simple Python project that is often updated, so I need to track its version number and display it in the runtime. I store version and build date in <code>__init__.py</code> in project's root:</p> <pre class="lang-py prettyprint-override"><code>__version__ = &quot;1.0.6&quot; __date__ = &quot;2025-10-08 18:3...
<python><python-3.x><setuptools><pyproject.toml>
2025-10-08 10:33:52
2
681
Leszek Pachura
79,785,313
2,891,692
Logging without year:month:day but with hours:minutes:seconds,milliseconds
<p>I try to get logging setup <code>hours:minutes:seconds,milliseconds</code></p> <p>Example: <code>11:28:51,284</code></p> <p>Actually I get <code>2025-10-08 11:44:07,658</code></p> <p>This is the source with which I try to do it:</p> <pre><code># --- Logging Setup --- # --- Logging Setup --- # Manual configuration fo...
<python><python-logging>
2025-10-08 09:57:43
1
2,630
SL5net