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
78,341,716
6,197,439
Can you catch a PyQt5 "fail fast exception" in Python?
<p>Usually, if you call a non-existing method on a PyQt5 object, like calling <code>.show()</code> on a boolean variable as in the click handler below, which is an example that will always trigger an exception:</p> <pre class="lang-python prettyprint-override"><code>import sys, os from PyQt5.QtWidgets import QApplicati...
<python><exception><pyqt5>
2024-04-17 14:22:12
1
5,938
sdbbs
78,341,624
1,422,096
OrderedDict with fully custom key order
<p>I know that keys have no order in a <code>dict</code> (even, if, they keep the insertion order in the recent implementations, as I saw this in CPython core developer Hettinger's video, but this is out of topic).</p> <p>Is there a data structure in Python that behaves like a <code>dict</code>, but for which <strong>t...
<python><dictionary><ordereddictionary><ordereddict>
2024-04-17 14:10:02
1
47,388
Basj
78,341,400
6,197,439
Python log both ("tee") to terminal and file, and real-time flushing with PyQt5?
<p>First of all, my platform:</p> <pre class="lang-none prettyprint-override"><code>$ for ix in &quot;uname -s&quot; &quot;python3 --version&quot;; do echo &quot;$ix: &quot; $($ix); done uname -s: MINGW64_NT-10.0-19045 python3 --version: Python 3.11.9 </code></pre> <p>I would like in my PyQt5 application to have a lo...
<python><python-3.x><pyqt5><flush><output-buffering>
2024-04-17 13:37:18
0
5,938
sdbbs
78,341,248
13,014,864
Supply hex color values to heat map Plotnine
<p>I am working with some data and would like to make a heat map with a specified, pre-made color palette. The data frame is shown below (I am using <code>polars</code> for all the data frame ops in this analysis).</p> <pre><code>┌──────────────┬─────────────┬────────────────┬──────────────────────┬─────────┐ │ team1 ...
<python><colors><python-polars><plotnine>
2024-04-17 13:13:14
1
931
CopyOfA
78,341,192
11,861,874
Python to PPTX using python-pptx library
<p>I am trying to update ppt using python. I have following set of code and need a help to solve following issue.</p> <ol> <li>Value in table should be integer with comma seperator.</li> <li>The columns should auto adjust as sometime figures are too big and it spill over to next row which doesn't solve the pupose of au...
<python><python-pptx><presentation>
2024-04-17 13:04:34
2
645
Add
78,341,075
7,838,169
I want to do a self join on a model using SQLAlchemy and then serialize it to JSON but get maximum recursion error
<p>I have a <code>User</code> model like the following</p> <pre><code>class User(Base): __tablename__ = 'user' id: so.Mapped[int] = so.mapped_column(primary_key=True, autoincrement=True, index=True) hashed_password: so.Mapped[str] = so.mapped_column(sa.String(256), nullable=False) created_by_id: so.Ma...
<python><sqlalchemy><fastapi>
2024-04-17 12:44:46
0
3,316
badger
78,340,704
1,923,575
git permission denied error in airflow dag when access git in subprocess or bashoperator
<p>I'm using Airflow on my local env using Docker Compose The Docker compose I'm using is <a href="https://airflow.apache.org/docs/apache-airflow/2.9.0/docker-compose.yaml" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-airflow/2.9.0/docker-compose.yaml</a></p> <p>Here are the <code>docker compose ps<...
<python><git><subprocess><airflow><airflow-2.x>
2024-04-17 11:45:59
1
1,771
Ashwin Hegde
78,340,613
2,249,312
xbbg blp.bdib function for certain commodity
<p>I set everything up so that it works with the ticker CO1 Comdty. In the terminal CO1 Comdty Des says the exchange on which this trades is &quot;ICE-ICE Futures Europe - Commodities&quot;. In my two files it looks as follows:</p> <p>asset.yml</p> <pre><code>Comdty: tickers: [CL] exch: NYME freq: M is_fut: True t...
<python><bloomberg><xbbg>
2024-04-17 11:25:19
0
1,816
nik
78,340,585
354,051
similarity score in between 2D arrays of different size
<p><a href="https://i.sstatic.net/izfO4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/izfO4.png" alt="paths for similarity score" /></a></p> <p>These are 2D (z=0) poly lines in 3D application Blender and they are used as paths. I would like to know the similarity score between them.</p> <p>It’s importa...
<python><cosine-similarity><cross-correlation>
2024-04-17 11:20:19
0
947
Prashant
78,340,572
774,575
Why does groupby with dropna=False prevent a subsequent MultiIndex.dropna() to work?
<p>My understanding is <code>MultiIndex.dropna()</code> removes index entries for which at least one level is <code>NaN</code>, there are no conditions. However it seems if a previous <code>groupby</code> was used with <code>dropna=False</code>, it's no longer possible to use <code>MultiIndex.dropna()</code>.</p> <ul> ...
<python><pandas><multi-index>
2024-04-17 11:17:34
2
7,768
mins
78,340,399
13,827,112
How to save several figures from an animation created by FuncAnimation?
<p>is it possible to save, for instance, 10 figures from a video, that is created as follows?</p> <pre><code>ani = FuncAnimation(fig, update, frames=num_frames, interval=40, blit=True) # Interval is in milliseconds dpi = 300 # Adjust this value as needed writer = FFMpegWriter(fps=60, bitrate=5000) ani.save('animatio...
<python><python-3.x><matplotlib><animation><figure>
2024-04-17 10:49:45
0
1,195
Elena Greg
78,340,390
2,583,346
Embedding plotly interactive figures in a confluence page
<p>Is there a way to embed my plotly figures in a confluence page? Here's what I've tried:</p> <pre><code>import plotly.express as px x = [1,1,2,3,3,3,4,5] fig = px.histogram(x=x) fig.write_html('my.html') </code></pre> <p>Then I tried copy-pasting the HTML from <code>my.html</code> into a HTML macro in a Confluence pa...
<python><plotly><confluence>
2024-04-17 10:48:28
0
1,278
soungalo
78,340,305
5,105,207
Gekko: parameter identification on a Spring-Mass system
<p>I want to do parameter estimation on a Spring-Mass system</p> <p><a href="https://i.sstatic.net/GZcpj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GZcpj.png" alt="enter image description here" /></a></p> <p>with direct collocation method. The parameter k should be determined from response.</p> <p>I...
<python><gekko>
2024-04-17 10:31:31
1
1,413
Page David
78,340,226
633,001
apply() with VLines vs HLines (holoviews)
<p>My code:</p> <pre><code>import holoviews as hv import numpy as np hv.extension('bokeh') def filter_lines(lines, x_range, y_range): if x_range is None or y_range is None: return lines if len(lines[x_range, y_range]) &gt; 40: return lines[x_range, y_range].opts(alpha=0.0) return lines[x_ra...
<python><holoviews>
2024-04-17 10:19:22
0
3,519
SinisterMJ
78,340,143
9,608,860
E bot.ftech_channel raises error with pytest AttributeError: '_MissingSentinel' object has no attribute 'is_set'
<p>I have a discord bot which needs to fetch guild and channels. If I get none from bot.get_guild(), I try to fetch_guild through api. The code looks something like this:</p> <pre><code>async def get_or_fetch_guild(obj_id, bot, guild): guild = bot.get_guild(obj_id) status = 'SUCCESS' status_code = 200 i...
<python><discord><discord.py><pytest>
2024-04-17 10:06:32
0
405
Aarti Joshi
78,340,115
1,841,839
write_videofile throws list index out of range - but works
<p>I have a bunch of videos in a directory 1.mp4, 2.mp4 .... I am merging them into output_1_2.mp4.</p> <p>The following code works, but ..</p> <p>Its throwning an error that i cant seem to figure out.</p> <blockquote> <p>Merging: videos/1.mp4 videos/2.mp4 videos/output_1_2.mp4<br> Length of clips list: 2<br> Moviepy ...
<python><moviepy>
2024-04-17 10:02:57
0
118,263
Linda Lawton - DaImTo
78,340,111
12,560,241
Comparing Columns , Arrays, List using SQL, Numpy or Python List. Would Intertools be valid alternative and faster?
<p>I have two table in SQL</p> <p>tModel which has 9 columns (ID, Date N1, N2, N3, N4, N5, N6, Flag) and 300 million rows</p> <p>tPairAP which has 3 columns (ID, N1, N2) and 750 rows</p> <p>The task I need to to perform is to find if any rows on tModel for N1, N2, N3, N4, N5, N6 contain N1 and N2 from tPairAP</p> <p>De...
<python><sql><arrays><list><python-itertools>
2024-04-17 10:02:31
2
317
Marco_sbt
78,340,019
8,163,773
Python debuger with vscode ipmort local files error
<p>When I try to launch vscode debugger it fails on the line where I try to import something from local files saying that the module is not installed.</p> <blockquote> <p>No module named 'app' File &quot;/path/to/my_project/app/script.py&quot;, line 1, in from app.other_cript import helper ModuleNotFoundError: No modu...
<python><visual-studio-code>
2024-04-17 09:48:59
1
9,359
Arseniy-II
78,339,830
5,624,602
Python TKinter progressbar style issue
<p>I'm writing a TKinter GUI app and having issue with the progressbar style configuration. I'm running the same code in different machines and one time it is ok and in the other it is not.</p> <pre><code>import tkinter as tk from tkinter import ttk root = tk.Tk() app = tk.Frame(root) app.pack() app.green_style = ...
<python><python-3.x><tkinter><windows-10>
2024-04-17 09:20:08
2
1,513
STF
78,339,718
2,902,280
mamba claims package is already installed when it is not
<p>When installing <code>seaborn</code>, mamba says it is already present. Yet trying to import it in my python interpreter (the mamba one) fails:</p> <pre><code>(base) ➜ materials git:(main) ✗ mamba install seaborn Looking for: ['seaborn'] conda-forge/linux-64 Using cache cond...
<python><python-packaging><mamba>
2024-04-17 09:04:10
1
13,258
P. Camilleri
78,339,449
3,548,089
what is the best approach to compute Brun's constant with python (witch include primality test and long run sum)?
<p>Brun's constant : <a href="https://en.wikipedia.org/wiki/Brun%27s_theorem" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Brun%27s_theorem</a> <a href="http://numbers.computation.free.fr/Constants/Primes/twin.html" rel="nofollow noreferrer">http://numbers.computation.free.fr/Constants/Primes/twin.html</a></...
<python><math><computation>
2024-04-17 08:22:03
1
310
Ch'nycos
78,339,444
13,987,643
Pandas filtering yields null values
<p>I have a df which I am filtering based on a particular column. This is my code to do that</p> <pre><code>test_table[(test_table['Item']=='1')] </code></pre> <p>Ideally this code should return the rows where the value of column 'Item' is equal to '1'. Instead it returns the full dataframe with just that particular ro...
<python><pandas><dataframe><filter>
2024-04-17 08:21:40
0
569
AnonymousMe
78,339,197
1,088,076
Is it possible to utilize a lambda function in an python-attrs converter?
<p>I am attempting to automatically create converter functions that require metadata to operate. I am seeing odd behavior when a lambda function is used for the converter.</p> <pre><code>import attrs def add(x, y=10): return x + y def func(cls, fields): results = [] for f in fields: y = f.metadata...
<python><python-attrs>
2024-04-17 07:43:47
0
1,911
slaughter98
78,339,142
15,140,144
PyGame: asynchronous version of pygame.time.Clock.tick()
<p>There is no API for asynchronous <code>Clock.tick()</code> in pygame, how could I implement something like this? (This could be useful for things like <code>pygbag</code> that require async main loop.)</p>
<python><pygame-ce>
2024-04-17 07:33:19
0
316
oBrstisf8o
78,339,121
161,110
Get user assignments to Azure AVD application group with python sdk
<p>I'm trying to get the assignments of an AVD application group, but I do not see any way to do it in the python azure sdk:</p> <p><a href="https://learn.microsoft.com/en-us/python/api/azure-mgmt-desktopvirtualization/azure.mgmt.desktopvirtualization.models.applicationgroup?view=azure-python" rel="nofollow noreferrer"...
<python><azure><virtual-desktop><azure-avd>
2024-04-17 07:29:51
1
2,196
Jorge
78,339,087
827,927
Is it possible to have a default value that depends on a previous parameter?
<p>Suppose I want to write a recursive binary search function in Python. The recursive function needs to get the start and end of the current search interval as parameters:</p> <pre><code>def binary_search(myarray, start, end): ... </code></pre> <p>But, when I call the actual function from outside, I always start at 0 ...
<python><default-value>
2024-04-17 07:24:20
1
37,410
Erel Segal-Halevi
78,338,848
1,231,450
Pandas all() but with a threshold
<p>Suppose we have the following dataframe and program logic</p> <pre><code>import pandas as pd df = pd.DataFrame({'A': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'B': [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]}) def more_than(series, threshold=5): try: trues = series.value_counts()[True] p = trues / len(series) *...
<python><pandas>
2024-04-17 06:41:57
1
43,253
Jan
78,338,808
1,814,498
How to interpret the Coefficient of nonlinear regression in scikit learn?
<p>I am using the following code to do a nonlinear regression, and I am getting an intercept &amp; 20 coefficients. How to interpret those coefficients to be able to construct a formula Y = intercept + coeff*feat_a + .....?</p> <pre><code>data = pd.read_csv(&quot;data.csv&quot;) # Step 2: Preprocess the data X = data...
<python><scikit-learn><linear-regression><polynomial-approximations>
2024-04-17 06:34:36
1
736
Ziri
78,338,736
13,250,589
How to call a one Firebase function from another Firebase function using python SDK
<p>I am deploying functions on firebase in python.</p> <p>I want to call one firebase function from another and pass some data to it. I have looked into documentation and I cannot find a proper method.</p> <p>I tried to follow the approach mentioned in <a href="https://groups.google.com/g/firebase-talk/c/t_2xEmBrKEo/m/...
<python><firebase><google-cloud-functions>
2024-04-17 06:16:58
1
885
Hammad Ahmed
78,338,658
4,847,250
Is it possible to use Curve_fit on several signal without a for loop?
<p>I'm wondering if it is possible to make a curve fitting for a matrix directly without making a for loop I would like to make the curve fitting directly on an array where each line is a signal to estimate. So at the end I would like to have popt as an array 2XN</p> <pre><code># -*- coding: utf-8 -*- import matplotlib...
<python><curve-fitting>
2024-04-17 05:57:40
0
5,207
ymmx
78,338,367
14,259,505
"ValueError: year -1 is out of range" -error while trying to import data
<p>There are invalid or unexpected values in the timestamp data being processed, such as negative years or null values. How to address this issue, we need to ensure that the timestamp values are correctly formatted and within the valid range for conversion to Python datetime objects.</p> <pre><code>import psycopg2 impo...
<python>
2024-04-17 04:32:19
0
391
Yogesh Govindan
78,338,208
1,088,076
In python Attrs package, how to add a field in the field_transformer function?
<p>The documentation for the python Attrs, the <a href="https://www.attrs.org/en/stable/extending.html#automatic-field-transformation-and-modification" rel="nofollow noreferrer">Automatic Field Transformation and Modification</a> section states</p> <blockquote> <p>...You can add converters, change types, and even remov...
<python><python-attrs>
2024-04-17 03:31:59
1
1,911
slaughter98
78,337,846
8,076,158
Looping over a variable number of columns in a dataframe
<p>I want to speed up my row loop in a Pandas DataFrame, using the zip columns trick, like this:</p> <pre><code>import pandas as pd df = pd.DataFrame({&quot;a&quot;: [0,1], &quot;b&quot;: [2,3]}) for a, b in zip(df[&quot;a&quot;], df[&quot;b&quot;]): pass </code></pre> <p>The dataframe has a variable number of col...
<python><pandas>
2024-04-17 00:47:47
2
1,063
GlaceCelery
78,337,824
4,855,843
Segmentation Fault when calling FFMPEG on Lambda - but not locally
<p>I am trying to extract the next 30 seconds of audio from a live video stream on YouTube using AWS Lambda. However, I'm facing an issue where Lambda does not wait for an FFmpeg subprocess to complete, unlike when running the same script locally. Below is a simplified Python script illustrating the problem:</p> <pre><...
<python><amazon-web-services><aws-lambda><ffmpeg><subprocess>
2024-04-17 00:33:52
0
489
thiagogps
78,337,737
1,498,830
How do I copy-paste a worksheet from one excel workbook to another using python?
<p>In Excel, I can manually:</p> <ul> <li>open the source workbook</li> <li>select the sheet I want to copy</li> <li>click the Select All button in the upper left corner</li> <li>ctrl-c</li> <li>open the targe workbook</li> <li>insert a new sheet using the tabs at the bottom</li> <li>select the new sheet's A1 cell</li>...
<python><excel><automation><copy-paste><xlwings>
2024-04-16 23:43:29
1
2,962
spierepf
78,337,715
1,524,372
Adding a method to an existing enum in Python
<p>I have an existing enumeration with a number of values defined in package <code>b</code>, and I want to add behavior in the current package <code>a</code>. I understand that you can't directly subclass an enum with existing members but I am trying to reuse the existing names/values without having to duplicate them....
<python><enums><subclassing>
2024-04-16 23:32:08
0
311
Paul
78,337,671
1,564,852
Python ffill with calculation for timestamp as fill value
<p>I have a table as follows</p> <pre><code>Timestamp | record_id 01-04-2024 00:00 | 1 01-04-2024 00:01 | 2 01-04-2024 00:02 | 3 01-04-2024 00:03 | 4 N/A | 5 N/A | 6 01-04-2024 00:06 | 7 </code></pre> <p...
<python><dataframe><forward-fill>
2024-04-16 23:09:22
1
1,192
Visahan
78,337,596
5,224,236
2024: chrome not reachable python selenium
<p>I want to open a Chrome window with my settings and connect to it via Selenium.</p> <p>I start Chrome then try to connect but I get this error:</p> <pre><code>selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at localhost:9014 from chrome not reachable. </code></pre> <...
<python><google-chrome><selenium-webdriver>
2024-04-16 22:38:37
1
6,028
gaut
78,337,532
689,242
Python language server is installed but not found by Helix text editor
<h2>Problem description</h2> <p>I am using Helix text editor and am trying to add a Python language server (<a href="https://github.com/python-lsp/python-lsp-server" rel="nofollow noreferrer">link</a>) to it.</p> <p>I installed Python 3 using the <code>.exe</code> from their official website. Then I executed these comm...
<python><helix-editor><pylsp>
2024-04-16 22:16:39
1
1,505
71GA
78,337,315
4,061,339
Disable a button only during an expensive operation in streamlit
<ul> <li>python 3.12.2</li> <li>streamlit 1.33.0</li> </ul> <p>I have an expensive operation and would like to disable a button to execute it only during the operation. In other words, there is an enabled button. When you press it, it is disabled and the operation starts. When the operation ends, the button is enabled ...
<python><button><streamlit><isenabled>
2024-04-16 21:04:29
1
3,094
dixhom
78,337,034
10,145,953
Deskew image using opencv in Python
<p>I am preprocessing images of PDFs which will eventually have text extracted from them. I am using <code>opencv</code> for the bulk of the preprocessing work and due to constraints of the client environment, I can really only stick to using <code>opencv</code> for the image processing. I have a function (below) to de...
<python><opencv><image-processing>
2024-04-16 19:49:45
1
883
carousallie
78,336,924
651,174
Partition by column, order by another
<p>I am simulating a SQL query with the following values:</p> <pre><code>rows = [(1, '2021/04', 'Shop 2', 341227.53), (2, '2021/05', 'Shop 2', 315447.24), (3, '2021/06', 'Shop 1', 1845662.35), (4, '2021/04', 'Shop 2', 21487.63), (5, '2021/05', 'Shop 1', 1489774.16), (6, '2021/06', 'Shop 1', 52489.35), (7, '2021/04', 'S...
<python><python-3.x><lambda><functional-programming>
2024-04-16 19:24:09
1
112,064
David542
78,336,798
13,349,653
Mysterious "Killed" message
<p>I am trying to run a program that consumes a large, but not infeasible amount of memory (see below). I checked that my computer has <code>15.6GiB</code> according to <code>htop</code>. However, this exits with the message <code>Killed</code>. Why is this happening and how can I confirm it?</p> <pre class="lang-py pr...
<python><numpy><out-of-memory>
2024-04-16 18:57:35
0
1,788
Test
78,336,767
23,260,297
Strip all column values, but check if any tuples exist
<p>I have multiple dataframes that use the same functions to strip all the values. However, some of the values are tuples and it is throwing an error whenever I come across stripping a tuple.</p> <p>My function looks like this:</p> <pre><code>for col in df.columns: if df[col].dtype == 'object': d...
<python><pandas>
2024-04-16 18:50:15
1
2,185
iBeMeltin
78,336,597
1,120,370
How do I use PymuPDF/fitz to denormalize xobjects?
<p>I have a PDF that contains some xobjects. I need to denormlize them, i.e. make a copy of each xobject in every place it appears in the document. How can I do this using <a href="https://pymupdf.readthedocs.io/en/latest/" rel="nofollow noreferrer">PymuPDF/fitz?</a></p> <p>I've been reading the documentation and askin...
<python><pdf><pymupdf>
2024-04-16 18:13:33
0
17,226
W.P. McNeill
78,336,492
2,751,433
Unable to cancel asyncio.task from another function
<p>I was expecting to cancel <code>foo_wrapper</code> using <code>cancel</code> function, however, it still generates result.</p> <p>If I change <code>foo_wrapper</code> as non-async function and change <code>self.lock</code> to <code>threading.Lock</code> solves the issue. Any idea?</p> <pre><code>import asyncio from ...
<python><python-asyncio>
2024-04-16 17:53:14
2
673
flexwang
78,336,105
929,122
Generate dynamic tasks with Airflow with .expand
<p>I have the a DAG with the following structure:</p> <pre class="lang-py prettyprint-override"><code>with DAG( # configs go here ) as dag: def get_intervals() # logic to retrieve some data from CloudSQL return intervals # intervals looks like: [['0'], ['10'], ['50'], ['10...
<python><airflow><google-cloud-composer>
2024-04-16 16:39:30
0
437
drake10k
78,335,986
11,814,996
Show more minor/major tick labels when using log10 scale with matplotlib.axes.Axes.set_yscale
<pre class="lang-py prettyprint-override"><code>import pandas as pd from matplotlib import pyplot as plt ## making data temp_df = pd.DataFrame({'year': [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012], 'numbers': [2684044.85, 4005117.02, 3046403.46, 6413495.07, 148...
<python><matplotlib>
2024-04-16 16:16:24
1
3,172
Naveen Reddy Marthala
78,335,850
8,382,452
How to multiprocess/multithread documents loading in chromadb?
<p>I'm creating an application with langchain, chromadb and ollama with mistral model, where I have dozens of PDF files, each of them with a lot of pages. The problem is that It takes a lot of time (34min to get 30 PDF files in the vector database) and the streamlit application awaits all this time too to load.</p> <p>...
<python><langchain><large-language-model><chromadb>
2024-04-16 15:53:09
1
345
Yuri Costa
78,335,778
22,466,650
How to create a summary table from a dictionary of lists with different len?
<p>My input is this dict :</p> <pre><code>response = { 'A': ['CATEGORY 2'], 'B': ['CATEGORY 1', 'CATEGORY 2'], 'C': [], 'D': ['CATEGORY 3'], } </code></pre> <p>And I'm trying to make this kind of dataframe :</p> <pre><code>| ITEM | CATEGORY 1 | CATEGORY 2 | CATEGORY 3 | | A | |...
<python><pandas>
2024-04-16 15:40:50
1
1,085
VERBOSE
78,335,566
4,442,337
Django: how to disable the HTTP_HOST check on a specific endpoint?
<p>I defined a super simple healthcheck endpoint in my Django app (<code>urls.py</code>) to be used in a docker compose environment, like:</p> <pre class="lang-yaml prettyprint-override"><code>services: django: build: context: . dockerfile: ./compose/production/django/Dockerfile depends_on: ...
<python><django><docker-compose>
2024-04-16 15:09:35
0
2,191
browser-bug
78,335,536
8,721,169
Can I profile my pip requirements installation to see which ones take time?
<p>I'm looking for a way to sort the requirements of a project, depending to the time they typically need to be downloaded and installed.</p> <p>I'm aware this time may have a huge variance depending on a lot of external parameters, but I guess it should still be possible to tell which packages cost the most time.</p> ...
<python><pip><google-cloud-functions><requirements.txt>
2024-04-16 15:04:21
0
447
XGeffrier
78,335,498
10,927,457
Interpolation between two Dataframes (years with values) in Pyspark
<p>How can I implement linear interpolation between two PySpark DataFrames representing data for different years, say 2020 and 2030, to generate a new PySpark DataFrame for an intermediary year like 2025? Both DataFrames have identical structures with numeric values. The years have the same granularity.</p> <p>My initi...
<python><dataframe><apache-spark><pyspark><interpolation>
2024-04-16 14:58:34
1
582
Pfinnn
78,335,474
8,831,742
python-constraint not solving the n-queens puzzle
<p>I'm using the <code>python-constraint</code> library to try to solve the <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle" rel="nofollow noreferrer">n-queens problem</a> (n queens are placed on an n-by-n board and they must be arranged in such a way that they don't menace each other)</p> <p>My formulation ...
<python><constraint-programming><python-constraint>
2024-04-16 14:55:29
1
353
none none
78,335,413
6,741,546
Google Cloud Dataflow : ModuleNotFoundError: No module named 'package'
<p>I'm building a Google Cloud Dataflow pipeline using Python 3.8 to parse data from a pub/sub topic. I followed every tutorial about it, it compiles and launches, but when executed I always get:</p> <pre><code>LoadMainSessionException: Could not load main session. Inspect which external dependencies are used in the ma...
<python><docker><google-cloud-platform><google-cloud-dataflow>
2024-04-16 14:44:20
0
340
Jean Walrave
78,335,190
3,232,771
_repr_html_ not showing when custom __getattr__ implemented
<p>I'm trying to implement <code>_repr_html_</code> on a python class (<a href="https://ipython.readthedocs.io/en/stable/config/integrating.html" rel="nofollow noreferrer">docs</a>).</p> <p>The class is a read-only facade for navigating a JSON-like object using attribute notation (based on example 19-5 from Fluent Pyth...
<python><visual-studio-code><ipython><getattr><repr>
2024-04-16 14:09:48
1
396
davipatti
78,335,141
4,847,250
is it possible to optimize a curve fitting where a variable depend on another?
<p>I'm wondering if it is possible to make a curve fitting od a dual exponential where the parameter b is strictly superior to the parameter d?. I don't understand how I can add such a constraint.</p> <p>Here's a minimal example</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from scipy.optimize impor...
<python><optimization><scipy><curve-fitting>
2024-04-16 14:03:37
1
5,207
ymmx
78,335,103
3,623,537
overload typing for variable amount of arguments (`args` or `kwargs`)
<p>Example is below, need to make sure IDE type checker or <code>reveal_type</code> would identify <code>k</code>, <code>j</code> and <code>i</code> types correctly.</p> <p>Perhaps there is some way to suggest the typing that <code>args</code> is an empty <code>tuple</code> and <code>kwargs</code> empty <code>dict</cod...
<python><python-typing>
2024-04-16 13:58:49
1
469
FamousSnake
78,335,078
10,595,871
NoSuchElementException in Selenium with text cell
<p>The code:</p> <pre><code>driver = webdriver.Chrome() driver.get(&quot;https://commercialisti.it/iscritti&quot;) driver.implicitly_wait(10) casella_testo = driver.find_element(&quot;id&quot;, &quot;Cap&quot;) </code></pre> <p>The error:</p> <pre><code>NoSuchElementException: Message: no such element: Unable to loca...
<python><selenium-webdriver>
2024-04-16 13:54:35
1
691
Federicofkt
78,334,902
118,549
Efficient way to lookup prices based on date ranges
<p>I'm playing around with importing my energy usage data into Python, and I'm trying to figure out a good way to do price lookups.</p> <p>The unit energy price changes a few times a year, so I have ranges of dates and the unit price, for example:</p> <pre class="lang-none prettyprint-override"><code>start_date end...
<python><data-structures><lookup>
2024-04-16 13:29:55
3
752
Gordon Mckeown
78,334,676
7,695,845
Monte Carlo simulation of PI with numba is the slowest for the lowest number of points?
<p>As part of a homework exercise, I am implementing a Monte-Carlo simulation of pi in Python. I am using Numba to accelerate and parallelize the computation. From a previous test I performed, I found that parallelized <code>numba</code> runs faster than a non parallelized <code>numba</code> version and from a pure <co...
<python><numba><montecarlo>
2024-04-16 12:52:01
1
1,420
Shai Avr
78,334,661
2,768,539
Get XGBoost prediction based on individual trees
<p>It might be duplicated from <a href="https://stackoverflow.com/questions/43702514/how-to-get-each-individual-trees-prediction-in-xgboost">How to get each individual tree&#39;s prediction in xgboost?</a> but the solution no longer works (possibly to changes on XGBoost library). My idea is to dump the model in a raw f...
<python><machine-learning><xgboost>
2024-04-16 12:49:27
2
387
rriccilopes
78,334,486
13,394,817
How to add labels without markers and in place of them (left aligned merging label and marker) in legends
<p>I want to add some parameters with their values into legends, which have no markers and must be left aligned placing on top of other markers positions (i.e. in a column with other markers). It will be done with using titling them in legends if we have just one columnar legend. The problem arises when two or more col...
<python><matplotlib>
2024-04-16 12:19:32
0
2,836
Ali_Sh
78,334,416
14,358,734
Trying to switch between frames in tkinter
<p>I'm trying to design a (semi) text-based game in tkinter. I'd like to be able to switch between frames, with each frame acting as a menu or map. However, each button in each frame is present from the start, and transitioning from e.g. <code>Opening</code> to <code>NewGame</code> doesn't make the buttons in <code>Ope...
<python><tkinter>
2024-04-16 12:05:07
2
781
m. lekk
78,334,332
16,389,095
SQL Queries: the most common value in a column grouped by another column
<p>Let's say I have a database employee.db, created as following:</p> <pre><code># %% CREATE DATAFRAME data = {'Name': ['John', 'Jane', 'Adam', 'Jane', 'Frank', 'Mary'], 'Age': [35, 28, 42, 32, 35, 39], 'Department': ['HR', 'IT', 'Finance', 'IT', 'Sales', 'IT']} df = pd.DataFrame(data) # %% CREATE A SQ...
<python><sql><pandas><sqlite>
2024-04-16 11:48:39
1
421
eljamba
78,334,276
4,999,991
How to Set gfortran Compiler Flags in a Complex Build System Involving Makefile.am, configure.ac, and setup.py?
<p>Following <a href="https://stackoverflow.com/q/78311453/4999991">this question</a>, I am working on building <a href="https://github.com/JModelica/JModelica" rel="nofollow noreferrer">a project</a> that involves compiling <a href="https://github.com/JModelica/JModelica/tree/master/external/Assimulo/thirdparty/hairer...
<python><makefile><gfortran><configure><autotools>
2024-04-16 11:37:43
0
14,347
Foad S. Farimani
78,334,193
940,490
`pandas` rolling sum with a maximum number of valid observations in a window
<p>I am looking for help to speed up a rolling calculation in <code>pandas</code> which would compute a rolling average with a predefined maximum number of most recent observations. Here is code to generate an example frame and the frame itself:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd im...
<python><pandas><dataframe><pandas-rolling>
2024-04-16 11:25:46
1
1,615
J.K.
78,334,117
6,197,439
pyqt5 layout.replaceWidget kills setTextInteractionFlags of unrelated QLabel?
<p>Consider the following example, based on the example from <a href="https://www.pythonguis.com/tutorials/pyqt-dialogs/" rel="nofollow noreferrer">https://www.pythonguis.com/tutorials/pyqt-dialogs/</a> , where I want to have a custom QDialog class, where text in the label is selectable, and where I can control the but...
<python><pyqt5>
2024-04-16 11:13:34
1
5,938
sdbbs
78,334,080
17,530,552
How can I speed up the processing of my nested for loops for a giant 3D numpy array?
<p>I created a very large 3D numpy array called <code>tr_mat</code>. The shape of <code>tr_mat</code> is:</p> <pre><code>tr_mat.shape (1024, 536, 21073) </code></pre> <p><strong>Info on the 3D numpy array:</strong> First and before going into the actual code, I would like to clarify what I am attempting to do. As can b...
<python><numpy><performance><multidimensional-array>
2024-04-16 11:07:13
1
415
Philipp
78,334,011
3,127,059
OpenCV gstreamer backend use GPU for H264 encoding
<p>I have a gstreamer pipeline to encode frames in H264, it's working but I have a noticeable latency or delay of 2 seconds or more.</p> <p>I've seen that my program is not using GPU, so maybe this is the main cause of that delay. I have read that I can use vaapih264enc but seems to be not available in my gstreamer ins...
<python><opencv><gpu><gstreamer><h.264>
2024-04-16 10:55:37
0
808
JuanDYB
78,334,004
4,999,991
How to Automatically Split Overlong Lines in FORTRAN 77 Files Using Python?
<p>Following <a href="https://stackoverflow.com/q/78311453/4999991">this question</a>, I'm working with <a href="https://github.com/JModelica/JModelica/tree/master/external/Assimulo/thirdparty/hairer" rel="nofollow noreferrer">legacy FORTRAN 77 files</a> and need to address an issue where some lines exceed the 72-chara...
<python><regex><automation><text-processing><fortran77>
2024-04-16 10:54:51
0
14,347
Foad S. Farimani
78,333,840
16,725,431
Scrapers blocked but not browser
<p>I am trying to scrape from <code>https://www.[cencored].com/</code> using python</p> <p>At first, it worked with a simple <code>request.get()</code>, however, the subsequent attempts failed <strong>on the next day</strong>. I did allow Windows to update in between. Not sure if it's the cause. I tried including heade...
<python><python-3.x><selenium-webdriver><web-scraping><python-requests>
2024-04-16 10:25:57
1
444
Electron X
78,333,729
5,790,653
openpyxl creates incorrect sheet names within for loop
<p>This is my code:</p> <pre class="lang-py prettyprint-override"><code>import os import sys my_path = 'C:/Users/S.Fazlollahzadeh/Desktop/shell-scripts/test only/excel' os.chdir(my_path) sys.path.append(my_path) from openpyxl import Workbook names = ['name1', 'name2', 'name3', 'name4'] wb = Workbook() ws = wb.active ...
<python>
2024-04-16 10:07:34
2
4,175
Saeed
78,333,689
5,790,653
openpyxl appends all data to one column instead of multiple columns
<p>This is my code and my first issue (I may ask a new question for the second one which is related to this one):</p> <pre class="lang-py prettyprint-override"><code>import random from openpyxl import Workbook from openpyxl.worksheet.table import Table, TableStyleInfo wb = Workbook() ws = wb.active names = ['name1', '...
<python>
2024-04-16 10:01:42
0
4,175
Saeed
78,333,583
8,968,910
Python: map json format with names in another list
<p>I have a table.json file like this:</p> <pre><code> { &quot;tables&quot;: [ { &quot;name&quot;: &quot;table_1&quot;, &quot;columns&quot;: { &quot;column1&quot;: &quot;name&quot;, &quot;column2&quot;: &quot;address&quot; ...
<python><json>
2024-04-16 09:45:19
1
699
Lara19
78,333,191
475,766
What can I do about Overfitting in Tabular Data Model
<p>I've built a predictive model for predicting outcomes based on certain features in the supplied data.</p> <p>The model is a tabular learner utilizing fastai.</p> <p>The dataset consists of about 300 records split for training, validation and testing sets.</p> <p>I've implemented techniques to address overfitting suc...
<python><machine-learning><fast-ai>
2024-04-16 08:38:01
1
8,296
Ortund
78,333,176
1,835,727
Prophet forecast data doesn't match observed data
<h1>Context</h1> <p>I'm trying to model office attendance using the <a href="https://facebook.github.io/prophet/" rel="nofollow noreferrer">Prophet</a> library in python. My data is pretty simple, headcounts at 15 minute intervals. It's shown by the black dots in the plot below.</p> <p><a href="https://i.sstatic.net/yj...
<python><facebook-prophet>
2024-04-16 08:35:57
3
13,530
Ben
78,333,012
1,711,271
Replace a Polars column with a 1D array or Series
<p>Sample df:</p> <pre><code>import polars as pl import numpy as np df = pl.DataFrame( { &quot;nrs&quot;: [1, 2, 3, None, 5], &quot;names&quot;: [&quot;foo&quot;, &quot;ham&quot;, &quot;spam&quot;, &quot;egg&quot;, None], &quot;random&quot;: np.random.rand(5), &quot;A&quot;: [True, T...
<python><dataframe><replace><python-polars>
2024-04-16 08:02:19
2
5,726
DeltaIV
78,332,995
1,841,839
After installing Python 3.12.3, it fails to create a venv
<p>I just installed the new version of <a href="https://www.python.org/downloads/" rel="nofollow noreferrer">Python</a>.</p> <p>It installed correctly:</p> <pre class="lang-none prettyprint-override"><code>C:\Development\pythontest&gt;python --version Python 3.12.3 </code></pre> <p>When I try to create the new venv it ...
<python>
2024-04-16 07:59:08
1
118,263
Linda Lawton - DaImTo
78,332,952
7,123,933
Airflow sensor which checks if GCS object was updated
<p>I would like to have a DAG which checks if avro file on GCS and if yes go to another task. This avro file comes to gcs under different names so i would like to use prefix to just get any avro file in the folder. I used code like this:</p> <pre class="lang-py prettyprint-override"><code> gcs_sensor = GCSObjectsWit...
<python><google-cloud-platform><google-cloud-storage><airflow>
2024-04-16 07:52:54
1
359
Lukasz
78,332,877
2,149,718
TypeError: cannot unpack non-iterable MultiPoint object
<p>In my python app I am using Shapely. Invoking the function below:</p> <pre><code>def get_t_start(t_line: geometry.LineString): print('get_t_start', t_line.boundary) p1, p2 = t_line.boundary t_start = p1 if p1.y &lt; p2.y else p2 return t_start </code></pre> <p>produces the following output:</p> <bloc...
<python><python-3.x><shapely>
2024-04-16 07:38:20
1
72,345
Giorgos Betsos
78,332,807
5,147,886
Convert HMAC signature from Go into R
<p>I am trying to reproduce the following golang code in R for creating the signature for the <a href="https://github.com/consbio/mbtileserver" rel="nofollow noreferrer">consibio/mbtilesever</a>. The aim is to build apps in R and python which can access mbtileservers uisng a secure connection. While I am able to genera...
<python><r><go><hmacsha1><mbtiles>
2024-04-16 07:25:35
1
440
pdbentley
78,332,753
11,922,237
Decreasing the text granularity when working with image_to_boxes in `pytesseract`
<p>I have the following image:</p> <p><a href="https://i.sstatic.net/snH0B.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/snH0B.png" alt="enter image description here" /></a></p> <p>I tried <code>image_to_boxes</code> function to draw bounding boxes but the boxes are drawn around each letter. I am guess...
<python><ocr><tesseract><python-tesseract>
2024-04-16 07:17:28
0
1,966
Bex T.
78,332,519
11,671,779
My Python 3.11 did not use new error message
<p>I'm using Python 3.10 for my daily driver because of some dependency. Now, I just download Python 3.11, install it, and successfully use environment.</p> <pre><code>(env311) PS D:\user\package&gt; py Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] on win32 Type &quot;help&quot...
<python><python-3.11>
2024-04-16 06:26:44
1
2,276
Muhammad Yasirroni
78,332,401
14,320,103
Sympy breaks regex in python?
<p>I have the code:</p> <pre class="lang-py prettyprint-override"><code>import re import math #from sympy import * # breaks? #x, y, z = symbols('x y z') #init_printing(use_unicode=True) def evaluate_expression(expr, variables): # Evaluate the expression using eval(), and provide the variables dictionary retur...
<python><regex><math><sympy>
2024-04-16 05:57:48
1
619
Vatsa Pandey
78,332,120
354,979
Flax neural network with nans in the outputs
<p>I am training a neural network using Flax. My training data has a significant number of nans in the outputs. I want to ignore these and only use the non-nan values for training. To achieve this, I have tried to use <code>jnp.nanmean</code> to compute the losses, i.e.:</p> <pre><code>def nanloss(params, inputs, targe...
<python><tensorflow><deep-learning><jax><flax>
2024-04-16 04:28:05
1
7,942
rhombidodecahedron
78,332,079
7,497,127
LogisticRegression model producing 100 percent accuracy
<p>I have fetched Amazon Reviews for a product and now trying to train a logistic regression model on it to categorize customer reviews. It gives 100 percent accuracy. I am unable to understand the issue. Here is a sample from my dataset:</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>Name<...
<python><pandas><dataframe><machine-learning><logistic-regression>
2024-04-16 04:09:28
1
1,375
JAMSHAID
78,332,025
7,994,685
How to add another pass through to langchain using expression languages
<p>I am using Langchain's expression language to create a retriever. The goal is to create a function where the AI checks the response to a previous interaction.</p> <p>Therefore, I need to give this function two inputs: the original question and the answer. This means I want to pass two parameters to it: 'question' an...
<python><langchain>
2024-04-16 03:49:41
1
1,328
Sharif Amlani
78,331,868
3,174,398
How to (idiomatically) read indexed arrays from a delimited text file?
<p>I have text files from an external source that are formatted like so:</p> <pre><code> 0 0 -0.105961 0.00000 1 0 -1.06965 0.00000 1 1 -0.0187213 -0.240237 2 0 -0.124695 0.00000 2 1 -0.178982 0.0633255 2 2 ...
<python><arrays><matrix><file-io><julia>
2024-04-16 02:42:36
3
489
rigel
78,331,861
16,115,413
Counting Tokens with Message History in OpenAI: Correct Approach?
<p>Issues Identified on the Internet:</p> <ol> <li><p>Websites like <a href="https://tiktokenizer.vercel.app/" rel="nofollow noreferrer">https://tiktokenizer.vercel.app/</a> are useful for counting tokens, but they seem to have limitations when memory is involved in the API, especially when handling both new and old me...
<python><token><openai-api><large-language-model><chatgpt-api>
2024-04-16 02:40:22
0
549
Mubashir Ahmed Siddiqui
78,331,796
2,604,247
How Does .venv in Python Inherit Jupyter Notebook from System?
<h5>Context</h5> <p>I was <em>not</em> a regular virtual environment user. I just used to install pip packages at the user level like</p> <pre class="lang-bash prettyprint-override"><code>python3 -m pip install --user tensorflow </code></pre> <p>and worked with it. This is how installed my jupyter lab as well to work w...
<python><python-3.x><jupyter-notebook><pip><pipenv>
2024-04-16 02:15:23
1
1,720
Della
78,331,636
857,932
What is the cleanest way to replace a hostname in an URL with Python?
<p>In Python, there is a standard library module <code>urllib.parse</code> that deals with parsing URLs:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import urllib.parse &gt;&gt;&gt; urllib.parse.urlparse(&quot;https://127.0.0.1:6443&quot;) ParseResult(scheme='https', netloc='127.0.0.1:6443', path='...
<python><urllib><url-parsing>
2024-04-16 01:02:21
2
2,955
intelfx
78,331,391
1,361,802
moto upgrade results in error The queue should either have ContentBasedDeduplication enabled or MessageDeduplicationId provided explicitly
<p>I upgraded moto from 4.1.x to 4.2.x and now I am hitting this error when I run my pytest unit tests.</p> <blockquote> <p>botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the SendMessage operation: The queue should either have ContentBasedDeduplication enabled or MessageDeduplic...
<python><amazon-web-services><boto3><amazon-sqs><moto>
2024-04-15 23:11:18
1
8,643
wonton
78,331,165
1,913,367
Setting new values in subset of xarray dataset
<p>I have a xarray dataset covering longitudes from 9 to 30 and 54 to 66. How to set all the variables in that dataset from certain coordinate range to -1?</p> <p>As soon as I do df.isel or df.iloc or df.sel or df.loc, I get a subset of data, which is much smaller than the original dataset. I would like to obtain datas...
<python><python-xarray><netcdf>
2024-04-15 21:44:02
1
2,080
msi_gerva
78,331,020
8,713,442
Unable to write data in file
<p>I have data stored in one file - delimiter tab {'id': '123', 'name': 'pečnostní informační služba'}</p> <p>When I am trying to read the data and write data in 2nd file using python code but getting error</p> <pre><code> with open(output_file, 'w') as f_output, open(input_file,encoding = 'utf-8-sig') as f_input: ...
<python><python-3.x><python-unicode>
2024-04-15 21:05:05
1
464
pbh
78,330,930
1,194,864
Disabling fusing attention in ViT models in PyTorch
<p>I am inspecting different vision transformer models on <code>PyTorch</code> and I am trying to understand their differences. My models can be seen in the following code:</p> <pre><code>retrained_vit_weights = torchvision.models.ViT_B_16_Weights.DEFAULT # requires torchvision &gt;= 0.13, &quot;DEFAULT&quot; means bes...
<python><pytorch><transformer-model>
2024-04-15 20:40:16
1
5,452
Jose Ramon
78,330,835
10,944,175
Extract text from dxf that is not TEXT or MTEXT entity using ezdxf
<p>I am trying to get numbers from a specific dxf file using ezdxf.</p> <p>However, a query on the modelspace for <code>msp.query('TEXT')</code> or <code>msp.query('MTEXT')</code> yields no results, if I iterate over all entities, I can see they are all of type <code>INSERT</code>.</p> <p>In the dxf file, I can see num...
<python><ezdxf>
2024-04-15 20:11:07
2
549
Freya W
78,330,829
2,726,900
pandera: how to create a DataFrameSchema or DataFrameModel from existing pandas.DataFrame?
<p>I have written a data transformation function that eats a <code>pandas.DataFrame</code> at input and returns another <code>pandas.DataFrame</code> at ouput. I have a reference <code>pandas.DataFrame</code> object on which I was testing my function.</p> <p>I want to check input data schema to make sure that the schem...
<python><pandas><pydantic><pandera>
2024-04-15 20:09:32
1
3,669
Felix
78,330,672
2,475,195
Python global counter for multiprocessing pool
<p>I want to keep count how many items have already been processed, but I get an error. Here's my minimal code and the error stack trace.</p> <pre><code>import multiprocessing from multiprocessing import Value from ctypes import c_int class DemoProcessor(object): def __init__(self, data_to_process): self...
<python><multiprocessing><process-pool>
2024-04-15 19:35:03
1
4,355
Baron Yugovich
78,330,669
726,730
QTreeWidget internal move rows (only topLevelItems)
<pre class="lang-py prettyprint-override"><code>from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(&quot;MainWindow&quot;) MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) sel...
<python><pyqt5><drag-and-drop><qtreewidget>
2024-04-15 19:33:21
0
2,427
Chris P