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,884,453
5,342,009
Azure Appservice for Django fails with Azure Devops Pipeline
<p>I have an appservice running on Azure in a Linux environment.</p> <p>I try to associate it with a Azure Devops Pipeline so I can have CI/CD for the repositories &amp; branches on Github.</p> <p>I want the builds to occur on Azure Pipeline &amp; Azure infrastructure, not Github Actions.</p> <p>I have tried all other ...
<python><django><azure><azure-devops><azure-pipelines>
2024-08-18 11:24:41
1
1,312
london_utku
78,884,344
4,262,324
How to obtain syntax highlight/coloring for Snakemake file?
<p>The snakemake documentation show syntax highlighting of the <code>Snakefile</code> file, like in here <a href="https://i.sstatic.net/QsEVyRyn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QsEVyRyn.png" alt="enter image description here" /></a></p> <p>Can I obtain something like for the <code>Snakefi...
<python><snakemake>
2024-08-18 10:35:30
2
3,149
Fanta
78,884,251
12,338,762
Unable to install wordnet with nltk 3.9.0 as importing nltk requires installed wordnet
<p>It is not possible to import nltk, and the solution given by the output required me to import nltk:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;import nltk Traceback (most recent call last): File &quot;D:\project\Lib\site-packages\nltk\corpus\util.py&quot;, line 84, in __load root = nltk.da...
<python><nltk><wordnet>
2024-08-18 09:53:51
1
1,263
Maritn Ge
78,884,169
3,561,433
"tf.summary.image" gives Invalid Argument Error for the standard example
<p>I have recently started Tensorflow by trying to replicate some of the existing repos, and I have been stuck at writing summaries since quite some time now.</p> <p>Specifically, I have been trying to port the <a href="https://github.com/bmild/nerf" rel="nofollow noreferrer">https://github.com/bmild/nerf</a> code to T...
<python><tensorflow2.0><tensorboard>
2024-08-18 09:16:40
1
522
Manish
78,884,161
7,695,845
Control how many digits are printed for an astropy quantity in a jupyter notebook
<p>I use <code>astropy</code> to make calculations with units and I normally do these calculations in a jupyter notebook so the results are printed nicely. I would like to know how to control the number of digits that are displayed in the notebook. Take a look at this example:</p> <p><a href="https://i.sstatic.net/iVlF...
<python><jupyter-notebook><astropy>
2024-08-18 09:11:21
1
1,420
Shai Avr
78,884,128
4,454,021
Zip file is only partially downloaded
<p>I am trying to download a zip file with Python 3 requests:</p> <pre><code>try: r = requests.get(BASEURL, stream=True) with open(localfiletitle, 'wb') as fd: shutil.copyfileobj(r.raw, fd) except requests.exceptions.RequestException as e: send_notice_mail(&quot;Error downloading the file:&quot;, e)...
<python><python-requests>
2024-08-18 08:50:17
1
1,677
Fabio Marzocca
78,884,068
16,725,431
ytdlp download video with fixed output path
<p>By default, ytdl adds an extension to the file and I am trying to avoid that.</p> <p>I created the function below to save video files <em>exactly</em> at <code>output_path</code> (will be further used by some other function).</p> <pre><code>import logging import yt_dlp as youtube_dl from typing import Callable, Any,...
<python><youtube-dl><yt-dlp>
2024-08-18 08:14:56
1
444
Electron X
78,884,032
9,397,607
Histogram with bar width not proportional to bar range
<p>Using Matplotlib, I want to display a heavily long-tailed distribution, such as the one in the attached picture. Obviously, this figure is not very readable. What I want to achieve is as follows:</p> <ul> <li>get a histogram with 4 bars of equal width</li> <li>the ranges of the bars must be '0', '1-5', '6-25', '26-1...
<python><matplotlib>
2024-08-18 07:59:31
1
940
Jonas De Schouwer
78,883,943
22,466,650
How to identify groups based on id and sign change?
<p>My input is a dataframe with one column :</p> <pre><code>import pandas as pd df = pd.DataFrame({'ID': ['A1-B1', 'A1-B2', 'A1-B3', 'A1-B8', 'A2-B10', 'A2-B16', 'A2-B9', 'A3-B13', 'A3-B14']}) </code></pre> <p>I'm trying to create a second column that will identify the groups based on two things :</p> <ul> <li>the Axx...
<python><pandas>
2024-08-18 07:14:36
1
1,085
VERBOSE
78,883,931
14,724,837
How to avoid single block formatting when exporting DataFrame to CSV?
<p>I'm facing an issue when exporting a DataFrame to a CSV file using <code>df.to_csv()</code> in pandas. The content in one of my DataFrame columns is multiline text, but when I export it to a CSV file, the entire text block gets written into a single cell without proper line breaks, resulting in an unreadable format....
<python><csv>
2024-08-18 07:07:42
1
689
Megan
78,883,833
1,176,573
Use plotly to plot multiple pandas column with a dropdown menu to select column
<p>I have a pandas dataframe for which I am trying to a plot bar graph using <code>Plotly</code> with a dropdown menu to select by the stock name column, referring <a href="https://stackoverflow.com/a/56236906/1176573">this answer</a>.</p> <p>But I am unsure how do I add multiple columns to the <code>updatemenus</code>...
<python><pandas><drop-down-menu><plotly>
2024-08-18 06:03:07
1
1,536
RSW
78,883,801
16,723,655
umap.plot requires pandas matplotlib datashader bokeh holoviews scikit-image and colorcet to be installed
<pre><code>import sklearn.datasets pendigits = sklearn.datasets.load_digits() mapper = umap.UMAP().fit(pendigits.data) umap.plot.connectivity(mapper, show_points=True) </code></pre> <p>Above code gave me the error below.</p> <pre><code>umap.plot requires pandas matplotlib datashader bokeh holoviews scikit-image and col...
<python>
2024-08-18 05:39:22
2
403
MCPMH
78,883,777
14,250,641
How to Optimize Memory Usage for Cross-Validation of Large Datasets
<p>I have a very large DF (~200GB) of features that I want to perform cross validation on a random forest model with these features. The features are from a huggingface model in the form of a .arrow file.</p> <p>I am trying to figure out how I can minimize the amount of RAM needed to process this code-- even with 600GB...
<python><pandas><dataframe><scikit-learn><huggingface-transformers>
2024-08-18 05:13:15
1
514
youtube
78,883,527
10,589,070
Django Choice Dropdown Not Working on Cloned Form in Formset
<p>I am cloning my an empty form in django following guidance I've found elsewhere in stack overflow. The JS will append a new form as intendended however the dropdowns from a choice widget are no longer working and I can't figure out why.</p> <p>I have already validated that all of my options are there using my brows...
<javascript><python><css><django><materialize>
2024-08-18 00:35:45
1
446
krewsayder
78,883,445
1,285,061
Find absolute difference value between elements using just NumPy array operations
<pre><code>a = np.array([101,105,90,102,90,10,50]) b = np.array([99,110,85,110,85,90,60]) expected result = np.array([2,5,5,8,5,20,10]) </code></pre> <p>How can I find minimum absolute difference value between elements using just <code>numpy</code> operations; with modulus of 100 if two values are across 100.</p>
<python><numpy><numpy-ndarray>
2024-08-17 23:16:00
4
3,201
Majoris
78,883,312
1,405,767
Django REST Framework cached view returning 2 different payloads
<p>I'm experiencing a strange issue with my Django REST Framework paginated list view, which utilizes a 2 hour cache. If I repeatedly make requests to the view's endpoint, I am sometimes getting Response 1 (x bytes in size) and sometimes getting Response 2 (y bytes in size).</p> <p>The view code is as follows:</p> <pre...
<python><django><django-rest-framework>
2024-08-17 21:32:52
1
926
stackunderflow
78,883,292
6,814,154
concate column rows with previous rows based on a condition
<p>I have this CSV file, (part of a very large one)</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>Course/Section</th> <th>Credits</th> <th>Course Name</th> <th>Time</th> <th>Building</th> <th>Instructor</th> <th>Exam Date</th> <th>Course Language</th> </tr> </thead> <tbody> <tr> <td>ACCT11...
<python><pandas>
2024-08-17 21:18:50
1
4,606
Khalil Al Hooti
78,882,910
16,869,946
Complicated nested integrals in terms of python scipy.integrate
<p>I want to write the following complicated function using python <code>scipy.integrate</code>:<a href="https://i.sstatic.net/CughB0rk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CughB0rk.png" alt="enter image description here" /></a></p> <p>where \phi and \Phi are the pdf and cdf of the standard no...
<python><scipy><numerical-integration><quad>
2024-08-17 17:47:45
1
592
Ishigami
78,882,696
2,180,332
How to use dynamic type parameters with mypy?
<p>I need to build a dynamic union of types to be used to create pydantic models dynamically. I am looking how to type the variable to be passed to the <code>Union</code> so mypy is happy.</p> <p>A simplified snipped would look like this:</p> <pre><code>from random import choice, randint from typing import Union types...
<python><python-typing><mypy>
2024-08-17 16:04:08
1
4,656
azmeuk
78,882,661
5,790,653
How to convert bytes to string in a list of dictionaries
<p>I have a list of dictionaries like this:</p> <pre class="lang-py prettyprint-override"><code>list1 = [ {'id': b'1', 'ip': b'1.1.1.1'}, {'id': b'2', 'ip': b'2.2.2.2'} ] </code></pre> <p>How can I convert each value of the dictionaries within a <code>for</code> loop?</p> <p>I first tried like this, but <code>t...
<python>
2024-08-17 15:51:04
2
4,175
Saeed
78,882,526
312,444
Substitute elements of an array using JsonPath
<p>I am using jsonpath-ng to substitute an element of an array. Given the yaml below:</p> <pre><code>paths /api/v1/chats: get: - name: other_chats in: query required: false type: boolean - name: status in: query required: false allOf: - $ref: '#/...
<python><jsonpath><jsonpath-ng>
2024-08-17 14:51:56
1
8,446
p.magalhaes
78,882,469
16,869,946
New rows in Pandas Dataframe by considering combination of rows in the original dataframe and applying function to it
<p>I have a Pandas dataframe df that looks like</p> <pre><code>Class_ID Student_ID theta 6 1 0.2 6 2 0.2 6 4 0.1 6 3 0.5 3 2 0.1 3 5 0.2 3 7 0.22 3 4 0.4 3 ...
<python><pandas><dataframe><group-by>
2024-08-17 14:30:48
3
592
Ishigami
78,882,366
11,565,514
Delete div and label for that div without label id
<p>Using Crispy forms in Django app, I the HTML code:</p> <pre><code>&lt;div id=&quot;div_id_pripadnost&quot; class=&quot;form-group&quot;&gt; &lt;label for=&quot;id_pripadnost_0&quot; class=&quot;&quot;&gt; Pripadnost &lt;/label&gt; &lt;div class=&quot;&quot;&gt; &lt;div class=&quot;form-che...
<javascript><python><html><django><django-crispy-forms>
2024-08-17 13:39:15
1
373
MarkoZg
78,882,352
5,451,769
Plotting a timeseries as bar plot with pandas results in an incorrect year
<p>I have the following dataframe (except my actual data is over 25 years):</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame( dict( date=pd.date_range(start=&quot;2020-01-01&quot;, end=&quot;2020-12-31&quot;, freq=&quot;MS&quot;), data=[1,2,3,4,5,6,7,8,9,10...
<python><pandas><dataframe><matplotlib><plot>
2024-08-17 13:33:37
1
1,366
kdheepak
78,882,326
8,545,455
Python ruamel.yaml - ensure quotes on specific keys
<p>Following on from this question: <a href="https://stackoverflow.com/questions/55808945/json-to-yaml-in-python-how-to-get-correct-string-manipulation">JSON to YAML in Python : How to get correct string manipulation?</a></p> <p>I'd like to have specific key names (regardless of nesting depth) always given a double-quo...
<python><ruamel.yaml>
2024-08-17 13:19:18
1
1,237
tuck1s
78,882,235
15,218,250
How can I send a batch email using postmark in Anymail for Django?
<p>I am trying to use the Anymail API for postmark in my Django application. This is not the same as putting a list of emails in the cc, but I am trying to send a separate email to each individual email address (the email content is the same though). Right now, I have the following to send transactional (one-time) emai...
<python><django><email><django-anymail>
2024-08-17 12:37:36
1
613
coderDcoder
78,882,184
7,784,017
How to properly reload a module in Python
<p>This question has been asked many times, here are a few for reference:</p> <p><a href="https://stackoverflow.com/questions/1254370/reimport-a-module-while-interactive">Reimport a module while interactive</a></p> <p><a href="https://stackoverflow.com/questions/2534480/proper-way-to-reload-a-python-module-from-the-con...
<python><module><python-import>
2024-08-17 12:11:18
1
876
Shayan
78,882,159
5,923,374
How to validate with RetrievalMetric in Lightning on multiple GPU?
<p>I want to compute retrieval metric in distributed setting with torch lightning.</p> <p>Retrieval metrics compute metrics over groups of inputs. This is a problem in distributed setting, because the groups get split between different batches, so just logging the metric in validation step will result in incorrect outp...
<python><pytorch-lightning>
2024-08-17 11:56:51
1
1,538
Ford O.
78,882,117
3,752,268
AssertionError when assigning set with a single element in numba njit method
<p>I'm trying to use numba's njit decorator to optimize a method. I'm getting an error that seems to be caused by defining a set with multiple elements, then overwriting it with a set with a single element (or vice versa). I'm running python 3.10.12, numba version 0.60.0.</p> <p>The following minimal example reproduces...
<python><numba>
2024-08-17 11:41:15
1
2,816
bjarkemoensted
78,882,013
1,785,063
Errors while trying to install matplotlib
<p>I am not python expert and this project used to work but now giving me massive red errors while trying to build the project:</p> <p><code>pip2 install -r requirements.txt --no-cache-dir</code></p> <p>Can somebody help me to figure out how to fix it. It seems the issue related to <code>matplotlib</code> and <code>num...
<python><matplotlib><macos-sonoma>
2024-08-17 10:47:26
1
347
Duaa Zahi
78,881,895
315,168
Using short (native) tracebacks in Jupyter Notebooks
<p>Currently Jupyter Notebook, as run in Visual Studio Code, uses its verbose traceback output, outputting code samples where the exception propagated. This is the opposite of Python native traceback that only gives you the file and line number.</p> <p>Example snippet:</p> <pre><code>UnboundLocalError ...
<python><jupyter-notebook>
2024-08-17 09:50:25
0
84,872
Mikko Ohtamaa
78,881,845
874,380
How to open a Github folder in Google Colab?
<p>I have a GitHub repository with the following general structure</p> <pre><code>repository/ -- topic1/ -- topic2/ -- topic3/ ---- data/ ---- src/ ------ notebook3.1.ipynb ------ notebook3.2.ipynb ------ notebook3.3.ipynb -- topic4/ -- topic5/ ... </code></pre> <p>The notebooks belonging to the same notebook may acces...
<python><github><jupyter-notebook><google-colaboratory>
2024-08-17 09:21:48
0
3,423
Christian
78,881,781
315,427
How to determine model changes?
<p>My <code>QListView</code> class is feed by <code>QAbstractListModel</code>, where I've implemented insert, remove, update rows. There is no problem between model and list view. However, I would like to subscribe to model change to do some custom calculations.</p> <p>For that I can't find any events neither in QListV...
<python><pyqt><pyqt6>
2024-08-17 08:50:41
1
29,709
Pablo
78,881,333
865,220
Group by and transform the value each group with its median
<p>I have a Pandas dataframe with data like this:</p> <pre><code>Name,Year,Value ---------------- Wendys,2021,6915 Wendys,2021,6916 Wendys,2022,6943 Wendys,2022,7016 Wendys,2022,7026 Wendys,2022,7028 Wendys,2023,7055 Wendys,2023,7128 Wendys,2023,7129 Wendys,2023,7138 Wendys,2023,7140 Wendys,2024,7166 White Castle,1950,...
<python><pandas><dataframe>
2024-08-17 03:43:35
1
18,382
ishandutta2007
78,881,240
5,003,606
Decimal shift behaves bizarrely if constructed from float
<p>Consider the following Python code:</p> <pre class="lang-py prettyprint-override"><code>from decimal import Decimal d = Decimal(&quot;1.23&quot;) print(f&quot;{d = }, {d.shift(1) = }&quot;) </code></pre> <p>When I execute it in Python 3.12.4, I get this output:</p> <pre class="lang-none prettyprint-override"><code>...
<python><floating-point><decimal><shift>
2024-08-17 02:02:30
1
951
HaroldFinch
78,881,135
1,189,239
Why does my Bayesian linear regression with survival analysis perform worse than standard linear regression?
<p>Experts in statistics wanted here.</p> <p>I am working on a Bayesian linear regression function that considers asymmetric uncertainties and censored data (upper/lower limits) in both x and y. The function uses the emcee MCMC package to estimate the posterior distributions of the slope and intercept. Despite taking i...
<python><statistics><linear-regression><bayesian><mcmc>
2024-08-16 23:59:33
0
933
Alessandro Peca
78,881,092
3,997,163
Unable to connect DB2 Database with Python in Visual Studio
<p>I have installed Python 3.12.5 and Visual studio in Windows. I have followed the steps mentioned in the link <a href="https://github.com/ibmdb/python-ibmdb/blob/master/INSTALL.md" rel="nofollow noreferrer">https://github.com/ibmdb/python-ibmdb/blob/master/INSTALL.md</a> (Step 1) . Executed the below command,</p> <pr...
<python><visual-studio><db2>
2024-08-16 23:27:53
1
407
max092012
78,880,980
19,672,778
Why doesn't Marching Square Visualization In Pygame draws nothing?
<p>so i wanted to draw implicit equation of heart in pygame via using the marching squares algorithm in it. i implemented the marching square's algorithm but it doesn't work? can anyone help me out why?</p> <pre class="lang-py prettyprint-override"><code>import pygame w = 500 h = 500 grid = [] for i in range(-h//2, ...
<python><pygame>
2024-08-16 22:17:33
1
319
NikoMolecule
78,880,945
5,563,584
weighted sum on multiple dataframes
<p>I have several dataframes with an ID, a time of day, and a number. I would like to weight each dataframe number and then sum them for each id/time of day. As an example:</p> <pre><code>weighted 0.2 ID TOD M 0 10 morning 1 1 13 afternoon 3 2 32 evening 2 3 10 evening 2...
<python><pandas><dataframe><weighted>
2024-08-16 21:56:08
1
327
greenteam
78,880,829
1,809,530
Selecting interpreter in VS Code does not activate environment
<p>I am working with a conda environment that contains multiple packages, and I am trying to debug a Python script that calls those packages via shell commands. While selecting interpreter via VS Code uses that environment's packages, it does not allow me to use the packages installed directly via conda.</p> <p>Take th...
<python><visual-studio-code><conda>
2024-08-16 20:58:28
1
11,824
tktk
78,880,721
4,177,781
Iterate over groups created using group_by on date column
<p><strong>Update:</strong> This was fixed by <a href="https://github.com/pola-rs/polars/pull/18251" rel="nofollow noreferrer">pull/18251</a></p> <hr /> <p>I am new to Polars. I want to iterate over the groups created by grouping over the column where each cell of that column contains a list of two dates. I used the fo...
<python><datetime><python-polars>
2024-08-16 20:19:45
1
352
arman
78,880,486
6,118,556
How to change the state of a ttkbootstrap ScrolledText widget after creation?
<h3>Problem</h3> <p>I'm trying to change the state of a <code>ScrolledText</code> <em>ttkboostrap</em> widget after creation. I can set its state as I please when I create it, but trying to change it after creation fails for both examples below with error message: <code>_tkinter.TclError: unknown option &quot;-state&qu...
<python><tkinter><state><ttk><ttkbootstrap>
2024-08-16 18:55:05
1
1,136
pfabri
78,880,464
1,993,414
Plot sequence of colors in 1-d using associated x-values and labels by x-value and color value (Matplotlib)
<h1>Update</h1> <p><a href="https://stackoverflow.com/questions/78880464/plot-sequence-of-colors-in-1-d-using-associated-x-values-and-labels-by-x-value-a">This question</a> provided a different method which did more accurately display the color values but I still have x-value and label issues.</p> <pre><code>cmap_ = Li...
<python><matplotlib><colormap>
2024-08-16 18:48:38
2
389
XonAether
78,880,325
11,233,365
Perform an SQL 'database.exec()' search in a function not under a FastAPI decorator
<p>I am trying to streamline a FastAPI endpoint being developed by my team, in which we are repeatedly registering items to an SQL database if they don't already exist in it.</p> <p>The session was defined in one file as follows:</p> <pre class="lang-py prettyprint-override"><code>from functools import partial from sq...
<python><fastapi><sqlmodel>
2024-08-16 18:01:20
1
301
TheEponymousProgrammer
78,880,068
6,168,231
How to portably write stdout as if piped through `less`?
<p>I'm working on a Python project which is supposed to spit out output onto stdout. In some cases, the output can be quite long. In such situations, I'd like it if the output wasn't just dumped onto screen, but would behave as if piped into <code>less</code>, i.e. hold the position at the start of the output and allow...
<python><windows><stdout>
2024-08-16 16:35:23
0
562
mivkov
78,879,801
1,439,122
gdown command not working in jupyter notebook in anaconda.cloud
<p>I am using Jupyter notebook on anaconda.cloud with kernel <code>anaconda-2024.02-py310.</code></p> <p>When I execute the following in a cell:</p> <pre><code>!pip install gdown !gdown 1on54WRa6RCAQwrlpE2mABChNs4mNO2fd </code></pre> <p>It throws the following error:</p> <pre><code>Defaulting to user installation becau...
<python><jupyter-notebook><anaconda><gdown>
2024-08-16 15:18:11
2
2,721
RRM
78,879,781
9,571,463
How to get same results from base64 atob in Javascript vs Python
<p>I found some code online that I am trying to work through which encodes to base64. I know Python has <code>base64.urlsafe_b64decode()</code> but I would like to learn a bit more about what is going on.</p> <p>The JS <code>atob</code> looks like:</p> <pre><code>function atob (input) { var chars = 'ABCDEFGHIJKLMNOPQ...
<javascript><python><base64><base64url>
2024-08-16 15:12:50
2
1,767
Coldchain9
78,879,657
8,667,016
Selecting rows that compose largest group (within another group) in a pandas DataFrame
<h2>Main problem</h2> <p>I'm trying to find a way to select the rows that make up the largest sub-group inside another group in a Pandas DataFrame and I'm having a bit of a hard time.</p> <h3>Visual example (code below)</h3> <p>Here is a sample dataset to help explain exactly what it is I'm trying to do. There is code ...
<python><pandas><dataframe>
2024-08-16 14:42:08
1
1,291
Felipe D.
78,879,558
200,663
Update airflow config without restarting scheduler with LocalExecutor
<p>I have a bunch of tasks running and want to update airflow.cfg to enable more tasks to run simultaneously. My understanding is that I need to restart the scheduler for these updates to take place. However, when I try to restart the scheduler, I get this warning:</p> <blockquote> <p>INFO - Shutting down LocalExecutor...
<python><airflow><config>
2024-08-16 14:18:00
1
1,450
Tim
78,879,249
7,941,309
sympy matrix scientific notation
<p>I'm trying to display a sympy matrix in scientific notation, and it is only working for values less than 1. I can't understand why <a href="https://github.com/sympy/sympy/blob/2197797741156d9cb73a8d1462f7985598e9b1a9/sympy/matrices/matrixbase.py#L2089-L2110" rel="nofollow noreferrer"><code>applyfunc</code></a> is be...
<python><sympy>
2024-08-16 12:58:46
2
353
Erik Iverson
78,879,247
445,810
Ignoring "undefined symbol" errors in ctypes library load
<p>I'm loading a not-owned-by-me library with Python's <code>ctypes</code> module as <code>ctypes.CDLL(&quot;libthirdparty.so&quot;)</code> which produces an error <code>undefined symbol: g_main_context_push_thread_default</code> because <code>libthirdparty.so</code> was overlinking a lot of unneeded / unused stuff lik...
<python><ctypes><ld-preload>
2024-08-16 12:57:56
1
1,164
Vadim Kantorov
78,879,232
16,725,431
tkinter auto joining thread
<p>I am writing a tkinter app and is using threads for performance (computing-intensive tasks)</p> <p>Threads need to be joined, but I am lazy.</p> <p>I don't really like the idea of constantly checking if a thread is alive.</p> <p>I created a class to handle join automatically when the job is done. However, it still h...
<python><multithreading><tkinter>
2024-08-16 12:53:05
1
444
Electron X
78,879,448
11,233,365
Validating file paths to satisfy GitHub CodeQL's "Uncontrolled data used in path expression" alert
<p>I'm writing functions for a Python package to register files from a file system to an SQL database, and GitHub's CodeQL has flagged that the file paths are a potential security risk.</p> <p>I have constructed a basic validator to make sure that only file paths that exist and start with a given base path when resolve...
<python><codeql><file-inclusion>
2024-08-16 12:49:08
1
301
TheEponymousProgrammer
78,878,639
1,489,009
Pymongo: create_collection error after updating python to 3.12.5
<p>I'm using Mongo db from Python.</p> <p>Creating collections using this code:</p> <pre><code>self.client = MongoClient(MONGODB_CONNECT) self.db = self.client[MONGODB_NAME] self.db.create_collection(collection_name, options) </code></pre> <p>Where option is a dictionary like:</p> <pre><code>option = { &quot;timese...
<python><pymongo><python-3.12>
2024-08-16 10:09:37
1
4,836
Guian
78,878,468
3,767,239
What is the rationale behind `TransformedTargetRegressor` always cloning the given `regressor` and how to prevent this behavior?
<p>The docs of <a href="https://scikit-learn.org/stable/modules/generated/sklearn.compose.TransformedTargetRegressor.html" rel="nofollow noreferrer"><code>sklearn.compose.TransformedTargetRegressor</code></a> state that:</p> <blockquote> <p><strong>regressor object, default=None</strong></p> <p>Regressor object such as...
<python><scikit-learn>
2024-08-16 09:28:48
2
36,629
a_guest
78,878,466
3,732,793
relative import for class fails
<p>not sure why I always struggle with relative imports...</p> <p>usually I have this structure</p> <pre><code>- project - package1 some.py - package2 - tests tests_package1.py </code></pre> <p>where tests_package1.py starts with</p> <pre><code>from ..packe1.some import some </code></pre> <p>however I ...
<python>
2024-08-16 09:28:17
2
1,990
user3732793
78,878,331
15,358,800
Numpy: UFuncBinaryResolutionError: ufunc 'add' cannot use operands with types dtype('<M8[D]') and dtype('<M8[D]')
<p>One of my function generates list of dates in <code>numpy</code> array like so and iam just trying to apply median function on results...Finding median in such arrays is invalid or Iam missing something??</p> <p><strong>Reproducable</strong></p> <pre><code>import numpy as np dt_array = np.array([np.datetime64('2024-...
<python><numpy>
2024-08-16 08:51:01
2
4,891
Bhargav
78,878,107
4,508,605
How to add file name pattern in AWS Glue ETL job python script
<p>I wanted to add file name pattern in <code>AWS Glue ETL</code> job python script where it should generate the files in s3 bucket with pattern <code>dostrp*.csv.gz</code> but could not find way how to provide this file pattern in python script :</p> <pre><code>import sys from awsglue.transforms import * from awsglue....
<python><amazon-s3><aws-glue><filepattern>
2024-08-16 07:44:27
1
4,021
Marcus
78,878,048
26,843,912
Shaky zoom with opencv python
<p>I want to apply zoom in and out effect on a video using opencv, but as opencv doesn't come with built in zoom, I try cropping the frame to the interpolated value's width, height, x and y and than resize back the frame to the original video size, i.e. 1920 x 1080.</p> <p>But when I rendered the final video, there is ...
<python><opencv><image-processing><video-processing>
2024-08-16 07:33:21
1
323
Zaid
78,877,805
219,153
Calculating an average of multiple polygons
<p>I would like to &quot;average&quot; several polygons having a substantial intersection, e.g. these three:</p> <p><a href="https://i.sstatic.net/vT84Twro.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vT84Twro.png" alt="enter image description here" /></a></p> <p>Preferably using a Python library, e.g...
<python><computational-geometry><shapely>
2024-08-16 06:11:32
4
8,585
Paul Jurczak
78,877,560
5,565,100
liboqs-python throws AttributeError: module 'oqs' has no attribute 'get_enabled_kem_mechanisms'
<p>I'm trying to get this Open Quantum Safe example working: <a href="https://github.com/open-quantum-safe/liboqs-python/blob/main/examples/kem.py" rel="nofollow noreferrer">https://github.com/open-quantum-safe/liboqs-python/blob/main/examples/kem.py</a></p> <p>I'm getting this error:</p> <pre class="lang-none prettypr...
<python><post-quantum-cryptography>
2024-08-16 03:53:06
1
2,371
Emily
78,877,520
11,627,201
gspread exceeded api call quota even though I only run it once per minute?
<p>I am using google drive with google colab. Here is the code (basically, login to google drive, read a spreadsheet with some data, process that data, and write it to another spread sheet)</p> <pre><code>from google.colab import drive drive.mount('/content/drive') import gspread from google.colab import auth auth.auth...
<python><google-cloud-platform><google-colaboratory><google-sheets-api><gspread>
2024-08-16 03:22:19
0
798
qwerty_99
78,877,335
6,743,618
SQLAlchemy: multiple one-to-many relationships between the same 2 models
<p>This is a simplified version of my models. Say I have a User model with many billing addresses and many shipping addresses. Both correspond to the Address model.</p> <pre class="lang-py prettyprint-override"><code>from sqlalchemy import ForeignKey from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, re...
<python><sqlalchemy><orm>
2024-08-16 01:13:51
0
895
Javier López
78,877,314
14,761,117
NotNullViolation Error When Inserting Data into PostgreSQL Table with Non-Nullable ID Column
<p>I'm working on inserting data from a Pandas DataFrame into a PostgreSQL table using Python. The table structure is as follows:</p> <pre class="lang-sql prettyprint-override"><code>CREATE TABLE sales ( id BIGINT NOT NULL, -- Primary Key tahun INTEGER NOT NULL, bulan NUMERIC NOT NULL, v_kod VARCHAR(10...
<python><database><postgresql><auto-increment>
2024-08-16 00:56:51
1
331
AmaniAli
78,877,275
16,725,431
Python class mimic makefile dependency
<p><strong>Q: Is there a better way to do this, or the idea itself is wrong</strong></p> <p>I have a processing class that creates something with multiple construction steps, such that the next function depends on the previous ones.</p> <p>I want to have dependencies specified like those in a <code>makefile</code>, and...
<python><python-3.x><makefile><python-decorators>
2024-08-16 00:29:29
1
444
Electron X
78,877,239
3,022,254
Pytorch MemoryMappedTensors causing Bus Error, possibly insufficient memory
<p>I'm loading some data using PyTorch's MemoryMappedTensor (version==2.4.0+cu118) and getting a Bus Error. I'm running the code using WSL2 on Windows 10:</p> <blockquote> <pre><code> Operating System: Windows 10 Pro 64-bit (10.0, Build 19045) (19041.vb_release.191206-1406) Language: English (Regional ...
<python><pytorch><memory-mapped-files><bus-error>
2024-08-16 00:10:47
0
1,372
Mackie Messer
78,876,815
2,171,348
FastAPI - Pydantic model does not allow space in value of string Enum value?
<pre><code>python 3.12.5 pydantic 2.8.2 fastapi 0.111.1 </code></pre> <p>Running in a docker container on WSL2 Ubuntu 22.04 LTS.</p> <p>Here is the model class definition:</p> <pre class="lang-py prettyprint-override"><code>from enum import Enum from app.models.common.base import DomainModel class ProjectState(s...
<python><enums><fastapi><pydantic>
2024-08-15 20:57:33
1
481
H.Sheng
78,876,658
7,577,930
Strange timing and order of prints to log
<p>I ran the following program through a Slurm job:</p> <pre class="lang-python prettyprint-override"><code>import datetime print(f'Program started at {datetime.datetime.now()}.') # More imports here. print(f'Modules finished loading at {datetime.datetime.now()}.') seed_everything(7253, workers=True) </code></pre> ...
<python><logging><slurm><pytorch-lightning>
2024-08-15 19:54:49
1
346
Moon
78,876,255
8,537,770
mypy function signature matching for **kwargs argument and different kinds of return types
<p>I have a class that I am trying to make as an interface. For simplicity, I've only included one of the abstract methods (see below).</p> <pre class="lang-py prettyprint-override"><code>class MyInterface(metaclass=abc.ABCMeta): @classmethod def __subclasshook__(cls, subclass): return (hasattr(subclass...
<python><python-typing><mypy>
2024-08-15 17:38:03
0
663
A Simple Programmer
78,876,137
610,569
How to disable string processing in wikipedia-1.4.0 API?
<p>When using the <a href="https://pypi.org/project/wikipedia/" rel="nofollow noreferrer">https://pypi.org/project/wikipedia/</a> API, <code>wikipedia==1.4.0</code>, it seems that when accessing the page, the library would first do some string processing to alter the inputs, e.g.</p> <pre><code>import wikipedia wikiped...
<python><wikipedia><wikipedia-api>
2024-08-15 17:02:06
1
123,325
alvas
78,876,123
2,808,020
GitHub file search by name results differ from web when using API or pyGitHub
<p>I have a large git repo with multiple .Net solutions in it (in the example repo there is only one). I want to return the paths of all the <code>Directory.Packages.props</code> files within that specific repo. I am trying to use the code below:</p> <pre><code>from github import Github token = '&lt;my token&gt;' # C...
<python><github-api><pygithub>
2024-08-15 16:57:55
1
704
AC4
78,875,978
5,287,011
Error using LlmFactory with "TheBloke/OpenHermes-2.5-Mistral-7B-GGUF" Huggingface
<p>I tried replicating a simple Python code to create a small LLM model.</p> <p>I have macOS M1 machine. I created a separate environment where I installed Pytorch and llama-cpp-python. The code:</p> <pre><code>from llmflex import LlmFactory # Load the model from Huggingface try: # Instantiate the model with the c...
<python><pytorch><metal><large-language-model><huggingface>
2024-08-15 16:11:45
1
3,209
Toly
78,875,935
5,738,150
Aligning a 3D face mesh to face the camera
<p>I'm working on aligning a 3D face mesh using PyVista for visualization. My goal is to position the nose tip at the origin (0, 0, 0) and ensure that the eyes are aligned along the Y-axis so that the face is directly facing the camera. Here's what I'm aiming to achieve:</p> <p>I have already extracted the nose tip, le...
<python><geometry><spatial><vtk><pyvista>
2024-08-15 16:00:59
1
728
colt.exe
78,875,922
3,327,344
How to read and input data into a table graph in an template word file using python docx
<p>I have a docx file with table graph which can not recognized by doc.tables. Here is the file: <a href="https://github.com/python-openxml/python-docx/files/1867861/non_readable_table.docx" rel="nofollow noreferrer">https://github.com/python-openxml/python-docx/files/1867861/non_readable_table.docx</a></p> <p>Same iss...
<python><ms-word><python-docx>
2024-08-15 15:58:35
1
509
xie186
78,875,846
11,065,874
how to maintain the order of logs when using python's subprocess to call other processes
<p>I have <code>a.sh</code> as below</p> <pre><code>#!/bin/bash echo 100 python3 b.py if [ $? -ne 0 ]; then exit 1 fi echo &quot;this will not be printed&quot; </code></pre> <p>and <code>b.py</code> as below</p> <pre><code>import subprocess print(&quot;101&quot;) result = subprocess.run([&quot;bash&quot;, &quot;...
<python><linux><subprocess>
2024-08-15 15:38:55
1
2,555
Amin Ba
78,875,771
4,247,599
python `(datetime.datetime.now() - datetime.datetime.now()).seconds` does not return 0 seconds
<p>I'm working with python 3.12.4 and using the standard library datetime.</p> <p>I am expecting the difference between two datetime.now to be zero. Instead I get a number like <code>86399</code>.</p> <pre><code>import datetime print((datetime.datetime.now() - datetime.datetime.now()).seconds) # returns 86399 </code>...
<python><datetime>
2024-08-15 15:19:26
1
4,299
SeF
78,875,770
6,597,296
How to use startTLS in Twisted?
<p>I want to establish a non-encrypted connection to a server and then, upon sending an agreed-upon command, to switch to a TLS-encrpted connection. It seems that Twisted's <code>startTLS</code> is meant exactly for this purpose - except I can't make it to work, not even the very examples given in Twisted's <a href="ht...
<python><twisted>
2024-08-15 15:19:17
1
578
bontchev
78,875,714
13,088,678
Non Spark code (Plain Python) run on Spark cluster
<p>As per the doc (<a href="https://docs.databricks.com/en/optimizations/spark-ui-guide/spark-job-gaps.html" rel="nofollow noreferrer">https://docs.databricks.com/en/optimizations/spark-ui-guide/spark-job-gaps.html</a>), Any execution of code that is not Spark will show up in the timeline as gaps.For example, <code>yo...
<python><apache-spark><databricks>
2024-08-15 15:04:32
1
407
Matthew
78,875,711
1,277,239
Concatenate matrices and vectors in Python
<p>I am a MATLAB user, and trying to convert a rotation/translation code into Python:</p> <pre><code>from functools import reduce import numpy as np import matplotlib as plt from math import pi as PI from math import sin as sin from math import cos as cos # plt.close('all') # coordinate in old system x0 = np.arr...
<python><matrix>
2024-08-15 15:03:32
1
2,912
Nick X Tsui
78,875,646
4,913,254
When adding planes to my 3D scatter plot, one plane is not shown (Plotly)
<p>I am creating three plots in one HTML file. The third plot is a 3D scatter plot in which I want to add two planes. For a reason the same approach add the second plane but not the first. I though that the second plane overwrite the first but this is not the case.</p> <p>This is the whole script of my script</p> <pre>...
<python><3d><plotly>
2024-08-15 14:49:25
0
1,393
Manolo Dominguez Becerra
78,875,567
19,838,568
Using default_namespace argument of ElementTree.tostring throws error
<p>I want to use ElementTree to modify an XML-document and to keep it comparable, I want to have the same namespace-prefixes in the new file as in the old file.</p> <p>However, the <code>default_namespace=</code> argument of <code>ET.tostring</code> and <code>ET.write</code> causes errors with even simple documents.</p...
<python><xml><elementtree>
2024-08-15 14:27:44
1
2,406
treuss
78,875,554
1,384,464
Configuring Django and MinIO using HTTPS on same server
<p>I have set up MinIO as my Django app object storage and integrate the functionality of this module on my the same server. I followed the instruction in <code>django-minio-backend</code>, but I got the below error.</p> <pre><code>urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='subdomain.domain.org', port=...
<python><django><ubuntu><ssl><minio>
2024-08-15 14:24:41
1
1,033
Timothy Tuti
78,875,297
4,451,315
"horizontal sum" in DuckDB?
<p>In Polars I can do:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame({'a': [1,2,3], 'b': [4, 5, 6]}) df.select(pl.sum_horizontal('a', 'b')) shape: (3, 1) ┌─────┐ │ a │ │ --- │ │ i64 │ ╞═════╡ │ 5 │ │ 7 │ │ 9 │ └─────┘ </code></pre> <p>Is there a way to do this with D...
<python><python-polars><duckdb>
2024-08-15 13:23:35
2
11,062
ignoring_gravity
78,875,237
4,520,520
Disable Django admin buttons after click
<p>Is there any easy way in Django change forms to disable buttons after submit. I want to prevent users from submitting the form twice at the same instant!</p>
<python><python-3.x><django><django-forms>
2024-08-15 13:04:23
3
2,218
mohammad
78,875,181
9,897,331
How to optimise parallelisation of nested numba loops
<p>I'm having issues figuring out how to optimise the parallelisation of nested loops with numba. As a basic example I've written a 2D convolution algorithm which relies on multiple nested loops. Obviously there are better options for calculating a 2D convolution, this is just for illustration. As you can see in the co...
<python><for-loop><parallel-processing><numba>
2024-08-15 12:52:59
1
365
Felipe Moser
78,875,128
9,343,043
How to merge dictionary of dataframes and make key values a column in merged dataframe
<p>I have a dictionary of about 600 dataframes for connectome metrics for those 600 participants. I'm making a dummy dictionary though for conciseness. The dataframes all have 1 row. Ignore the fact that the actual meaning of &quot;mean&quot; as the column names are not what is of the row samples I give below, they're ...
<python><pandas><dataframe><dictionary>
2024-08-15 12:38:55
1
871
florence-y
78,875,000
4,265,257
How to highlight traces on legend hover events
<p>I'm plotting lines from variable data, the items can sometimes have identical data points so need a way to see which lines are stacked. I'd like to implement something similar to the mplcursors highlight feature which highlights figures as you hover them in the legend.</p> <p>In Seaborn using dodge on a catplot work...
<python><plotly>
2024-08-15 12:06:45
0
349
Arno
78,874,855
736,662
how to represent null and true i json payload Python
<p>I have a payload in my request against an endpoint having values null and true. In Pycharm I get red-dotted line below the two respectively. How can I &quot;define null and true inside my json payloads setmethod in Python?</p> <pre><code>def setpayload_set(): myjson = { &quot;hpsId&quot;: 10034, &quot;powerP...
<python><json>
2024-08-15 11:21:15
1
1,003
Magnus Jensen
78,874,845
5,618,856
Pandas read_sql with SQLAlchemy from Oracle Database with many parameters
<p>I have a working setup to read sql data into a pandas dataframe:</p> <pre class="lang-py prettyprint-override"><code>connect_string = f&quot;DSN={config.DB};UID={credentials['UID']};PWD={credentials['pwd']};DBQ={config.DB_server};DBA=W;APA=T;EXC=F;FEN=T;QTO=F;FRC=10;FDL=10;LOB=T;BTD=F;BNF=F;TABLE={config.table}&quot...
<python><pandas><oracle-database><sqlalchemy><python-oracledb>
2024-08-15 11:18:20
2
603
Fred
78,874,712
1,860,314
What could even be an error when loading a pickled file in Python?
<p>The pickled file is <a href="https://github.com/sjy1203/GAMENet/blob/master/data/voc_final.pkl" rel="nofollow noreferrer">voc_final.pkl</a>, in the source code used in the paper <a href="https://arxiv.org/abs/1809.01852" rel="nofollow noreferrer">GAMENet</a>.</p> <p>I tried to load it:</p> <pre><code>import dill voc...
<python><serialization><deserialization><pickle><dill>
2024-08-15 10:43:09
1
1,077
JoyfulPanda
78,874,684
16,869,946
Python scipy quad and nqaud giving different answers
<p>I am not sure if this is more suitable for math stackexchange or stack overflow, but since the mathematical proofs look alright to me, I suspect its the code that's the issue and hence I will post it here:</p> <p><a href="https://i.sstatic.net/19KiGQj3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1...
<python><scipy><probability><scipy.stats><quad>
2024-08-15 10:33:15
2
592
Ishigami
78,874,506
5,758,423
How can I avoid interface repetition in Python function signatures and docstrings?
<p>I'm looking for a standard, lightweight (preferably built-in) way to handle the problem of <strong>interface repetition</strong>—where the same parameters (with annotations, defaults, and docs) are repeated across multiple functions that share common functionality. Is there a way to centralize the parameter definiti...
<python><dry>
2024-08-15 09:41:26
1
2,432
thorwhalen
78,874,499
3,972,291
Influxdb: store data into influxdb from oracle database using apache airflow
<p>I am using Apache airflow for storing data in influxdb from oracle database. I need to store all data from oracle database into influxdb. But it insert last row of data only each company_id. Other data not insert. Here is oracle data set:</p> <p><a href="https://i.sstatic.net/O99n2Q71.jpg" rel="nofollow noreferrer">...
<python><airflow><influxdb>
2024-08-15 09:40:05
1
5,095
Enamul Haque
78,874,155
508,236
How to create a single CSV file with specified file name Spark in Databricks?
<p>I know how to use Spark in Databricks to create a CSV, but it always has lots of side effects.</p> <p>For example, here is my code:</p> <pre class="lang-py prettyprint-override"><code>file_path = “dbfs:/mnt/target_folder/file.csv” df.write.mode(&quot;overwrite&quot;).csv(file_path, header=True) </code></pre> <p>Then...
<python><csv><apache-spark><databricks>
2024-08-15 08:00:20
1
15,698
hh54188
78,874,114
14,808,637
Visualizing multiple graphs in a single figure while conserving space and maintaining clarity
<p>I'm visualizing a graph using the given code, where each pair of nodes connected by a comma represents an edge, and the numeric value represents the intensity of that edge. Here is the code for a graph:</p> <pre><code>import matplotlib.pyplot as plt import networkx as nx import os import matplotlib.colors as mcolors...
<python><matplotlib><networkx>
2024-08-15 07:46:21
2
774
Ahmad
78,873,745
14,808,637
Visualization of Weighted Graph with NetworkX and Matplotlib: Addressing Node Overlapping Issue
<p>I am visualizing a graph where each pair of nodes connected by a comma represents an edge, and the numeric value represents the intensity of that edge. Here is the code:</p> <pre><code>import matplotlib.pyplot as plt import networkx as nx data = { ('A', 'B'): 0.71, ('M', 'B'): 0.67, ('N'...
<python><matplotlib><networkx>
2024-08-15 05:28:19
0
774
Ahmad
78,873,680
4,609,089
How to create a function call tool to analyse CSV in LLM Long-chain with all columns definition predefined
<p><em><strong>Context</strong></em></p> <p>I would like to create an GPT Agent. This Agent should be able to fetch data from 3 predefined CSV files. Hence I would like to create 3 function tools for each CSV file.</p> <p><em><strong>Expectation</strong></em></p> <p>AI Agent should understand what does each CSV do exac...
<python><openai-api><langchain><large-language-model><gpt-4>
2024-08-15 04:55:11
0
833
John
78,873,598
143,397
How to wrap a PyDict in PyO3 with a constructor that takes a new parameter?
<p>I am using PyO3 (v0.22.2) / Rust to write something a little similar to <code>defaultdict</code>, but with an integer default rather than a callback:</p> <pre><code>&gt;&gt;&gt; from my_package.pyo3_ext import PyDefaultDict &gt;&gt;&gt; d = PyDefaultDict(42, a=1, b=2) &gt;&gt;&gt; d['a'] 1 &gt;&gt;&gt; d['z'] 42 ...
<python><inheritance><rust><python-extensions><pyo3>
2024-08-15 04:01:51
0
13,932
davidA
78,873,362
20,295,949
Optimize Python Web Scraping Script Using concurrent.futures to Reduce Execution Time
<p>I'm currently working on a web scraping script in Python that extracts table data from multiple pages of a website using urllib, BeautifulSoup, and pandas. The script is designed to handle content encoding like gzip and brotli, and it retries on certain HTTP errors such as 429 (Too Many Requests) with exponential ba...
<python><web-scraping><beautifulsoup><python-requests><multiprocessing>
2024-08-15 01:24:13
1
319
HamidBee
78,873,304
1,601,580
How to sample multiple completions (n) directly from Claude API without a for loop
<p>I'm using the Anthropic Claude API and I'm trying to generate multiple completions (n completions) for a given prompt in a single API call. OpenAI's API provides an n parameter in their sampling settings to achieve this, but I can't find an equivalent option in the Claude API.</p> <h3>My Current Approach:</h3> <p>I'...
<python><machine-learning><nlp><large-language-model><claude>
2024-08-15 00:37:53
0
6,126
Charlie Parker