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
⌀
77,290,072
284,932
How to use transformers.Trainer on Windows without conda?
<p>I am trying to use the Trainer class from transformers module on Windows 10, python 3.10 and CUDA 12.1 and <em>all modules installed using</em> <strong>pip</strong>.</p> <p>nvcc --version :</p> <pre><code>nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2023 NVIDIA Corporation Built on Wed_Feb__8_05:53:42_Co...
<python><huggingface-transformers><huggingface-trainer>
2023-10-13 18:52:49
0
474
celsowm
77,290,012
1,925,652
How can pip install packages which are missing from it's index?
<p>According to Chris' answer (most upvotes) to <a href="https://stackoverflow.com/questions/4888027/python-and-pip-list-all-versions-of-a-package-thats-available/26664162#26664162">this question</a>, <code>pip index versions package_name</code> is a reliable way to find the versions available for a given package.</p> ...
<python><tensorflow><pip>
2023-10-13 18:38:23
1
521
profPlum
77,290,003
5,246,617
Segmentation Fault when Using SentenceTransformer Inside Docker Container
<p>Edit: After test on different machines it is Apple M1 M2 specific bug.</p> <p>I am trying to run a Flask application inside a Docker container on Apple Silicon M2 (could be an issue), where I use the SentenceTransformer model to encode sentences. However, when I call the encode method on the model, the application c...
<python><docker><apple-m1><sentence-transformers>
2023-10-13 18:36:32
4
1,093
Pavol Travnik
77,289,982
13,227,516
Python asyncssh equivalent of paramiko Channel to display SSH prompt
<p>I'm trying to establish an interactive SSH shell using asyncssh. So far I have the following code:</p> <pre><code>import asyncio, asyncssh, sys async def run_client(): async with asyncssh.connect( HOST, port=PORT, username=USER, password=PASSWORD, known_hosts=None) as conn: stdi...
<python><asyncssh>
2023-10-13 18:31:46
1
315
johnc
77,289,653
11,922,765
Combine two lists alternatively
<p>I am doing a simple list comprehension: combine two lists in alternative order and make another list.</p> <pre><code>big_list = [i,j for i,j in zip(['2022-01-01','2022-02-01'],['2022-01-31','2022-02-28'])] </code></pre> <p>Expected output:</p> <pre><code>['2022-01-01','2022-01-31','2022-02-01','2022-02-28'] </code><...
<python><python-3.x><list><list-comprehension><python-zip>
2023-10-13 17:27:12
5
4,702
Mainland
77,289,577
2,612,592
Can't run test due to ImportError
<p>I have the following project structure:</p> <pre><code>| .gitignore | README.md | call_test_outside.py | main.py | setup.cfg | setup.py |- src |- PropTools | __init__.py | PropTools | __init__.py | SQLiteWrapper.py | dates.py | prices.py |- transactions...
<python><python-packaging>
2023-10-13 17:09:37
2
587
Oliver Mohr Bonometti
77,289,480
10,642,196
Why does the PyAV-encoded video have a different total time in seconds than the original file
<p>I'm taking a mp4 file, decoding it frame by frame and reencoding it. I'm using PyAV and the reencoding is running on h265. When the code is running, it seems that all frames are passed from the decoder to the encoder, but at the end I have a file with 3 seconds less. For longer videos I'll have bigger differences.</...
<python><video><ffmpeg><pyav>
2023-10-13 16:54:02
0
595
Diego Medeiros
77,289,175
3,050,730
Why am I getting a Pylance error "Object of type 'A*' is not callable" in VSCode when using generics?
<p>I'm attempting to write a generic class in Python 3.11 that should be able to process a list of elements using different processing classes (<code>A</code> or <code>B</code> in this example). My goal is to use the type variable <code>T</code> to specify the processing class that should be used.</p> <p><strong>Clarif...
<python><generics><python-typing><pyright>
2023-10-13 15:58:50
2
523
nicrie
77,289,083
5,213,015
Django - AllAuth How to style the email.html template?
<p>Quick question.</p> <p>I'm beefing up the authentication for my Django application. I would like to have users change and verify their emails with Allauth but I can't figure out how to style a template.</p> <p>Is there a way how we can style the <code>email.html</code> template?</p> <p>I tried to add <code>{{ form.a...
<python><django><django-views><django-allauth>
2023-10-13 15:45:10
1
419
spidey677
77,289,011
21,420,742
How to make a date filter using column from one dataframe to another
<p>I have two datasets that I need to create a filter looking at 90 days back in df1 from the <code>target_date</code> in df2.</p> <p>Example:</p> <p>DF1</p> <pre><code> id name start_date end_date team 1234 John Smith 1/1/2022 2/1/2022 Sales 1234 John Smith 2/1/2022 4...
<python><pandas><dataframe><loops><datetime>
2023-10-13 15:32:15
0
473
Coding_Nubie
77,288,976
1,422,096
How to export a private key / public key into bytes with Python cryptography module?
<p>I tried many combinations of parameters of <a href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.private_bytes" rel="nofollow noreferrer"><code>rsa.RSAPrivateKey.private_bytes</code></a> but none of them work:</p> <pre><code>from cryp...
<python><cryptography><rsa><python-cryptography>
2023-10-13 15:27:15
0
47,388
Basj
77,288,951
6,125,803
pipenv install and lock fails every time - on new install of Mac OS Ventura
<p>I'm trying to set up a new environment and Ive run into an issue with PIPENV.</p> <p>Pipenv will create the virtual env, but when I try to install <em>any</em> package using the command <code>pipenv install &lt;package&gt;</code> the install and the lock fails - see an example of the traceback below.</p> <p>I can by...
<python><python-3.x><pipenv>
2023-10-13 15:23:45
2
305
stevec
77,288,757
10,331,731
ImportError: GSSAPIProxy requires the Python gssapi library
<p>Hello after updating to python 3.11.5 i am getting this particular import error on all of my scripts. Anyone knows what i need to install/update for this</p> <pre><code> ImportError: GSSAPIProxy requires the Python gssapi library: No module named 'krb5' </code></pre> <p>i already installed gssapi but keep getting th...
<python><importerror><gssapi><krb5.ini>
2023-10-13 14:55:47
0
393
Learner
77,288,502
1,380,613
Python Ctypes Segmentation Fault
<p>With the help of folks here I was able to get most of my ctype integration working in my python script.</p> <p><a href="https://stackoverflow.com/questions/74976145/python3-processing-ctypes-data">Python3 processing ctypes data</a></p> <p>I am interfacing with the Fanuc Focas library to pull in data from CNC machine...
<python><ctypes>
2023-10-13 14:20:27
1
412
Developer Gee
77,288,414
18,904,265
How can I correctly instantiate with __new__ and class methods?
<p>I have a class, which connects to a server through a python module. The login takes some time, so the idea was to put its instance into a singleton pattern, so I always pass around the exact same instance. In another <a href="https://softwareengineering.stackexchange.com/questions/448082/how-can-i-nicely-pass-on-a-c...
<python><singleton>
2023-10-13 14:06:23
1
465
Jan
77,288,319
1,422,096
Decorator to do a test before launching each function
<p>Instead of repeating <code>if not self.connected: ... return</code> for every method of this class:</p> <pre><code>class A: def __init__(self): self.connected = False def connect(self, password): if password == &quot;ab&quot;: self.connected = True def send(self, message): ...
<python><decorator>
2023-10-13 13:52:44
3
47,388
Basj
77,288,315
130,468
Pythonic equivalent of Java marker annotations
<p>I want to search my Python classpath for all classes that can handle a certain input (type), at runtime. Then I will instantiate them and call them when I receive that input. I would like each class author to be able to mark their class as a possible handler.</p> <p>In Java, I can define the annotation <code>@Handle...
<python>
2023-10-13 13:52:13
1
1,568
Sam Jones
77,288,262
7,978,221
Convert JSON objects to table structure in Python
<p>I have some JSON with an 'items list. I want to convert it to semicolon separated file with headers</p> <p>I want to produce lines in this format: <code>id, date, order[x][0], order[x][1], ...</code></p> <p>My issue is that I need to include headers, the names of the fields, and some <code>order</code> items do not ...
<python><json><export><export-to-csv>
2023-10-13 13:45:18
1
1,575
Jeppe
77,288,248
2,232,418
Python - SSL Error when making API call with urllib.request
<p>I'm trying to make a HTTPS API call in a Python script that will be included in an Azure DevOps pipeline step. I'm restricted to using <code>urllib.request</code>.</p> <p>The current code I have is:</p> <pre><code>try: os.environ['HTTP_PROXY'] = '&lt;redacted&gt;' os.environ['HTTPS_PROXY'] = '&lt;redacted&gt...
<python><ssl><urllib><github-api>
2023-10-13 13:42:38
0
2,787
Ben
77,288,212
9,908,011
Python socket.send on localhost alternates success and failure
<p>I am experiencing some weird behavior when calling <code>socket.send()</code>, which alternatively succeeds and fails with a &quot;connection refused&quot; error:</p> <pre class="lang-py prettyprint-override"><code>import socket, time sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) dest = (&quot;127.0.0.1&q...
<python><sockets><localhost><send>
2023-10-13 13:37:26
1
310
L. Bruce
77,288,210
8,843,585
Asyncio: Detecting never awaited coroutines beforehand
<p>When <code>await</code> is not expressed in a coroutine call, asyncio shows</p> <pre><code>RuntimeWarning: coroutine was never awaited </code></pre> <p>The problem is that this print is easily missable in production environment. It's also difficult when your console shows other application logs.</p> <p>It's a critic...
<python><python-asyncio><python-3.10>
2023-10-13 13:36:52
1
1,219
Ramon Dias
77,288,093
8,387,921
Pull the string between two string in python which has multiple repeating same words
<p>I'm trying to get string from text &quot;20231006-OPUS solution _ cfhs0230.22d OP1696574785263-792.txt&quot;, I'm interested in &quot;cfhs0230.22d&quot;, I used the below method but it doesn't work as there are two &quot;OP&quot; in it...so i want to skip first &quot;OP&quot; and take second &quot;OP&quot; instead a...
<python><python-3.x>
2023-10-13 13:19:23
3
399
Sagar Rawal
77,288,045
10,086,915
Simplifying a set of constraints with sympy by removing variables
<p>I'm currently writing a simplification tool for another software project and I want to simplify some math.</p> <p>I have a given a set of equations and inequalities like</p> <pre><code>x = a y + 1 = b x = y z = c y &gt; z </code></pre> <p>I want to get a set of simplified equations and inequalities with preferably l...
<python><constraints><sympy>
2023-10-13 13:13:36
1
638
Max Ostrowski
77,288,028
5,151,362
How would you implement a thread-safe function which reads from a shared hashtable using a key and updates the value in a multi-threaded environment?
<p>Suppose we have some function which takes in a key, retreives its value from a shared hashtable, and perform some operations on it to obtain a new value , and then updates the hashtable with this new value. Now, this function is multi-threaded so there could be multiple threads calling this same function, either wit...
<python><multithreading><concurrency><hashtable><mutex>
2023-10-13 13:11:56
2
843
Lew Wei Hao
77,287,948
1,914,034
pytorch - passing image original size to transform function
<p>I am using pytorch with albumentations for image transformations in a sementic segmentation model.</p> <p>For some transformations, I need to pass the original image size as parameters but I just dont know how I can do it.</p> <p>I have the transforms function and my dataset class in seperate modules like below. In ...
<python><pytorch><albumentations>
2023-10-13 12:59:55
1
7,655
Below the Radar
77,287,927
8,580,574
I would like to create data with python faker with columns that are dependant on each other
<p>I have to create a synthetic dataset using faker, in which we have columns that have values that are dependant on each other.</p> <p>I tried to use standard faker providers, but it seems there is no way to use this to generate dependant data.</p> <p>For example, I have a column <strong>A</strong> and a column <stron...
<python><dataframe><faker>
2023-10-13 12:57:03
0
2,542
PEREZje
77,287,827
8,324,480
Creating QWidget class and inserting it in an QFormLayout looses alignment
<p>I want a simple widget which contains a QLineEdit, a QPushButton and a second QLineEdit to enter a directory and file name. I started by defining everything within the same QWidget, named <code>CentralWidget</code> that I wanted to add as the central widget of a <code>QMainWindow</code>. But putting everything in th...
<python><qt><pyqt><pyside>
2023-10-13 12:40:06
1
5,826
Mathieu
77,287,622
9,518,886
ModuleNotFoundError: No module named 'kafka.vendor.six.moves' in Dockerized Django Application
<p>I am facing an issue with my Dockerized Django application. I am using the following Dockerfile to build my application:</p> <pre><code>FROM python:alpine ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV DJANGO_SUPERUSER_PASSWORD datahub RUN mkdir app WORKDIR /app COPY ./app . RUN mkdir -p volumes RUN apk...
<python><django><apache-kafka>
2023-10-13 12:11:04
7
537
Navid Sadeghi
77,287,514
8,204,956
Django ORM group by on primary key mysql
<p>In the django ORM it's easy to group by when using an aggregate function like this:</p> <pre class="lang-py prettyprint-override"><code>from django.contrib.auth.models import User User.objects.values('id').annotate(Count('id')) </code></pre> <p>However if I want to group by <em>without</em> an aggregation function (...
<python><mysql><django><django-orm>
2023-10-13 11:55:02
1
938
Rémi Desgrange
77,287,238
10,139,792
Send post request with custom non JSON content in Python
<p>I am trying to create a post request to a specific url but the content I would like to pass is just simple text, not in JSON format, example:</p> <pre><code>POST / HTTP/1.1 Host: www.example.re Content-Type: text/plain Content-Length: 51 \r\n I really like cheese, but I hate it in JSON format! </code></pre> <p>I've ...
<python><http><python-requests>
2023-10-13 11:04:45
1
352
Tal Moshel
77,287,175
8,248,194
Getting NonExistentTimeError in pytz
<p>With this example:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import pytz timestamp = pd.Timestamp('2023-04-30 02:20:28.594000') timezone = pytz.timezone('Africa/Casablanca') print( timestamp.tz_localize(timezone, ambiguous=True) ) </code></pre> <p>I'm getting <code>NonExistentTim...
<python><pandas><timezone><python-datetime><pytz>
2023-10-13 10:56:28
1
2,581
David Masip
77,286,794
5,437,090
TypeError: SparseArray does not support item assignment via setitem
<p>Given:</p> <pre><code>import pandas as pd print(pd.__version__) # '2.1.0' df=pd.DataFrame([[1., 0., 1.5], [0., 2., 0.]], dtype=pd.SparseDtype(&quot;float32&quot;)) </code></pre> <p>I'd like to assign custom values in my sliced pandas sparse dataframe, so I do the following:</p> <pre><code>df_sliced=df.iloc[0].copy()...
<python><pandas><sparse-matrix>
2023-10-13 09:59:18
1
1,621
farid
77,286,695
12,827,931
Join two dataframes median (IQR)
<p>Let's assume two dataframes of medians and interquartile ranges</p> <pre><code>medians = pd.DataFrame({&quot;Median A&quot; : [16, 14, 11], &quot;Median B&quot; : [9, 8, 5]}) iqrs = pd.DataFrame({&quot;IQR A&quot; : [5, 3, 4], &quot;IQR B&quot; : [2, 2, 4]}) </code></pre> <p>What I'd like to to is to join these two ...
<python><pandas><dataframe><join>
2023-10-13 09:43:30
2
447
thesecond
77,286,508
2,786,156
Convert bytes to list of 2s complement 8 bytes signed integer
<p><code>python 3.7</code></p> <p>Having a <code>bytes</code> of a size multiple to <code>8</code> is there a way to convert to a <code>list</code> of 8 bytes large signed integers? I tried the following:</p> <pre><code>some_bytes = #retrieve bytes print(list(some_bytes)) #prints as it was treated a 4 bytes integers </...
<python><list><memory><integer>
2023-10-13 09:13:15
2
27,717
St.Antario
77,286,483
636,626
Maturin project with Python bindings behind feature
<p>I'm trying to write <em>optional Python bindings</em> for a Rust library, using maturin and PyO3. The default layout created by maturin is</p> <pre><code>my-project ├── Cargo.toml ├── python │ └── my_project │ ├── __init__.py │ └── bar.py ├── pyproject.toml ├── README.md └── src └── lib.rs </code><...
<python><rust><pyo3><maturin>
2023-10-13 09:10:21
1
37,219
Nils Werner
77,286,476
2,148,773
Does the Debian python3-opencv package have advantages over the pypy.org opencv-python one?
<p>Under Debian I can install the OpenCV bindings for Python using (at least) one of these two ways:</p> <ul> <li>from the <a href="https://packages.debian.org/bookworm/python3-opencv" rel="nofollow noreferrer">Debian repository</a> (with <code>apt install python3-opencv</code>)</li> <li>or from the <a href="https://py...
<python><opencv><pip><debian><pypi>
2023-10-13 09:08:51
0
6,891
oliver
77,286,470
13,396,497
Write regular expression for text file having wireshark logs and read few lines
<p>I am trying to write regular expressions for wireshark logs captured in text file and read few lines from frames which says 'eth:ethertype:ip:tcp:http:xml' protocol in frame only.</p> <p>If above frame condition match I want to read only lines -</p> <p>1- Internet Protocol Version( for Src and Dst IP's)</p> <p>2- T...
<python><regex>
2023-10-13 09:07:48
1
347
RKIDEV
77,286,299
15,176,150
How do Jupyter Notebook extensions add functionality to a notebook?
<p>Given that behind the scenes the data in a Jupyter notebook is JSON, I assume that a similar simple system is used for notebook extensions.</p> <p>However, I haven't been able to figure out exactly how they work from the <a href="https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/index.html" rel="nofollow...
<python><json><jupyter-notebook><jupyter>
2023-10-13 08:40:41
1
1,146
Connor
77,286,105
10,431,629
Match two pandas data frames using one column in one data frame as default
<p>I have say 2 data frames as below:</p> <pre><code> df1 A B C 1 a X 1 b Y 1 c U 2 d T 3 k Z </code></pre> <p>And 2nd data frame say as</p> <pre><code> df2 A B C 1 a M1 1 d K 2 d Fr 7 y Io </code></pre> <...
<python><pandas><merge><grouping><multiple-columns>
2023-10-13 08:10:57
0
884
Stan
77,286,104
72,791
matplotlib set_major_formatter taking into account range of values
<p>I've written a UI that includes a matplotlib figure. It shows graphs and I'd like to use engineering notation (exponents that are multiples of 3) on the axes. Note that I want the powers to be written out (e.g. &quot;123×10⁶&quot;, not &quot;123 M&quot;, hence not using <a href="https://matplotlib.org/stable/api/t...
<python><matplotlib>
2023-10-13 08:10:52
1
73,231
DrAl
77,286,053
6,499,643
installing transformers on M1 gives jax
<p>I am new to Python and trying to install transformers following instructions <a href="https://huggingface.co/docs/transformers/installation#install-with-conda" rel="nofollow noreferrer">here</a></p> <p>i did all the steps but when I got to</p> <blockquote> <p>python -c &quot;from transformers import pipeline; print(...
<python><pip><conda><huggingface-transformers><apple-m1>
2023-10-13 08:02:52
1
385
m45ha
77,285,903
972,647
Barplot grouped by class and time-interval
<p>I have data of request response times in a pandas dataframe</p> <pre><code> execution_time request_type response_time_ms URL Error 2 2023-10-12 08:52:16 Google 91.0 https://www.google.com NaN 3 2023-10-12 08:52:16 CNN 115.0 https://edition.cnn.com NaN 6 2023-10-12 08:52:27 ...
<python><pandas><seaborn><grouped-bar-chart>
2023-10-13 07:42:45
1
7,652
beginner_
77,285,870
202,335
troubleshooting: To run a flask file in jupyter lab
<p><a href="https://i.sstatic.net/2hhME.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2hhME.png" alt="enter image description here" /></a>Below is the code in jupyter lab.</p> <pre><code>from flask import Flask, render_template app = Flask(__name__) @app.route('/') def home(): return render_templ...
<python><flask><jupyter-lab>
2023-10-13 07:37:50
0
25,444
Steven
77,285,558
8,990,329
Why does python shared memory implicitly unlinked on exit?
<p>I wrote the following simple program to try shared memory in python:</p> <pre><code>#!/usr/bin/env python3.8 from multiprocessing import shared_memory from time import sleep PATH='/pth' if __name__ == '__main__': shm = shared_memory.SharedMemory(PATH) sleep(10) </code></pre> <p>The issue is that on the pr...
<python><linux><shared-memory><python-3.8>
2023-10-13 06:39:54
1
9,740
Some Name
77,285,514
15,233,792
How to launch / terminate periodic task running on the background using python asyncio in Flask Backend App?
<p>I have a python flask backend app. I want to create a mechanism that can let some jobs run periodic on the background, like auto-update something every 1 minute.</p> <p>But I have been blocked by some errors that made the backend didn't behave as expected.</p> <p><strong>view_func.py</strong></p> <pre class="lang-py...
<python><flask><python-asyncio>
2023-10-13 06:30:22
1
2,713
stevezkw
77,285,501
8,510,149
Openpyxl, how to do two operations on x-axis labels, rotating and change font, without one overrides the other
<p>I aim to rotate the labels on the x-axis and change font. However, in the code below, these two operations work individually, but when I do both, the rotating is undone by the font change.</p> <p>How can I do these two operations on my chart?</p> <pre><code>import openpyxl from openpyxl.chart import BarChart, Refere...
<python><excel><openpyxl>
2023-10-13 06:27:02
1
1,255
Henri
77,285,334
13,184,183
Is pyspark dataframe a pointer?
<p>I read several dataframes from different locations and them union them. To do that, firstly I collect them in a list.</p> <pre class="lang-py prettyprint-override"><code>from functools import reduce # spark initialization df_list = [] for path in paths: df = spark.table(path) df_list.append(df) data = redu...
<python><apache-spark><pyspark>
2023-10-13 05:50:42
2
956
Nourless
77,285,312
2,418,375
Install the PyCoral library fails: "No matching distribution found for pycoral~=2.0"
<p>I just got a Google Coral USB Accelerator and am trying to install it on a Windows 11 machine following the instructions at <a href="https://coral.ai/docs/accelerator/get-started/" rel="nofollow noreferrer">https://coral.ai/docs/accelerator/get-started/</a>. I got Python 3.11 from the Microsoft app store and it's wo...
<python><google-coral><pycoral>
2023-10-13 05:45:46
0
334
wjr
77,285,110
521,347
subject table for an INSERT, UPDATE or DELETE expected,got 'comparison_bill_data'
<p>I am trying to write an insert query using Python sqlAlchemy. I keep getting an error <code>sqlalchemy.exc.ArgumentError: subject table for an INSERT, UPDATE or DELETE expected, got 'comparison_bill_data'.</code>.My code is as follows-</p> <pre><code>from uuid import uuid4 import sqlalchemy as sa from sqlalchemy.dia...
<python><sqlalchemy><fastapi>
2023-10-13 04:48:27
1
1,780
Sumit Desai
77,284,988
8,387,921
use if else statement in python selenium for a text_to_be_present_in_element
<p>I have following line of code which after uploading files returns 'Upload successful!' text . But several times there is error in uploading files and the element of website displays 'Upload Status' in place of 'Upload Successful'. So how to use the logic of if else statment to run the the rest command even if it fai...
<python><selenium-webdriver>
2023-10-13 04:04:52
0
399
Sagar Rawal
77,284,983
1,232,087
How to connect to a remote Jupyter server from vscode.dev
<p><strong>Question</strong>: How do I get URL for <code>jupyter server</code> when jupyter extension is installed in <a href="https://code.visualstudio.com/docs/editor/vscode-web" rel="nofollow noreferrer">VSCode for web</a>?</p> <p>I have successfully installed <code>python</code> and <code>jupyter</code> extensions ...
<python><visual-studio-code><jupyter-notebook>
2023-10-13 04:01:53
1
24,239
nam
77,284,980
525,916
How to add a new column that has the occurrence number of the value in a column?
<p>Given a Polars Dataframe:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.from_repr(&quot;&quot;&quot; ┌───────┬───────┬───────┐ │ Col_1 ┆ Col_2 ┆ Col_3 │ │ --- ┆ --- ┆ --- │ │ str ┆ str ┆ i64 │ ╞═══════╪═══════╪═══════╡ │ A ┆ a ┆ 1 │ │ B ┆ b ┆ 2 │...
<python><dataframe><python-polars>
2023-10-13 04:00:56
1
4,099
Shankze
77,284,970
19,238,204
How to change x-axis ticks into pi (π) terms with Sympy Plotting (Python 3)
<p>I have this Fourier computation for n=3, n=5, and n=7. I want to make the x-axis have ticks in pi terms (from -4π to 4π with increment that can be adjusted for example π). I find on SoF that x-axis can be changed to π terms, but they all are using matplotlib to plot, this code of mine is using Sympy to plot.</p> <p>...
<python><sympy>
2023-10-13 03:58:20
1
435
Freya the Goddess
77,284,954
8,942,319
Poetry install not updating scripts
<p>I made a simply change so that a script was moved up a directory. Poetry doesn't seem to recognize that it's been moved since the <code>poetry install</code> or <code>update</code> command does nothing</p> <pre><code>Installing dependencies from lock file No dependencies to install or update </code></pre> <p>and th...
<python><python-poetry>
2023-10-13 03:51:27
1
913
sam
77,284,822
10,852,841
Only keep the best trial using keras-tuner (Hyperband)
<p>How can I tell <code>keras_tuner</code> to only save the best model (overwriting each trial) and not create any checkpoints or directories for each trial?</p> <p>There has been discussion already about how to reduce the amount of disk space that <code>keras_tuner</code> uses by either <a href="https://github.com/ker...
<python><tensorflow2.0><keras-tuner>
2023-10-13 03:01:38
0
2,379
m13op22
77,284,818
1,761,761
Should hypen-minus (U+002D) or hypen (U+2010) be used for ISO 8601 datetimes?
<p>Python interpreter gives the following when generating an ISO-8601 formatted date/time string:</p> <pre><code>&gt;&gt;&gt; import datetime &gt;&gt;&gt; datetime.datetime.now().isoformat(timespec='seconds') '2023-10-12T22:35:02' </code></pre> <p>Note that the '-' character in the string is a hypen-minus character. Wh...
<python><datetime><unicode><ascii><iso8601>
2023-10-13 02:58:52
3
7,380
deadlock
77,284,715
8,444,568
How to make python auto-select right pyc file to execute?
<p>I want to distribute my python script in <code>pyc</code> format(generated by <code>python -OO -m py_compile run.py</code>)</p> <p>For different python versions, I've created <code>run.cpython-36.pyc</code>, <code>run.cpython-38.pyc</code>...</p> <p>Now, if the users are using python3.6, they need to call <code>pyth...
<python><pyc>
2023-10-13 02:17:36
1
893
konchy
77,284,709
4,898,865
pythonic popup messagebox in dearpygui (asyncio or sync way)
<p>for person who is looking for pythonic popup messagebox in dearpygui, hope it can help</p> <p>target:</p> <pre class="lang-py prettyprint-override"><code>do_sth_step1(...) user_response = msgbox('Confirm?') # Yes/No if user_response == 'Yes': do_sth_step2(...) </code></pre>
<python><messagebox><dearpygui>
2023-10-13 02:16:14
1
337
Atlas
77,284,576
13,176,726
Google AdMob app-ads.txt Configuration issue
<p>I'm currently facing an issue with configuring my Django application published in linode server using Nginx. My issue is in the app-ads.txt file for Google AdMob. I have set up a view in my views.py and added the corresponding URL pattern in urls.py as follows:</p> <h1>views.py</h1> <pre><code>@require_GET def ads_t...
<python><django><admob><linode>
2023-10-13 01:14:00
0
982
A_K
77,284,534
963,298
Python Slack API download binary file returns html
<p>I can upload files to a slack channel via the python Slack API. I am unable to download the binary file with the url indicated in <code>message['files'][0]['url_private_download']</code>.</p> <p>Rather, I get 40KB of HTML when using <code>requests.get</code>, <code>wget -mO &lt;file-name&gt; &lt;url&gt;</code>, and...
<python><download><slack-api>
2023-10-13 00:56:02
2
1,061
stephen
77,284,507
789,750
Use Plotly to show multiple lines by value of another column in the dataframe
<p>I have a dataframe that looks like this:</p> <pre><code>fruit number date apple 7 2013-11-4 banana 8 2016-4-6 apple 2 2018-7-22 banana 103 2020-4-4 </code></pre> <p>I want a line plot with two lines: the number of apples and the number of bananas as a function of the date. Is there a simple...
<python><pandas><dataframe><plotly>
2023-10-13 00:41:59
2
12,799
Dan
77,284,430
15,632,586
CUDA out of memory when running validation test for SciBERT
<p>I am trying to train SciBERT with a not-too-big dataset (roughly 10000 rows). I have partitioned the dataset as train, validation and loss, with proportion of 0.6, 0.2 and 0.2 respectively. Then I tried to train the model, with code like this:</p> <pre><code>from torch.optim import AdamW from tqdm import tqdm from s...
<python><pytorch><google-colaboratory><bert-language-model>
2023-10-13 00:03:15
1
451
Hoang Cuong Nguyen
77,284,406
16,988,223
BeautifulSoup with python unable to get value of a span tag
<p>I'm trying to get the value from the main titular news from this <a href="https://elperuano.pe/" rel="nofollow noreferrer">web page</a></p> <p><a href="https://i.sstatic.net/JjGGJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JjGGJ.png" alt="enter image description here" /></a></p> <p>Here is my cod...
<python><web-scraping><beautifulsoup>
2023-10-12 23:57:21
3
429
FreddicMatters
77,284,309
5,212,614
How to Convert a Pandas Dataframe to a Spark Dataframe?
<p>I downloaded and installed the Windows 64-bit driver from the link below.</p> <p><a href="https://www.databricks.com/spark/odbc-drivers-download" rel="nofollow noreferrer">https://www.databricks.com/spark/odbc-drivers-download</a></p> <p>Then, I did <code>pip install pyspark</code></p> <p>Now, I am testing the code ...
<python><python-3.x><pandas><apache-spark><pyspark>
2023-10-12 23:28:23
1
20,492
ASH
77,284,251
3,138,238
Run ASGI Application with FastAPI inside a Jelastic PaaS Environment using mod_wsgi
<p>I want to use <code>FastAPI</code> inside my python project, I want to deploy it on a Jelastic PaaS. Apparently <code>mod_wsgi</code> manages only WSGI application so I was trying to run an ASGI application inside a WSGI application using <code>a2wsgi</code> like this, this is my <code>wsgi.py</code>:</p> <pre><code...
<python><mod-wsgi><wsgi><jelastic><asgi>
2023-10-12 23:07:17
1
7,311
madx
77,284,187
14,192,391
Error: pyodbc.ProgrammingError: No results. Previous SQL was not a query. when using python script
<p>I am using python script and pyodbc library to connect to a MS Sql. ODBC Driver 17 for SQL Server.Then I use <code>DECLARE</code> to create a table variable:</p> <pre><code>SQL_QUERY = &quot;&quot;&quot; DECLARE @MyTable TABLE (ID INT, Name NVARCHAR(255)); INSERT INTO @MyTable (ID, Name) VALUES (1, 'John'), (2, 'Jan...
<python><sql><odbc><pyodbc><pymssql>
2023-10-12 22:43:33
0
495
zurich_ruby
77,284,175
9,669,142
Python - linear trendline on log-log plot is not fitted well
<p>I have multiple sets of four data points and I want to create for each of these sets a linear trendline on a log-log plot between each of the points (four points meaning three trendlines in total). I use <code>curve_fit</code> from <code>scipy.optimize</code> to do this. It works for all sets that I have, except for...
<python><scipy><curve-fitting>
2023-10-12 22:40:01
1
567
Fish1996
77,284,167
1,750,849
Conda env: confusing python versions in conda info and actual python command
<p>I created a new conda env with python 3.11 and here is the conda env info:</p> <pre><code>rakesh@Rakeshs-MBP ~ % conda activate mlearn (mlearn) rakesh@Rakeshs-MBP ~ % conda info active environment : mlearn active env location : /usr/local/Caskroom/miniconda/base/envs/mlearn ...
<python><conda><miniconda>
2023-10-12 22:37:43
0
451
rks
77,284,039
14,813,970
How to properly round to the nearest integer in double-double arithmetic
<p>I have to analyse a large amount of data using Python3 (PyPy implementation), where I do some operations on quite large floats, and must check if the results are close enough to integers.</p> <p>To exemplify, say I'm generating random pairs of numbers, and checking if they form <a href="https://en.wikipedia.org/wiki...
<python><precision><floating-accuracy><pypy><double-double-arithmetic>
2023-10-12 21:58:09
4
337
kleite
77,283,982
6,076,975
Pattern Matching callbacks for inputs of a form on multiple pages
<p>I have a use case where I am rendering a form with multiple select dropdowns. The form can be rendered with varying numbers of selects (chosen from a file). I am using dashboard_bootstrap_forms for this. I am rendering each form with a unique ID and there can be multiple number of such forms on a page in different t...
<python><plotly><plotly-dash>
2023-10-12 21:41:21
0
697
Arjun Singh
77,283,976
4,969,603
Add coroutine to gather array
<p>I have an array of coroutines in asyncio, all of the are blocking, and in one of them would like to add a new one to the array to be gathered. Not sure if this is possible ... Imagine the pingLoop code needs to add a new routine pingSpecial() and await it, it will be also blocking, so it would block the pingLoop, wh...
<python><python-asyncio>
2023-10-12 21:40:12
1
373
Miro Krsjak
77,283,841
3,657,988
Cached WMTS requests
<p>The Cartopy <a href="https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.mpl.geoaxes.GeoAxes.html#cartopy.mpl.geoaxes.GeoAxes.add_wmts" rel="nofollow noreferrer"><code>add_wmts</code></a> method uses <a href="https://scitools.org.uk/cartopy/docs/latest/reference/generated/cartopy.io.ogc_clients.W...
<python><matplotlib><cartopy>
2023-10-12 21:04:26
1
1,195
Dan
77,283,747
3,846,421
Windows 10: rstudio reticulate keras tensorflow :: anaconda vs. miniconda vs. python
<p>The number of issues I'm having with a STABLE python environment operating beneath R/Rstudio is overwhelming... and the permutations of installation steps is far too flexible to inspire confidence with any approach.</p> <p>First, I used <code>reticulate</code> to <code>uninstall_miniconda</code>. I wiped the compute...
<python><tensorflow><keras><rstudio><miniconda>
2023-10-12 20:44:07
0
685
quickreaction
77,283,648
11,107,541
VS Code Python extension (circa v2018.19) no longer includes support for linters and formatters. Why?
<p>The Python extension for VS Code used to provide builtin support for tools like formatters and linters, including:</p> <ul> <li>Linting: Pylint, Flake8, Mypy, Bandit, Pydocstyle, Pycodestyle, Prospector, Pylama</li> <li>Formatting: autopep8, Black, YAPF</li> </ul> <p>What's happening to the builtin support for these...
<python><visual-studio-code>
2023-10-12 20:24:36
1
59,003
starball
77,283,503
376,535
Python poetry stops with exit code 1 but no error message in CICD
<p>I am running <code>poetry install -vvv --no-interaction</code> in the CICD environment as part of CI. We recently updated poetry to 1.6.1. This is the latest version as of today. The build was passing. But then this started to happen.</p> <pre><code> #!/bin/bash -eo pipefail poetry install --no-interaction -vvv Lo...
<python><git><pip><python-poetry>
2023-10-12 19:53:43
1
57,835
Shiplu Mokaddim
77,283,291
21,061,890
Python ctypes how to reject function call with arguments for function taking no arguments
<p>In C++, I have created a C linkage function in a shared library like this:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt; extern &quot;C&quot; int myfunc() { std::cout &lt;&lt; &quot;Hello myfunc&quot; &lt;&lt; std::endl; return 1; } </code></pre> <p>Note the function does not req...
<python><ctypes>
2023-10-12 19:13:32
1
313
InTheWonderlandZoo
77,282,710
6,572,639
Stream a file from S3 to a HTTP multipart endpoint
<p>I'm trying to stream a large file from an S3 bucket to an HTTP API. I read a lot of SO threads partially covering my needs but was not capable of putting things together.</p> <p>Reading the file locally is working using request toolbelt:</p> <pre><code>stream = open('/tmp/file', 'rb') encoder = MultipartEncoder( ...
<python><python-requests><boto3>
2023-10-12 17:29:49
1
1,352
Plup
77,282,683
6,672,746
PyAthena - Invalid length for parameter RoleArn
<p>I am trying to use Python, PyAthena, and SQLAlchemy to connect to Athena.</p> <p>When trying to define a SQLAlchemy cursor:</p> <pre><code>from pyathena import connect cursor = connect( aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key, s3_staging_dir=s3_staging_dir, region_na...
<python><sqlalchemy><boto3><amazon-athena><pyathena>
2023-10-12 17:25:35
0
2,171
Evan
77,282,567
2,745,116
How to build Python wheels that are independent of the MacOS version?
<p>I am regularly building and shipping Python wheels for a library, where we build different wheels for different platforms, particularly for Mac x86 and Mac ARM (M1/M2) platforms.</p> <p>A resulting wheel for ARM is usually called something like <code>mylib-16.2.0-cp39-cp39-macosx_14_0_arm64.whl</code>, i.e., it not ...
<python><macos><pip><build><python-wheel>
2023-10-12 17:07:24
1
6,176
stefanbschneider
77,282,466
1,230,694
Calculating end position of annotation on plotly bar chart
<p>I am creating a bar chart using <code>plotly</code> which only has two bars, the left bar is always a larger value than the right.</p> <p>I need to place an arrow pointing downwards above the smaller bar, the head of the arrow should touch the smaller bar and this position is quite easy to compute, however the tail ...
<python><plotly>
2023-10-12 16:48:42
2
3,899
berimbolo
77,282,427
1,946,418
python - library to browse and download files from a remote server
<p>Have a webserver that has some folder/file structure. This list keeps on changing. I can download using <code>requests</code> if I have the full path, but the list of files is dynamic; looking to find the more recent file based on timestamps.</p> <p>I can scrape the HTML, but hoping to avoid. Looking for some sort o...
<python>
2023-10-12 16:42:37
0
1,120
scorpion35
77,282,316
1,555,615
How can Flask rest endpoint communicate to a pyqt application running on the same python program
<p>I am trying to create a simple rest endpoint, that when hit, it changes the status of a tray icon that is installed by the program itself.</p> <p>I believe that I need Flask and the QApplication to run in different threads and I tried to do this.</p> <p>However I am not familiar with python and most probably I am do...
<python><flask><pyqt><pyqt6>
2023-10-12 16:25:41
2
11,246
Marinos An
77,282,256
2,429,869
Why do these datetime conversions using pytz not land on hours before December of 1901?
<p>Perhaps I am not using the libraries correctly, or perhaps there was some kind of standard change on December 15, 1901 concerning world wide time keeping. But I stumbled across this odd behavior while working on a time related application.</p> <pre><code>sydney = pytz.timezone(&quot;Australia/Sydney&quot;) tokyo = p...
<python><datetime><timezone><pytz>
2023-10-12 16:16:15
1
1,430
Andrew Allaire
77,282,208
8,382,028
Aggregate not working in prefetched queryset in Django
<p>I have a query that I am trying to aggregate values so I can calculate balances more quickly than querying multiple times to get the values needed.</p> <p>Overall I simply want to be able to run, but the aggregation that seems to be what would allow that isn't working:</p> <pre><code>header_accounts = custom_report....
<python><python-3.x><django><django-aggregation>
2023-10-12 16:07:35
1
3,060
ViaTech
77,282,169
412,655
In a Jupyter notebook, is it possible to configure it to automatically display a (decorated) function where it's defined?
<p>Suppose I have a decorate that adds a <code>_repr_html_</code> method to an object, and I use it on a function <code>foo</code>:</p> <pre class="lang-py prettyprint-override"><code>def add_repr_html(f): f._repr_html_ = lambda: f&quot;This is {f.__name__}!&quot; return f @add_repr_html def foo(): ... </c...
<python><jupyter-notebook>
2023-10-12 16:02:10
1
4,147
wch
77,282,091
8,452,246
Change the color, marker size and name of single value - Plotly scatter
<p>I have a dataframe and I am using Plotly to draw a scatter plot. I want to change the color, size and name of just a single value there, e.g. datapoint &quot;one&quot;. I am not sure how to do this. I have been trying <code>for_each_trace</code> aiming to change the marker shape but never works.</p> <pre><code>impor...
<python><plotly><plotly-express>
2023-10-12 15:51:43
1
477
Martin Yordanov Georgiev
77,282,055
4,710,409
Chatterbot- multiple custom adapters don't work
<p>I'm using the django integration.</p> <p>settings.py</p> <pre><code>CHATTERBOT = { 'name': 'chatbot0', 'storage_adapter': &quot;chatterbot.storage.SQLStorageAdapter&quot;, 'logic_adapters': [ 'chatterbot.logic.BestMatch', #custom adapters 'chatbot.adapters.adapter_1', 'cha...
<python><django><chatterbot>
2023-10-12 15:42:58
1
575
Mohammed Baashar
77,282,006
12,502,424
Resolve incompatible packages for a Flask application
<p>Here's my requirements.txt</p> <pre><code>aiohttp==3.8.6 aiosignal==1.3.1 async-timeout==4.0.3 attrs==23.1.0 blinker==1.6.3 certifi==2023.7.22 charset-normalizer==3.3.0 click==8.1.7 Flask==1.1.2 Flask-Login==0.6.2 Flask-SQLAlchemy==2.5.1 frozenlist==1.4.0 greenlet==3.0.0 idna==3.4 itsdangerous==2.1.2 Jinja2==3.1.2 M...
<python><flask><pip><jinja2><werkzeug>
2023-10-12 15:35:52
1
1,199
VeeDuvv
77,281,982
5,994,623
SQLAlchemy - Relationship with "indirect" Foreign Key
<h1>Context</h1> <p>I'm using SQLAlchemy (v2) to set up a database for an application, and I'm trying to model some relationships on my data. The relationships look similar to this diagram.</p> <p><a href="https://i.sstatic.net/roJ6G.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/roJ6G.png" alt="ER-Diag...
<python><database><sqlite><database-design><sqlalchemy>
2023-10-12 15:31:45
1
820
Fynn
77,281,898
6,930,441
Pandas dataframe columns unexpectedly out of order
<p>I encountered a rather unexpected result today with a pandas dataframe.</p> <p>My script takes genome sequence data (in fasta format) as input and calculates several basic metrics. I store those metrics in a pandas dataframe.</p> <p>The script starts by defining an empty dataframe with headers:</p> <pre><code>stats_...
<python><pandas><dataframe>
2023-10-12 15:19:53
1
456
Rainman
77,281,895
8,595,535
Summing dataframe between dates that are located in another dataframe
<p>say I have two pandas dataframe df1 and df2 as follows:</p> <pre><code>import pandas as pd df1 = pd.DataFrame({'Name': ['A', 'B', 'C'], 'Date1':['2023-01-01', '2023-01-02', '2023-01-03'], 'Date2':['2023-01-03', '2023-01-04', '2023-01-05']}) df1.loc[:, ['Date1', 'Date2']] = ...
<python><pandas>
2023-10-12 15:19:35
2
309
CTXR
77,281,875
1,914,781
add new row with differ of last and first row
<p>I would like to create a summary row to show differ between last and first row.</p> <p>e.g.</p> <pre><code>import pandas as pd data = [ ['A',1,5], ['B',2,4], ['C',3,3], ['D',4,2], ['E',5,1], ['F',6,0] ] df = pd.DataFrame(data,columns=['name','x','y']) print(df) </code></pre> <p>Output dd...
<python><pandas>
2023-10-12 15:17:27
4
9,011
lucky1928
77,281,818
1,616,528
find_nearest_contour is deprecated. Now what?
<p>I'm using Matplotlib contours to explore a 2d map. I'm using <a href="https://matplotlib.org/stable/api/contour_api.html#matplotlib.contour.ContourSet.find_nearest_contour" rel="nofollow noreferrer"><code>contour.find_nearest_contour</code></a> to get the range of x and y of the contour that passes close to a point ...
<python><matplotlib><contour><deprecation-warning>
2023-10-12 15:09:23
1
329
matteo
77,281,614
1,734,097
python duplicate function parameter and execution
<p>Help i have the following code.</p> <p>I ran <code>gspread_connect()</code> and no issue found. The problem is I don't want to execute <code>get_data_gsheet()</code> by supplying the parameters that required by <code>gspread_connect()</code> in</p> <p><code>gc = gspread_connect(config_section_name,config_section_var...
<python>
2023-10-12 14:43:43
0
1,099
Cignitor
77,281,582
14,829,523
Sort pandas df based on constraints
<p>I have the following dummy df.</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame({'car': ['Pickup', 'Racer', 'Lorry', 'Luxury', 'Cabrio', 'Bicycle', 'Truck']...
<python><pandas>
2023-10-12 14:39:22
2
468
Exa
77,281,556
8,332,501
Python where to mock complexe case
<p>I have a complexe mocking case where I don't know where to patch in Python</p> <p>file <strong>supervised_model.py</strong></p> <pre class="lang-py prettyprint-override"><code>from sklearn.ensemble import RandomForestClassifier class SModel: def __init__(self) -&gt; None: self.model = RandomForestClass...
<python><mocking>
2023-10-12 14:37:28
0
521
thetradingdogdj
77,281,465
7,505,228
Form a "chain" of relationship through SQLAlchemy
<p>Say I have a database where I want to model a many-to-many relationship between users and the websites they have access to.</p> <p>I have the tables <code>users</code> and <code>websites</code>, and I create a third <code>users_have_sites</code> table with two foreign keys to modelize this many-to-many relationship....
<python><sqlalchemy>
2023-10-12 14:24:34
1
2,289
LoicM
77,281,448
3,380,209
How to get "xy" of a transformed polygon
<p><code>poly</code> is a given polygon.</p> <pre><code>&gt;&gt;&gt; from matplotlib.figure import Figure &gt;&gt;&gt; import matplotlib as mpl &gt;&gt;&gt; fig = Figure(figsize=(10, 8)) &gt;&gt;&gt; ax = fig.add_subplot() &gt;&gt;&gt; ax.add_patch(poly) &gt;&gt;&gt; poly &lt;matplotlib.patches.Polygon object at 0x7fbf...
<python><matplotlib>
2023-10-12 14:22:35
2
3,100
albar
77,281,211
8,201,655
Manually Add Source Files to Conda-Build Package
<p>I am building a conda package for a pure python application. The application has a setup.py file that the build.sh file uses to locate the packages that should go into the build. This works well for all of the normal packages.</p> <p>Now, I have a &quot;nested&quot; package that I also want to include in the build. ...
<python><continuous-integration><conda><setuptools><conda-build>
2023-10-12 13:51:53
0
977
Jared M
77,281,193
5,759,295
Get data output from Sagemaker training step before pipeline executes
<p>I'm saving output data as a part of my training step in my sagemaker pipeline. Some of this data is later used in another step for evaluation, not the model. Is there any way I can get the path before the execution? A pipeline variable is good enough. Just anything that lets me point to the s3 data path for later us...
<python><amazon-sagemaker>
2023-10-12 13:49:22
1
558
Carl Rynegardh