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,586,784
6,368,549
Sorting Dictionary By Date
<p>I have a dictionary which contains several years of data. The dictionary is basically this:</p> <pre><code>data = { '2024-09-20': 13.37, '2024-09-21': 14.92, '2024-09-22': 15.17, '2024-09-23': 12.15 } </code></pre> <p>It contains about 10 years of data or so. What I need to do is first limit the range to jus...
<python><sorting>
2025-04-22 15:03:42
2
853
Landon Statis
79,586,698
1,858,864
Migrate project with rpm dependencies from Centos 7 to AlmaLinux 9
<p>I have a legacy python/django project with a lot of x86_64 dependencies (~15), which are installed via rpm under Centos 7. Since Centos7 EOL happened in the previous year, I need to migrate this project to the AlmaLinux 9 (I cannot change OS, it is only AlmaLinux 8 or 9).</p> <p>Since it's a legacy project, I really...
<python><centos7><almalinux>
2025-04-22 14:23:18
0
6,817
Paul
79,586,568
6,000,623
Stop Otel from tracing its own internal metric exporting activity
<p>I've implemented Otel for my python app sending telemetry to GCP backend. I'm seeing these trace spans for <code>https://otel-collector-xxx.asia-southeast1.run.app/opentelemetry.proto.collector.metrics.v1.MetricsService/Export</code>. I suspect these are traces from the metric export activity.</p> <p>I don't want th...
<python><google-cloud-platform><google-app-engine><trace><open-telemetry>
2025-04-22 13:15:44
1
479
Deepanshu Kalra
79,586,540
10,232,932
Apache Spark left join python databricks
<p>I have three dataframes in databricks and try to run a join on them (apache spark functions). I mainly was used to pandas dataframe join. My current code is:</p> <pre><code>joined_df = df_1.join(df_2, df_1[&quot;RECONTRACT&quot;] == df_2[&quot;RECONTRACT&quot;], &quot;left&quot;) joined_df = joined_df.join(df_3, joi...
<python><apache-spark><databricks>
2025-04-22 13:00:50
3
6,338
PV8
79,586,299
511,436
"object has no attribute 'delay_on_commit'"
<p>Launching a Celery 5.5.1 task from a Django 4.2 view sometimes causes</p> <pre><code>'generate_report' object has no attribute 'delay_on_commit' </code></pre> <pre><code># tasks.py from celery import shared_task @shared_task def generate_report(data): # Code to generate report ... </code></pre> <pre><code>...
<python><django><celery><pythonanywhere>
2025-04-22 11:14:06
2
1,844
Davy
79,585,895
7,465,516
Can I get PyCharm to accept a Python interpreter not named 'python'?
<p>My project has an executable called <code>powerscript.exe</code>, which is a Python interpreter that does and knows some extra things. This is out of my control, I can not change this.</p> <p>From the command line I can use this as a drop-in replacement for the Python interpreter. In PyCharm I cannot. Adding this th...
<python><windows><pycharm>
2025-04-22 07:25:00
1
2,196
julaine
79,585,571
11,505,680
Python: using doctest with assert
<p>I've been using doctest for a while now, and I like it most of the time. It's annoying when I expect a number that has to fall within a certain range or a string that has to meet certain conditions. In this case, the recommended approach seems to be to encode the condition as a logical operator returning <code>True<...
<python><doctest>
2025-04-22 01:38:38
1
645
Ilya
79,585,532
464,318
How to make "Go to definition" in VS Code go to a Python library file in the workspace, rather than a file in the virtualenv?
<p>I have a project that includes multiple, unconnected git repos, which I check out next to each other in my <code>~/dev</code> folder.</p> <p>One repo, <code>~/dev/multitenant</code>, is the &quot;main&quot; project, and there are several libraries that Multitenant imports, including <code>~/dev/airspace</code>. Both...
<python><visual-studio-code><pylance>
2025-04-22 00:42:41
1
9,240
coredumperror
79,585,341
16,611,809
Delete row with negative data in Polars, if row with same value in one column and positive data exists
<p>Lets assume I have this Polars df:</p> <pre><code>import polars as pl df = pl.DataFrame({'name': ['a', 'a', 'b', 'b'], 'found': ['yes', 'no', 'no', 'no'], 'found_in_iteration': ['1', 'not_found', 'not_found', 'not_found']}) </code></pre> <p>(This df was generated in two iterati...
<python><dataframe><python-polars>
2025-04-21 21:04:15
2
627
gernophil
79,585,340
1,241,786
Update dataframe cell based on row criteria
<p>Let's say I have the following dataframe:</p> <pre><code>+----+------------------------------------------------+-------------+----------+----------+ | | String | Substring | Result 1 | Result 2 | +----+------------------------------------------------+-------------+-------...
<python><pandas><dataframe>
2025-04-21 21:00:38
1
728
kubiej21
79,585,301
1,709,413
Matplotlib vertical grid lines not match points
<p>Could you please explain why vertical grid lines not match points?</p> <p><a href="https://i.sstatic.net/BO1ONFIz.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BO1ONFIz.jpg" alt="enter image description here" /></a></p> <p>Here is my data for plot:</p> <p>{datetime.datetime(2025, 4, 15, 19, 23, 50, ...
<python><matplotlib>
2025-04-21 20:34:31
1
1,197
andrey
79,585,295
914,832
Python > yfinance > yf.Ticker(symbol) throwing error when symbol not known
<p>When using <strong>logging</strong> and <strong>yfinance</strong>, if one queries for a incorrect ticker name, they will get an error and I am struggling to shield the user from that error:</p> <p>Code which triggers the error:</p> <pre><code>ticker = yf.Ticker(&quot;QQQQQQQQQ&quot;) stock_info = ticker.info </code>...
<python><logging><yfinance>
2025-04-21 20:31:36
1
341
Bogdan Ciocoiu
79,585,116
19,527,503
Plus and equal increment operator not allowed inside dictionary
<p>In the dictionary below, <code>id_count</code> gets incremented as soon as the loop begins just before the dictionary is created. I need to increment it again inside the dictionary within locations <code>id</code>. Why is the <code>+=</code> operator not allowed inside the dictionary?</p> <pre><code> for i in range(...
<python><dictionary>
2025-04-21 18:27:19
2
323
marsprogrammer
79,585,042
577,288
python 3 - multithreading pyttsx3
<pre><code>import pyttsx3 import concurrent.futures import concurrent.futures def Threads1(curr_section, index1, engine): rec_audiofile = 'output' + str(index1) + '.mp3' voices = engine.getProperty('voices') engine.setProperty('rate', 160) engine.setProperty('voice', voices[1].id) engine.save_to...
<python><python-3.x><multithreading><pyttsx3>
2025-04-21 17:28:11
0
5,408
Rhys
79,584,914
790,474
Self-contained marimo notebook via uv
<p>I am trying to make a self-contained Python file that would use <code>uv</code> to install dependencies into the <code>uv</code> cache behind the scene, and simply launch the Marimo notebook once the script runs.</p> <p>This would make distribution much easier.</p> <p>I have worked out the following:</p> <pre class=...
<python><uv><marimo>
2025-04-21 15:50:57
1
3,120
henrikstroem
79,584,913
1,774,080
Firefox remote debugging for website in python - Select element inside an iframe
<p>I am trying to create an automation tool for scraping a site. As part of that, I am making a Python script that utilizes the Remote Debugging protocol through this library: <a href="https://github.com/jpramosi/geckordp" rel="nofollow noreferrer">https://github.com/jpramosi/geckordp</a></p> <p>My problem is, that the...
<python><firefox><remote-debugging><firefox-developer-tools><queryselector>
2025-04-21 15:50:05
0
1,967
Noob Doob
79,584,485
17,902,018
Unable to torch.load due to pickling/safety error
<p>I am trying to use a pytorch model present on this link:</p> <p><a href="https://drive.google.com/drive/folders/121kucsuGxoYQu03-Jmy6VCDcPzqlG4cG" rel="nofollow noreferrer">https://drive.google.com/drive/folders/121kucsuGxoYQu03-Jmy6VCDcPzqlG4cG</a></p> <p>since it is used by this project I am trying to run:</p> <p>...
<python><numpy><pytorch><deserialization><pickle>
2025-04-21 11:02:45
1
2,128
rikyeah
79,584,468
5,828,163
How to represent ranges of time in a pandas index
<p>I have a collection of user data as follows:</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th style="text-align: center;">user</th> <th style="text-align: center;">start</th> <th style="text-align: center;">end</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">John Doe</td> ...
<python><pandas><time-series><date-range>
2025-04-21 10:54:10
2
2,223
Adam Stewart
79,584,454
3,225,420
Can't Align Histogram Bin Edges with Chart Even When Using Numpy histogram_bin_edges
<p>I want the histogram edges to line up with the <code>xticks</code> of my chart. Other SO and answers I've read focus on calculating the bins and passing them. I've done this yet still can't get them to align: <a href="https://i.sstatic.net/z1I2C1o5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/z1I...
<python><matplotlib><histogram><xticks>
2025-04-21 10:46:59
1
1,689
Python_Learner
79,584,241
1,706,058
Overlay effect no working as expected in moviepy
<p>I'm trying to apply overlay effect (mp4 with black background) and the black color is not completely removed using the mask below</p> <pre class="lang-py prettyprint-override"><code>from moviepy.editor import VideoFileClip, CompositeVideoClip from moviepy.video.fx.all import mask_color # Load the base video and ove...
<python><moviepy>
2025-04-21 08:04:19
2
1,181
Devester
79,584,062
5,722,359
UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown
<p>I am trying to show a matplotlib.pyplot figure on Python 3.10 but can't. I am aware of this <a href="https://stackoverflow.com/q/77507580/5722359">question</a> and tried their answers but is still unsuccessful. The default OS distribution is Ubuntu 24.04 using Python 3.12 as a default.</p> <p>Here is how I setup the...
<python><matplotlib><uv>
2025-04-21 05:15:22
2
8,499
Sun Bear
79,584,016
1,187,304
How to pickle my custom enum class without a PicklingError?
<p>I have written an <code>Interval</code> python class with attributes for a starting point, an ending point, and a &quot;curve type&quot; that is used to interpolate between the start and the end. I only plan to support a couple specific predefined curve types, so I have put them in an Enum. Each curve type has a few...
<python><enums><pickle><namedtuple>
2025-04-21 04:07:36
1
482
thecommexokid
79,583,755
3,684,931
How to build a nested adjacency list from an adjacency list and a hierarchy?
<p>I have a simple adjacency list representation of a graph like this</p> <pre><code>{ 1: [2, 3, 4], 2: [5], 3: [6, 9], 4: [3], 5: [3], 6: [7, 8], 7: [], 8: [], 9: [] } </code></pre> <p>which looks like this</p> <p><a href="https://i.sstatic.net/51Ua0bFH.png" rel="nofollow noreferrer...
<python><data-structures><graph><nested><adjacency-list>
2025-04-20 20:59:57
2
1,984
Sachin Hosmani
79,583,668
7,361,580
Can older spaCy models be ported to future spaCy versions?
<p>The latest spaCy versions have better performance and compatibility for GPU acceleration on Apple devices, but I have an existing project that depends on spaCy 3.1.4 and some of the specific behavior of the 3.1.0 models (web lg, web trf).</p> <p>Would it be possible to port the old models from source to work with ne...
<python><nlp><gpu><spacy>
2025-04-20 19:10:02
0
2,115
synchronizer
79,583,640
21,446,483
Keras SKLearnClassifier wrapper can't fit MNIST data
<p>I'm trying to use the SKLearnClassifier Keras wrapper to do some grid searching and cross validation using the sklearn library but I'm unable to get the model to work properly.</p> <pre class="lang-py prettyprint-override"><code>def build_model(X, y, n_neurons: List[str], learning_rate: float): model = keras.mod...
<python><keras><scikit-learn><mnist>
2025-04-20 18:31:51
0
332
Jesus Diaz Rivero
79,583,536
161,012
How to display rule numbers in Ruff warnings using VS Code
<p>Would it be possible to configure Ruff to display the rule number violated in its warnings while using Ruff with VS Code?</p> <p>In my <code>ruff.toml</code>, I am enabling everything by default:</p> <pre class="lang-toml prettyprint-override"><code>[lint] select = [&quot;ALL&quot;] </code></pre> <p>Then, I plan to ...
<python><visual-studio-code><ruff>
2025-04-20 16:33:49
2
2,083
Pierre Thibault
79,583,354
8,020,900
How to make Plotly figure legend be right to left instead of left to right
<p>I have this plot with horizontal legend. I want the legend title to be on the right instead of the left, and I want the bullets of each legend item to be on the right of the name instead of on the left. How can I do this? Thank you!</p> <pre><code>import plotly.express as px long_df = px.data.medals_long() fig = px....
<python><python-3.x><graph><plotly><legend>
2025-04-20 12:25:24
0
3,539
Free Palestine
79,583,142
17,729,094
Broadcasting a [B, 1] tensor to apply a shift to a specific channel in PyTorch
<p>I have a tensor <code>p</code> of shape <code>(B, 3, N)</code> in PyTorch:</p> <pre class="lang-py prettyprint-override"><code># 2 batches, 3 channels (x, y, z), 5 points p = torch.rand(2, 3, 5, requires_grad=True) &quot;&quot;&quot; p: tensor([[[0.8365, 0.0505, 0.4208, 0.7465, 0.6843], [0.9922, 0.2684, 0.6...
<python><pytorch>
2025-04-20 07:44:45
1
954
DJDuque
79,583,131
10,242,281
XML (RDL) code broken after editing with Python (BS4), how to find error?
<p>I did editing RDL (same like XML?) files cleaning them not used Embedded elements. Didn't touch left images. Doing it in Python, sample code looks like below in pseudo view: Input has this header :</p> <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;Report xmlns=&quot;http://schemas.m...
<python><xml><visual-studio>
2025-04-20 07:31:33
2
504
Mich28
79,583,120
5,818,372
PyQtDarkTheme: Check‑mark missing for current item in QComboBox popup
<p>I'm using <em>PyQt6</em> with <em>PyQtDarkTheme</em> and have encountered a UI issue:<br /> When opening a <code>QComboBox</code> popup, the <strong>currently selected item doesn't show the usual ✔ checkmark</strong>, or it's so low-contrast that it's effectively invisible. This works correctly without <em>PyQtDarkT...
<python><pyqt6><qtstylesheets><qcombobox>
2025-04-20 07:13:25
0
686
Gykonik
79,583,067
5,887,173
How to use migration commands with Litestar?
<p>I am trying to use migration commands with Litestar, but I keep encountering the error: No such command 'database'.</p> <p>I have configured my project with pyproject.toml, main.py, and models.user.py as shown below. I also use advanced-alchemy for database integration and Alembic for migrations. However, I cannot f...
<python><webapi><dbmigrate><litestar>
2025-04-20 05:48:56
0
945
Alexander
79,582,933
10,461,632
How do you set the same row height for all rows in a table created with sphinx? (LaTeX)
<p>How can I modify the <code>latex_preamble</code> to force all rows in a table to have the same height? With Table 1 it's hard to spot, but if you look at Table 2, you can see the first and last row have extra space compared to the other rows.</p> <p>I tried these options, but neither of them remove the extra height....
<python><latex><python-sphinx>
2025-04-20 01:00:51
0
788
Simon1
79,582,815
256,828
Locally installed Python wheel throwing ModuleNotFoundError
<p>Recently I've been trying to learn a bit more about how to build python modules and share code amongst my personal projects. This is my first attempt and I'm running into errors and I'm having a tough time finding solutions through normal searches. I'm hoping you guys can point me in the right direction and maybe pr...
<python><python-3.x><setuptools><python-wheel>
2025-04-19 20:35:06
2
3,292
Staros
79,582,632
2,893,712
APScheduler Jitter Causes Multiple Runs
<p>I a have a job that I want to run once per day at 9am +- 15min. Here is my code:</p> <pre><code>def Function(): requests.get(&quot;https://EXAMPLE.com&quot;) logger.info(&quot;Ran function&quot;) sched.add_job(Function, 'cron', hour=9, jitter=900) sched.start() try: while True: time.sleep(2) exc...
<python><apscheduler><jitter>
2025-04-19 16:56:17
2
8,806
Bijan
79,582,396
1,306,747
Plotly date display using UNIX timestamp data in browser timezone
<p>My data comes as a Pandas DataFrame with a datetime index, that is generated from UNIX timestamps. I would like to display the data in a Plotly chart in the browser's timezone, but haven't figured out how.</p> <p>What I've tried so far:</p> <ul> <li>Use timestamps (Python <code>float</code>s): Displays timestamps as...
<python><plotly><timezone><unix-timestamp>
2025-04-19 12:37:08
1
989
Philipp Burch
79,582,013
395,857
Can't run a Python file in PyCharm: why?
<p>I can't run a Python file in PyCharm: why?</p> <p>The run icon is greyed out:</p> <p><img src="https://i.sstatic.net/CboOla1r.png" alt="The run button is greyed out." /></p> <p>I went to Run → Edit Configurations… to make sure the correct Python interpreter is selected. Debug, coverage, and profile are fine but I do...
<python><pycharm>
2025-04-19 04:14:30
1
84,585
Franck Dernoncourt
79,582,003
1,065,197
How can I check having functions with specific return type but without return value with ruff?
<p>Ruff has a nice rule <a href="https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function/" rel="nofollow noreferrer">ANN201</a> that checks the return type of a function. Example:</p> <pre><code>def add(a, b): # wrong! return a + b def add(a: int, b: int) -&gt; int: # right return a ...
<python><ruff>
2025-04-19 03:55:19
1
85,878
Luiggi Mendoza
79,581,784
10,242,281
Python editing file in loop, how to keep changes after each (xml)
<p>I need to clean few xml files from not needed elements, came up with this wild card replacement for nothing to get rid of not needed <code>&lt;EmbeddedImage&gt;</code>, but I'm missing how to store each change in the loop, looks like it overwrites it each time. Thought that Python will keep it, but it's not the case...
<python><xml>
2025-04-18 21:54:39
4
504
Mich28
79,581,767
14,278,409
Problems creating a generator factory in python
<p>I'd like to create a generator factory, i.e. a generator that yields generators, in python using a &quot;generator expression&quot; (generator equivalent of list comprehension). Here's an example:</p> <pre><code>import itertools as it gen_factory=((pow(b,a) for a in it.count(1)) for b in it.count(10,10)) </code></pr...
<python><generator>
2025-04-18 21:37:40
2
730
njp
79,581,727
11,515,528
Smartsheets API get_cell_history value only returned for first instance
<p>I am finding that when using <code>smartsheet_client.Cells.get_cell_history()</code> I am only getting the first instance of 'value' but the other varaibles are fine e.g. 'modifiedAt'.</p> <pre><code>import smartsheet as ss smartsheet_client = ss.Smartsheet(SMARTSHEET_ACCESS_TOKEN) SMARTSHEET_ACCESS_TOKEN = 'add you...
<python><python-3.x><smartsheet-api>
2025-04-18 21:07:26
1
1,865
Cam
79,581,618
5,781,499
PyMuPDF - Extract table contents
<p>I try to extract the table text of a PDF: <a href="https://i.sstatic.net/65R5FitB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/65R5FitB.png" alt="enter image description here" /></a></p> <p>With the following code code i get:</p> <pre><code>page 0 of page-1-ocr.pdf Tables rowsasf 49 texysdft [['', ...
<python><pdf><ocr><text-extraction><pymupdf>
2025-04-18 19:39:43
0
4,049
Marc
79,581,617
913,098
SitemapLoader(sitemap_url).load() hangs
<pre><code>from langchain_community.document_loaders import SitemapLoader def crawl(self): print(&quot;Starting crawler...&quot;) sitemap_url = &quot;https://gringo.co.il/sitemap.xml&quot; print(f&quot;[CRAWLER] Loading sitemap: {sitemap_url}&quot;) try: loader = Sitema...
<python><web-crawler><langchain><rag>
2025-04-18 19:38:13
2
28,697
Gulzar
79,581,533
620,679
Find pairs of keys for rows that have at least one property in common
<p>I'm using polars with a data frame whose schema looks like this:</p> <pre><code>Schema({'CustomerID': String, 'StockCode': String, 'Total': Int64}) </code></pre> <p>interpreted as &quot;Customer <em>CustomerID</em> bought <em>Total</em> of product <em>StockCode</em>.&quot; I'm looking for an efficient way to generat...
<python><join><python-polars>
2025-04-18 18:20:34
3
4,041
Scott Deerwester
79,581,373
2,110,944
How to create custom component in Langflow that can stream contant into ChatOutput
<p>In langflow components have OpenAI component than can stream its output into Chat Output</p> <p>When call this prompt flow via http api with stream, we can see stream-recive chunk of data. This chunks we can detect by <code>&quot;event&quot;: &quot;token&quot;</code> param in the body. And final result detect by <co...
<python><langflow>
2025-04-18 16:00:33
0
487
theSemenov
79,581,312
8,869,570
How to sum values across dicts?
<p>I'm using python 3.7. I have a list of dicts that and I want to create a concatenated dict where that concatenated dicts sums over values (grouped by keys) per key in the initial list of dicts.</p> <p>So e.g.,</p> <pre><code>d1 = {1: 1.1, 2: 2.2} d2 = {1: 3.3, 4: 5.5} </code></pre> <p>The result should be:</p> <pre>...
<python><dictionary><python-3.7>
2025-04-18 15:20:41
2
2,328
24n8
79,581,301
299,754
How to find all references of a pytest fixture in vscode?
<p>I'm refactoring a suite of tests and pytest fixtures, and need to <strong>locate all usages of a fixture within the test suite</strong>.</p> <p>The 'Find all references' function of VSCode is what I'd normally use when refactoring a method, to find and review all places affected, but it doesn't work for fixtures. Th...
<python><visual-studio-code><testing><pytest><fixtures>
2025-04-18 15:14:56
1
6,928
Jules Olléon
79,581,277
25,874,132
What's causing this weird jump in these phase graphs of Fourier coefficients?
<p>This is from an assignment in signal processing in Python. It's all done in Python (through Google Colab) with the libraries cmath, numpy, and matplotlib alone.</p> <p>Signal a is a window signal, and I calculate its Fourier coefficients as ak. In the same vein, bk is the Fourier coefficients of signal b.</p> <p>(th...
<python><numpy><matplotlib><signal-processing>
2025-04-18 14:59:04
0
314
Nate3384
79,581,046
1,026
lock specific dependency versions with `uvx` (uv tool run)
<p>I can request a specific version of tool and python when using <a href="https://docs.astral.sh/uv/concepts/tools/" rel="nofollow noreferrer"><code>uv</code>'s tool functionality</a>, e.g.:</p> <pre><code>uvx --python=3.10 --from=&quot;jupyterlab@4.0.10&quot; jupyter-lab </code></pre> <p>But I don't see <strong>a way...
<python><uv>
2025-04-18 12:39:24
1
32,485
Nickolay
79,580,670
16,383,578
Fast calculation of Nth generalized Fibonacci number of order K?
<p>How can I calculate Nth term in Fibonacci sequence of order K efficiently?</p> <p>For example, Tribonacci is Fibonacci order 3, Tetranacci is Fibonacci order 4, Pentanacci is Fibonacci order 5, and Hexanacci is Fibonacci order 6 et cetera.</p> <p>I define these series as follows, for order K, A<sub>0</sub> = 1, A<su...
<python><algorithm><fibonacci>
2025-04-18 08:24:13
1
3,930
Ξένη Γήινος
79,580,497
5,722,359
Error: cupy_backends.cuda.libs.cudnn.CuDNNError: cuDNN Error: CUDNN_STATUS_NOT_SUPPORTED
<p>I am trying to run <code>CuDNN</code> via <code>CuPy</code> but is experiencing the above mentioned error. <strong>How do I resolve this error?</strong> I have tried to check that all my args and kwargs are correct but still could not figure a way to overcome this issue.</p> <p>Nvidia GPU used has a compute capabili...
<python><cupy><cudnn><uv>
2025-04-18 05:53:30
1
8,499
Sun Bear
79,580,362
5,679,985
Why does Django not hot-reload on M1 Mac?
<p>I have a Django application. Back when I was using an Intel mac, it's hot-reloading functionality was working. However, a year ago I switched to one of the new Macs and now I can't get it to hot-reload.</p> <p>Here is my settings.py:</p> <pre><code> import os import firebase_admin BASE_DIR = os.path.abspath(os.pat...
<python><django>
2025-04-18 02:37:57
2
1,274
Human Cyborg Relations
79,580,343
13,562,186
Word to excel using python but preserve word format (bullet points) and structure
<p>Script to convert word documents to excel. Works well but fails to keep structure and certain characters like bullet points.</p> <pre><code> import tkinter as tk from tkinter import filedialog import re import os import subprocess from docx import Document from docx.oxml.text.paragraph import CT_P from docx.oxml....
<python><openpyxl><python-docx>
2025-04-18 02:04:32
1
927
Nick
79,580,309
1,609,514
How to align Pandas Periods of frequency 12 hours to start and end at 00:00 and 12:00
<p>I want to divide a large dataset into 12-hour periods of data starting/ending at midnight and noon each day.</p> <p>I was planning to use <a href="https://pandas.pydata.org/docs/reference/api/pandas.Period.html" rel="nofollow noreferrer">Pandas.Period</a> for this but I noticed that it converts an arbitrary datetime...
<python><pandas><datetime><period>
2025-04-18 01:35:05
1
11,755
Bill
79,580,250
395,857
How can I export an encoder-decoder PyTorch model into a single ONNX file?
<p>I converted the PyTorch model <a href="https://huggingface.co/Helsinki-NLP/opus-mt-fr-en" rel="nofollow noreferrer"><code>Helsinki-NLP/opus-mt-fr-en</code></a> (HuggingFace), which is an encoder-decoder model for machine translation, to ONNX using this script:</p> <pre class="lang-py prettyprint-override"><code>impo...
<python><pytorch><huggingface-transformers><onnx><machine-translation>
2025-04-17 23:59:25
0
84,585
Franck Dernoncourt
79,580,208
13,634,560
How to add jitter to plotly.go.scatter() in python when mode="lines"
<p>I have a dataframe as such:</p> <pre><code>Starting point Walking Driving Lunch 0 8 4 Shopping 0 7 3 Coffee 0 5 2 </code></pre> <p>Where I want to draw, for each index, a green line from &quot;Starting point&quot; -&gt; &quot;Walking&quot;, and a red line from &quot;Starting point&quot; -&...
<python><plotly><jitter>
2025-04-17 22:57:28
2
341
plotmaster473
79,580,145
2,499,281
How to focus tksheet in tkinter window
<p>I am trying to focus a tksheet so I can use the arrows to move around the cells, but nothing is working. I am trying to understand <a href="https://ragardner.github.io/tksheet/DOCUMENTATION.html#set-focus-to-the-sheet" rel="nofollow noreferrer">this documentation</a>.</p> <p>I tried</p> <pre><code>def key_table(even...
<python><tkinter>
2025-04-17 21:51:16
1
794
catquas
79,580,115
103,252
Proper type hint for a listify function
<p>I'm using VS Code with Pylance, and having problems correctly writing type hints for the following function. To me, the semantics seem clear, but Pylance disagrees. How can I fix this without resorting to <code>cast()</code> or <code># type ignore</code>? Pylance warnings are given in the comments.</p> <p>I am fu...
<python><python-typing>
2025-04-17 21:27:26
1
1,932
Watusimoto
79,580,057
5,292,347
Creating epub file with cover in python
<p>I`m trying to create an epub file in python.The table of content and the content including images of the epub file are both fine, only the cover is not showing up. The file is generated without a cover, it's not an error of having a cover without loading the image.</p> <p>It seems there is an issue with the cover fu...
<python><epub>
2025-04-17 20:42:06
0
1,224
Carlos Siestrup
79,579,904
25,874,132
why is there a complex argument in the array here trying to do DTFS?
<p>I have a window signal, which i calculate it's Fourier coefficients but then in the output i get a small complex value [3 order of magnitude less in the origin and the same order of magnitude in the edges of my sampling (from -1000 to 1000)] where the output should be purely real, if it was just a floating point app...
<python><numpy><math>
2025-04-17 18:55:48
2
314
Nate3384
79,579,884
2,125,392
How to tell Python to re-evaluate a parent class method's interface?
<p>Over the years, I can't count how many times I wanted to do something like this in Python:</p> <pre><code>class A: DEFAULT_MESSAGE = &quot;Unspecified Country&quot; def do_it(message=DEFAULT_MESSAGE): print(message) class B(A): DEFAULT_MESSAGE = &quot;Mexico&quot; </code></pre> <p>And have this...
<python><class>
2025-04-17 18:40:53
1
15,484
CivFan
79,579,614
4,528,716
@Gtk.Template and inheritance
<p>I'm trying to make an abstract class and it's subclass in python, where subclasses can be loaded from .ui template. I've managed to make it work more or less, but still can't understand why I'm getting one warning. Let's start with code:</p> <pre><code>from abc import ABCMeta, abstractmethod from gi.repository impor...
<python><inheritance><gtk>
2025-04-17 15:36:37
0
2,800
Damian Dudycz
79,579,581
6,829,655
Memory leak on ECS fargate sidecar container
<p>I have a Python application running on AWS ECS Fargate with a <strong>simple</strong> sidecar container. The sidecar is responsible for:</p> <ul> <li>Receiving gRPC requests from the main application(on localhost:port)</li> <li>Querying a local SQLite database to extract configuration data</li> <li>Simple transform ...
<python><amazon-web-services><memory-leaks><amazon-ecs><aws-fargate>
2025-04-17 15:20:08
1
651
datahack
79,579,568
3,343,425
task.result() throws InvalidStateError instead of CancelledError on cancelled task
<p>I built the following construct which is supposed to call a bunch of asynchronous operations and return as soon as any one of them completes or the timeout expires.</p> <pre class="lang-py prettyprint-override"><code>import asyncio async def async_operation(): while True: await asyncio.sleep...
<python><python-asyncio>
2025-04-17 15:12:13
2
725
fghibellini
79,579,457
2,864,143
Navigate to a different file from terminal
<p>I am debugging my package written in python from venv. Such that the repo source files, where the changes the the source appear are different from the source files installed in venv.</p> <p>Is it somehow possible (some extension?) to map the paths, that are included in the python exception trace (the env ones) to th...
<python><visual-studio-code><python-venv>
2025-04-17 14:11:42
0
960
Student4K
79,579,330
14,860,526
Python multiprocessing.Queue strange behaviour
<p>Hi I'm observing a strange behaviour with python multiprocessing Queue object.</p> <p>My environment:</p> <pre><code>OS: Windows 10 python: 3.13.1 </code></pre> <p>but I observed the same with:</p> <pre><code>OS: Windows 10 python: 3.12.7 </code></pre> <p>and:</p> <pre><code>OS: Windows 10 python: 3.10.14 </code></p...
<python><queue><python-multiprocessing><exit-code>
2025-04-17 13:12:58
1
642
Alberto B
79,579,181
447,426
Exponential run time behavior in simple pyspark operation
<p>My task is simple, i have a binary file that needs to be split into 8byte chunks where first 4bytes contain data (to be decoded in later step) the 2nd 4byte contain an int (time offset in ms). Some of these 8byte blocks are repeated - i want them to be removed. If at the end i have a reminder less than 8byte i mark ...
<python><apache-spark><pyspark><time-complexity>
2025-04-17 11:48:19
3
13,125
dermoritz
79,578,969
12,156,208
How do I replace "NaN" in a pandas dataframe with a dictionary?
<p>Sample dataframe:</p> <pre class="lang-py prettyprint-override"><code>df = pd.DataFrame([[1, {'t': 1}], [2, {'t': 2}], [3, np.nan], [4, np.nan]], columns=['A', 'B']) </code></pre> <pre><code> A B 0 1 {'t': 1} 1 2 {'t': 2} 2 3 NaN 3 4 NaN </code></pre> <p>What I want:</p> <pre><code> A ...
<python><pandas><dataframe>
2025-04-17 09:58:15
2
1,206
r4bb1t
79,578,619
11,110,509
MS Graph SDK - How to perform date range query to get emails in certain time frame?
<p>I'm using the python MS graph sdk to try to perform a query. I'm able to successfully get all of the user's emails, but I can't seem to be able to use the sdk to get the emails from a certain time range. I've searched the their repo</p> <p><a href="https://github.com/microsoftgraph/msgraph-sdk-python" rel="nofollow ...
<python><outlook><microsoft-graph-api><outlook-restapi>
2025-04-17 06:36:08
1
2,703
WHOATEMYNOODLES
79,578,520
13,946,204
How to annotate dict-like object with key-value structure in Python?
<p>Let's say that I have a class like:</p> <pre class="lang-py prettyprint-override"><code>from typing import Any class A: def __init__(self, *args): self.items: list[int] = list(args) def __getitem__(self, k: str): v = int(k) if v in self.items: return v return None def __setitem__(self,...
<python><python-typing>
2025-04-17 05:18:39
2
9,834
rzlvmp
79,578,306
1,413,856
Implementing DKIM or SPF in a Python package
<p>(I’m a bit vague about how email authentication works, so please bear with me).</p> <p>I am writing a Python application which will send an email. This app is then packaged using PyInstaller so that it can be deployed to other non-Python users.</p> <p>I’ve got it working to some extent. The technique I use is:</p> <...
<python><email><dkim>
2025-04-17 01:08:37
2
16,921
Manngo
79,577,779
714,077
How Do We Use numpy to Create a Matrix of all permutations of three separate value ranges?
<p>I want to make a pandas dataframe with three columns, such that the rows contain all permutations of three columns, each with its own range of values are included. In addition, I want to sort them asc by c1, c2, c3.</p> <p>For example, a = [0,1,2,3,4,5,6,7], b = [0,1,2], and c= [0,1]. The result I want looks like th...
<python><dataframe><numpy><permutation>
2025-04-16 17:26:48
5
961
noogrub
79,577,540
8,964,393
Python - Trading IG - Reason: ATTACHED_ORDER_LEVEL_ERROR
<p>I have tried to place a limit order in Python (using Trading-IG).</p> <p>Here is the code:</p> <pre><code> resp = ig_service.create_working_order( currency_code=&quot;GBP&quot;, direction=&quot;BUY&quot;, epic='IX.D.SPTRD.DAILY.IP', expiry='DFB', guaranteed_stop=False, ...
<python><rest><limit><trading>
2025-04-16 15:24:03
0
1,762
Giampaolo Levorato
79,577,512
6,896,234
Pytest caplog not capturing logs
<p>See my minimal example below for reproducing the issue:</p> <pre><code>import logging import logging.config def test_logging(caplog): LOGGING_CONFIG = { &quot;version&quot;: 1, &quot;disable_existing_loggers&quot;: False, &quot;formatters&quot;: { &quot;default&quot;: { ...
<python><python-3.x><pytest>
2025-04-16 15:10:06
1
2,054
Elgin Cahangirov
79,577,490
3,104,974
How to fit scaler for different subsets of rows depending on group variable and include it in a Pipeline?
<p>I have a data set like the following and want to scale the data using any of the scalers in <code>sklearn.preprocessing</code>.</p> <p>Is there an easy way to fit this scaler not over the whole data set, but per group? My current solution can't be included in a Pipeline:</p> <pre><code>import pandas as pd import num...
<python><pandas><scikit-learn><data-transform><scikit-learn-pipeline>
2025-04-16 14:58:55
1
6,315
ascripter
79,577,224
14,386,187
Redis-py not returning consistent results for match all query
<p>I'm attempting to add 100 documents to a Redis index, and then retrieving them with a match all query:</p> <pre class="lang-py prettyprint-override"><code>import uuid import redis from redis.commands.json.path import Path import redis.commands.search.aggregation as aggregations import redis.commands.search.reducers ...
<python><redis><redis-py>
2025-04-16 12:45:30
2
676
monopoly
79,577,174
580,083
How to interpolate circle arc with lines on Earth surface?
<p>I have the coordinates (lat, lon) of 3 points (P0, P1, P2) on the Earth surface. The distance between P1 and P0 is the same as the distance between P2 and P0. Therefore, one can make a circle arc from P1 to P2 with P0 as a centre. My problem is that I need to interpolate this circle arc by N lines to be able to work...
<python><geojson><geo>
2025-04-16 12:22:38
1
24,034
Daniel Langr
79,576,828
16,611,809
Get a grouped sum in polars, but keep all individual rows
<p>I am breaking my head over this probably pretty simply question and I just can't find the answer anywhere. I want to create a new column with a grouped sum of another column, but I want to keep all individual rows. So, this is what the docs say:</p> <pre><code>import polars as pl df = pl.DataFrame( { &q...
<python><dataframe><window-functions><python-polars><polars>
2025-04-16 09:29:12
1
627
gernophil
79,576,352
16,383,578
Is it possible to use the closed-form of Fibonacci series to generate the Nth Fibonacci number exactly and efficiently?
<p>The closed-form of the Fibonacci series is the following:</p> <p><img src="https://i.sstatic.net/elWkx.png" alt="" /></p> <p>As you can see the expression contains square roots so we cannot use it directly to generate Nth Fibonacci number exactly, as sqrt(5) is irrational, we can only approximate it even in pure mat...
<python><algorithm><fibonacci>
2025-04-16 03:40:19
2
3,930
Ξένη Γήινος
79,576,335
13,746,021
poetry shows as "no such file or directory" in Makefile, but works fine in terminal
<p>I am experimenting with using the CPython C API and managing dependencies (e.g. setuptools) via poetry.</p> <p>To compile my code I wrote a Makefile looking something like this:</p> <pre class="lang-makefile prettyprint-override"><code>PYTHON = poetry run python build: setup.py ...some C extension files... $(PY...
<python><makefile><python-poetry>
2025-04-16 03:12:49
1
361
Rusty
79,576,316
597,234
Exceptions being hidden by asyncio Queue.join()
<p>I am using an API client supplied by a vendor (Okta) that has very poor/old examples of running with async - for example (the Python documentation says not to use <code>get_event_loop()</code>):</p> <pre class="lang-py prettyprint-override"><code>from okta.client import Client as OktaClient import asyncio async def...
<python><python-asyncio><okta-api>
2025-04-16 02:48:59
2
2,036
yakatz
79,576,073
2,499,281
Can you create multiple columns based on the same set of conditions in Polars?
<p>Is it possible to do something like this in Polars? Like do you need a separate when.then.otherwise for each of the 4 new varialbles, or can you use <strong>struct</strong> to create multiple new variables from one when.then.otherwise?</p> <p>Regular Python example:</p> <pre><code>if x=1 and y=3 and w=300*z and z&lt...
<python><dataframe><conditional-statements><python-polars><polars>
2025-04-15 21:50:59
1
794
catquas
79,575,941
10,705,248
Why does RandomForestClassifier in scikit-learn predict even on all-NaN input?
<p>I am training a random forest classifier in python <code>sklearn</code>, see code below-</p> <pre><code>from sklearn.ensemble import RandomForestClassifier rf = RandomForestClassifier(random_state=42) rf.fit(X = df.drop(&quot;AP&quot;, axis =1), y = df[&quot;AP&quot;].astype(int)) </code></pre> <p>When I predict th...
<python><machine-learning><scikit-learn><random-forest><missing-data>
2025-04-15 19:53:59
1
854
lsr729
79,575,935
381,121
Trying to exeute the DBMS_STATS function in a python script
<p>I inherited a 1000+ line query the works in oracle's sql developer.<br /> When I try running the query in a python script, I get an error (An error occurred: ORA-00900: invalid SQL statement) at the line: <strong>EXEC DBMS_STATS.gather_table_stats('SSS', 'YYY')</strong>.</p> <p>I have very little experience with da...
<python><oracle-database>
2025-04-15 19:50:28
2
489
ChrisJ
79,575,919
11,313,748
Suggestion needed for enhancing problem formulation for constraint programming
<p>I'm trying to formulize a constraint programming solution for item allocation on shelf. The goal is simple items belonging to same brand should be kept as close as possible and should maintain a decent square or rectangular block.</p> <p>for this, the approach we have taken is we have divided the whole available spa...
<python><optimization><linear-programming><constraint-programming><cpmpy>
2025-04-15 19:36:40
1
391
Anand
79,575,741
6,101,024
Add a new row as the average of columns
<p>Give the following dataframe:</p> <pre><code>_BETTER _SAME _WORSE ___dataset Metric 0.373802 0.816794 0.568783 Train precision 0.391304 0.865229 0.519324 Train recall 0.382353 0.840314 0.542929 Train f1-score 0.500000 1.000000 0.583333 Val precision 0.33...
<python><pandas><dataframe>
2025-04-15 17:38:39
1
697
Carlo Allocca
79,575,684
5,423,080
PyTorchMetrics Mean Absolute Percentage Error extremely high value
<p>I am using <code>PyTorch</code> for a face recognition coursework and I have to calculate the MAPE value.</p> <p>My first attempt was with <code>torchmetrics.MeanAbsolutePercentageError</code> class, but the result doesn't make sense.</p> <p>For this reason I wrote a function to calculate it and it seems to work fin...
<python><pytorch><torchmetrics>
2025-04-15 17:03:25
1
412
cicciodevoto
79,575,456
1,480,131
Is a lock needed when multiple tasks push into the same asyncio Queue?
<p>Consider this example where I have 3 worker tasks that push results in a queue and a tasks that deals with the pushed data.</p> <pre class="lang-py prettyprint-override"><code> async def worker1(queue: asyncio.Queue): while True: res = await do_some_work(param=1) await queue.put(res) async def ...
<python><locking><python-asyncio>
2025-04-15 14:43:50
1
13,662
Pablo
79,575,363
2,939,369
how to force numba to return a numpy type?
<p>I find this behavior quite counter-intuitive although I suppose there is a reason for it - numba automatically converts my numpy integer types directly into a python int:</p> <pre class="lang-py prettyprint-override"><code>import numba as nb import numpy as np print(f&quot;Numba version: {nb.__version__}&quot;) #...
<python><numba>
2025-04-15 14:09:27
2
831
Raven
79,575,221
10,755,782
How to add a progress bar to Python multiprocessing.Pool without slowing it down (TQDM is 7x slower)?
<p>I'm running a long computation using multiprocessing.Pool in Python, and I wanted to add a progress bar to track it. Naturally, I tried tqdm with pool.imap, but surprisingly, it's ~7.3x slower than using pool.map() without it.</p> <p>Here's a minimal example to reproduce the issue:</p> <pre class="lang-py prettyprin...
<python><multiprocessing><tqdm>
2025-04-15 13:03:19
2
660
brownser
79,575,107
2,431,627
Correct selector to target a 'Textual' SelectionList selected items' text?
<p>I have a <a href="https://textual.textualize.io/" rel="nofollow noreferrer">Textual</a> <code>SelectionList</code> in my Python console app:</p> <pre class="lang-py prettyprint-override"><code>... yield SelectionList[str]( *tuple(self.selection_items), id=&quot;mylist&quot;) ... </code></pre> <p>In my associate...
<python><tui><textual>
2025-04-15 12:08:51
1
1,973
Robin Macharg
79,575,076
2,350,145
How to fit the font-awesome icon with text in the nicegui mermaid graph nodes
<p>I am trying to create a <code>mermaid</code> graph in nicegui. I am able to fit the icon and text in the graph node. But in browser only the icon is showing up. I know it is because of the width of the node's label. How to fix it?</p> <p><a href="https://i.sstatic.net/MvUXGqpB.png" rel="nofollow noreferrer"><img src...
<python><nicegui>
2025-04-15 11:56:05
2
5,808
Anirban Nag 'tintinmj'
79,575,019
389,119
How to configure Playwright so that the Chrome inspector opens at the bottom instead of the right?
<p>Since I often open the inspector while debugging tests in Playwright, I'd like to know if there's a way to make it open at the bottom when pressing F12 instead of to the right. I know I can change the position manually by clicking there:</p> <p><a href="https://i.sstatic.net/SVUoo.png" rel="nofollow noreferrer"><img...
<python><google-chrome><playwright><playwright-python>
2025-04-15 11:23:11
1
12,025
antoyo
79,574,989
3,719,399
How to write polars dataframe to S3 with partition_by?
<p>I am able to write a polars dataframe to S3 when <code>partition_by=None</code> using the following code:</p> <pre><code>import os import s3fs import polars as pl df = pl.DataFrame({'a': [1, 2, 3, 4], 'b': ['left', 'left', 'right', 'right']}) os.environ['AWS_CA_BUNDLE'] = r'C:\my\path\to\cert.pem' fs = s3fs.S3Fil...
<python><amazon-s3><python-polars>
2025-04-15 11:01:52
1
988
chengcj
79,574,821
1,908,650
How do I center vertical labels in a seaborn barplot?
<p>When I add a vertical text label to a <code>seaborn</code> bar chart, the labels are offset to the left of centre, like so:</p> <p><a href="https://i.sstatic.net/AwiQwH8J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AwiQwH8J.png" alt="enter image description here" /></a></p> <p><strong>How can I nu...
<python><matplotlib><seaborn>
2025-04-15 09:40:40
1
9,221
Mohan
79,574,649
388,506
How to create a virtual record of a variable?
<p>I have this defined in my equipment:</p> <pre><code>class AssetEquipment(model.Models): _name = &quot;asset.tracking&quot; _description = &quot;Module to track asset movement&quot; scrap_date = fields.Date('Scrap date') owner_id = fields.Many2one('res.users', string='Owner', default=False, tracking=...
<python><odoo><odoo-18>
2025-04-15 08:09:29
0
2,157
Magician
79,574,578
17,795,398
VSCode pylance not detecting matplotlib and mpi4py
<p>This is the problem in VSCode:</p> <pre><code>import matplotlib.pyplot as plt # Import &quot;matplotlib.pyplot&quot; could not be resolved from sourcePylancereportMissingModuleSource from mpi4py import MPI # No name 'MPI' in module 'mpi4py'PylintE0611:no-name-in-module </code></pre> <p>However, when I run the code...
<python><matplotlib><visual-studio-code><pylance><mpi4py>
2025-04-15 07:27:10
0
472
Abel Gutiérrez
79,574,571
8,899,106
Is PyPNG outaded or wrongly documented?
<p>I'm trying to save rows of pixels in python using PyPNG. First of all, i'm seeing various use of <code>png.Writer(width, height, bitdepth=8, greyscale=False)</code> with different input, from :</p> <ul> <li><a href="https://png.Writer(width,%20height,%20bitdepth=8,%20greyscale=False)" rel="nofollow noreferrer">a sim...
<python><pypng>
2025-04-15 07:20:25
1
772
Portevent
79,574,506
3,554,605
Algorand: TransactionPool.Remember: TransactionPool.ingest: no pending block evaluator
<p>I am currently trying out Algorand, with the intention of self-hosting a completely new network with just a single command.</p> <p>You can try it out via</p> <pre class="lang-bash prettyprint-override"><code>$ git clone https://github.com/hermesloom/algorand-node-fly $ cd algorand-node-fly $ ./setup.sh 100 EUR </cod...
<python><algorand>
2025-04-15 06:37:45
0
1,429
sigalor
79,574,433
4,050,510
Cannot run PyVista/VTK inside a Huggingface multiprocessing map()
<p>The following code crashes, with a forking error. It say <code>objc[81151]: +[NSResponder initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.</c...
<python><fork><huggingface-datasets><pyvista>
2025-04-15 05:34:54
1
4,934
LudvigH
79,574,386
16,869,946
Constructing custom loss function in lightgbm
<p>I have a pandas dataframe that records the outcome of F1 races:</p> <pre><code>data = { &quot;Race_ID&quot;: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4], &quot;Racer_Number&quot;: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4], &quot;Win_odds&quot;: [2.3, 4.3, 1.3, 5.0, 3.4...
<python><loss-function><lightgbm>
2025-04-15 04:37:08
1
592
Ishigami