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,014,319
6,646,188
How to map multiple values to a single value in python?
<p>How to map multiple values to a single value and return that single value when I will search? For example:</p> <pre><code>Fruit -&gt; Mango, Banana, Apple Vehicle -&gt; Car, Bus, Truck Place -&gt; Berlin, NewYork </code></pre> <p>Let's say, I will give input &quot;<strong>Truck</strong>&quot; and it will search and ...
<python><python-3.x>
2024-02-18 02:01:39
2
2,019
Abhijit Mondal Abhi
78,014,255
386,159
Python is_file not working on a mounted raw image
<p>Pathlib's is_file doesn't seem to work when running on a loop-backed mounted device</p> <p>I have a text file with file paths in it. The files correspond to a loop-back mounted .raw image.</p> <pre><code>cat diff.txt | grep kvm-recheck-rcu.sh usr/src/linux-hwe-6.5-headers-6.5.0-17/tools/testing/selftests/rcutorture/...
<python>
2024-02-18 01:20:23
0
2,376
bearrito
78,014,132
1,911,722
In python multimethod, how to define a case for empty list?
<p>For example, I define</p> <pre><code>@multimethod def f(x:list[str]): return 1 @multimethod def f(x:list[int]): return 0 </code></pre> <p>then</p> <pre><code>f([]) </code></pre> <p>gives error</p> <blockquote> <p>DispatchError: ('f: 2 methods found', (&lt;class 'multimethod.&lt;class 'list'&gt;'&gt;,), [(&lt...
<python><multimethod>
2024-02-18 00:14:49
1
2,657
user15964
78,014,051
1,424,880
pycharm adds extra tab inside parentheses
<p>I just recently upgraded to a newer pycharm 2023.3.3 and noticing that it started to put an extra tab inside the parentheses.<br /> Consider</p> <p><code>x = 'orange</code><BR> <code>x.replace('r', 'o')</code></p> <p>I would expect to have <code>x.replace('r', 'o')</code> stay as-is. <br> However, pycharm places ext...
<python><pycharm>
2024-02-17 23:21:16
0
1,545
JavaFan
78,013,861
6,533,037
Calculate Simple Moving Average
<p><code>data</code> is list containing candlestick objects. The <code>c</code>-property is the closing price of that candlestick.</p> <p>I have the following Python code to calculate the SMA:</p> <pre><code># Calculate to Simple Moving Average. def sma(close_prices): return sum(close_prices) / len(close_prices) def...
<python>
2024-02-17 21:57:58
0
1,683
O'Niel
78,013,836
1,443,702
Designing python code to execute concurrent requests by server for maximum requests
<p>I am trying to write the below python script, where for I have 5 servers and each server can process at max 2 requests concurrently. I have a pool of 10 requests to processed. Each server picks 2 requests each, processes them and picks up another request from the pool as soon as they have capacity to do so.</p> <p>T...
<python><python-3.x><concurrency><python-asyncio>
2024-02-17 21:44:51
3
4,726
xan
78,013,757
4,842,857
Package on pipx is missing a version
<p>I'm new to Python, so I'm probably missing something about pipx, but I've been instructed to install version 0.0.13 and the latest version I'm seeing is 0.0.8:</p> <pre class="lang-bash prettyprint-override"><code>pipx install insanely-fast-whisper==0.0.13 --force Fatal error from pip prevented installation. Full pi...
<python><conda><pipx>
2024-02-17 21:13:51
1
5,349
Jack Steam
78,013,649
893,254
Python functional method of checking that all elements in a list are equal
<p>I am trying to find a functional method which is available in Python which can be used to check if all elements in a list are equal. Instinctively, I feel that this should be possible.</p> <p>My objective is to build a functional solution to solve the problem of checking if all values in list are equal.</p> <p>If yo...
<python><functional-programming>
2024-02-17 20:39:01
3
18,579
user2138149
78,013,505
14,839,602
python-docx does not apply font size when changing text direction to RTL
<p>I want to change the direction to RTL since I write in Kurdish which uses Arabic numerals. but whenever I apply <code>run.font.rtl = True</code>, it will cancel the font size <code>run.font.size = Pt(20)</code></p> <p>How can I fix that issue?</p> <pre><code>for paragraph in doc.paragraphs: if '{text}' in paragr...
<python><ms-word><right-to-left><python-docx>
2024-02-17 19:50:26
1
434
Hama Sabah
78,013,422
595,305
qtbot in pytest-qt raising AttributeError
<p>OS: W10<br> Python: 3.10<br> pytest: 7.3.1<br> pytest-qt: 4.2.0<br></p> <p>It's some time since I've used the <code>qtbot</code> fixture. I have what I believe to be a simple setup here. In this code I have included the <code>qtbot</code> fixture in the test function:</p> <pre><code>def test_is_possible_to_log_a_mes...
<python><qt><pyqt><pytest><pytest-qt>
2024-02-17 19:24:52
0
16,076
mike rodent
78,013,394
15,061,831
WebSocket connection to 'ws://127.0.0.1:5000/socket.io/?EIO=4&transport=websocket&sid=wBX-4EpWW6-y-DfFAAAC' failed:
<p>Im trying to send a &quot;refresh message&quot; from a Flask python app to the html.</p> <p>I did this:</p> <pre><code>def alert(previous_date, date, archivo): with app.app_context(): if previous_date!= date: print(f&quot;Alert&quot;) socketio.emit('refresh_page') re...
<javascript><python><socket.io>
2024-02-17 19:16:54
0
833
JustToKnow
78,013,308
2,658,627
Why is this command not syncing in the bot - discord.py
<p>I am using discord.py and have a bot using <a href="https://discordpy.readthedocs.io/en/stable/interactions/api.html#commandtree" rel="nofollow noreferrer">app_commands.CommandTree</a>.</p> <p>When I go to define and add 2 slash commands, 1 syncs and shows up in the UI, the other does not.</p> <p>Can someone help me...
<python><discord.py>
2024-02-17 18:50:51
1
709
anonymous
78,013,251
16,425,408
How to make the Telegram bot send the PDF file or return a G-drive link
<p>I am just working around the Telegram bot using Python, and I wish to send a pdf file or a drive link via the bot. However, I am getting an error. </p> <pre><code>No error handlers are registered, logging exception. Traceback (most recent call last): File &quot;/home/murgod/.local/lib/python3.9/site-packages/teleg...
<python><python-3.x><bots><telegram><telegram-bot>
2024-02-17 18:31:39
0
838
Nani
78,013,162
14,196,341
Typehint function *args -> tuple[*args] with constraint on the args
<p>We want to type hint a function</p> <pre class="lang-py prettyprint-override"><code>def f(*args:float)-&gt;tuple[float,...]: ... return tuple(args) </code></pre> <p>such that it is specified that the number of elements in the tuple matches the number of args. Of course, the return here is a placeholder for mor...
<python><python-typing><mypy><pyright>
2024-02-17 18:03:44
1
392
Felix Zimmermann
78,013,031
1,581,441
debug pymongo access - [Errno 111] Connection refused
<p>I am trying to access my database on MongoDB from my virtual private server and from my shared hosting account on Godaddy. I follow the same installation steps for pymongo, and I added the public IP for both. The thing is that the connection to the DB works correctly for the virtual private server, but not for the s...
<python><mongodb><pymongo>
2024-02-17 17:21:04
1
1,512
hmghaly
78,012,948
14,775,478
How to invoke pydantic field_validator on another, optional field?
<p>I am trying to use a <code>field_validator</code> to validate a field based on the presence of another, optional field. So this is really about validating one input based on another input (the classic &quot;password1/password2&quot; tutorial case, albeit validating password1 on optional password2).</p> <p>Example: I...
<python><pydantic><pydantic-v2>
2024-02-17 16:58:19
0
1,690
KingOtto
78,012,870
16,689,086
Errors in installing mpc
<p>hi everyone when am trying to install mpc, by running the command:</p> <pre><code>pip install mpc </code></pre> <p>I get the following error:</p> <pre><code> Using cached mpc-0.0.4.tar.gz (17 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not ...
<python><pip><mpc><meshroom>
2024-02-17 16:34:26
1
653
Noya_G
78,012,868
1,030,287
jupyter lab rotating a 3D plot uses all CPUs
<p>I just did a fresh install of the latest linux Mint 21.3 &quot;Virginia&quot; Cinnamon based on Ubuntu 22.04. I've got a dedicated NVidia graphics card with the latest Nvidia drivers installed. I'm running AMD Ryzen 7 5800X and my NVidia graphics card is nothing exciting - it's a fanless 2GB card but this should be ...
<python><matplotlib><jupyter-notebook><jupyter><jupyter-lab>
2024-02-17 16:34:06
0
12,343
s5s
78,012,840
243,090
Polars: AWS S3 conection pooling
<p>I want to use Polars to read from Parquet files stored on S3. I'm running my code in AWS Lambda.</p> <p>When using boto3 I would make a client in the global scope in order that the connection is reused for each invocation (e.g, a client is made for each Lambda cold start, but not for each invocation):</p> <pre class...
<python><amazon-s3><aws-lambda><python-polars>
2024-02-17 16:30:30
1
537
Sym
78,012,759
3,232,982
Retry on "socket.send() raised exception"
<p>My code:</p> <pre><code>import asyncio import time valueTime = 3 async def telnet_client(host: str, port: int) -&gt; None: while True: try: reader, writer = await asyncio.open_connection(host, port) print(f&quot;connected to ({host}, {port})&quot;) while True: ...
<python><python-asyncio>
2024-02-17 16:07:09
1
413
Roni Hacohen
78,012,269
1,820,480
Nextflow Execution Environment Differs Between Processes
<p>I am defining two nextflow processes. The first one, scatter(), creates two files. Then, parallel() is spawned twice, once for each file.</p> <p>Here is my setup.</p> <pre><code>// bug.nf nextflow.enable.dsl = 2 workflow { main: scatter(params.config) scatter.out.configs | flatten ...
<python><docker><nextflow>
2024-02-17 13:31:39
2
3,196
r0f1
78,012,062
5,285,918
Why does it seem necessary to rotate transformation matrix for mapping coordinates with scikit image?
<p>I have a set of points that are effectively 3 vertices of a 45-45-90 right triangle and some other points, <code>a</code>, that should map to them.</p> <pre class="lang-py prettyprint-override"><code>import numpy as np points = np.array([ ( 90, 416), (398, 390), (374, 84) ]) a = np.array([ (0, 1),...
<python><computer-vision><linear-algebra><scikit-image>
2024-02-17 12:18:28
1
5,384
lanery
78,012,016
1,485,877
Equivalent to dlopen(None) in Windows
<p>I am using Python CFFI and want to open a library where I can call <code>free</code> on some data I get back. In Linux and Mac, I put <code>free</code> in the cdefs and load a base C library with <code>dlopen(None)</code>.</p> <pre class="lang-py prettyprint-override"><code>from cffi import FFI header = &quot;&quot...
<python><windows><python-cffi>
2024-02-17 12:01:14
1
9,852
drhagen
78,011,941
887,651
Django application to manage a small Inventory
<p>I have created a very small Django application to manage a very small Inventory.</p> <p>My <strong>models.py</strong> code is:</p> <pre><code>class Inventory(models.Model): account = models.ForeignKey( &quot;accounts.Account&quot;, on_delete=models.DO_NOTHING, null=False, blank=False ) class Invent...
<python><django><django-models>
2024-02-17 11:34:39
2
4,644
Dail
78,011,917
22,437,609
Kivy Buildozer: aiohttp asyncio Issue, App Crashes
<p>I will try to expain my problem exactly. First of all, my kivy app and its all sections works in VScode. It is a calculator app that scrape some datas and calculate them</p> <p><strong>Python version: 3.11.7 Kivy version: 2.3.0</strong></p> <p>I have two functions in my code so i want them to work together at the sa...
<python><python-3.x><kivy><kivymd><buildozer>
2024-02-17 11:25:37
1
313
MECRA YAVCIN
78,011,829
5,025,650
Inconsistent sending and reading of integers via Python serial to an Arduino
<p>I am trying to send Integers via Python and serial communication to an Arduino, read it there, and send it back (solely for debugging) to print via Python.</p> <p>I am getting often either zeros send back, or the integers in wrong orders. I am hitting the wall. I went back to a minimal example and still can't see my...
<python><arduino><serial-port>
2024-02-17 10:58:07
1
321
Nikolaij
78,011,805
5,695,336
Why does boolean indexing reverse the order of axis?
<pre><code>import numpy as np x = np.zeros((5,4,3,2)) i = np.array([[True, False], [False, False], [False, True]]) print(x[4,:,i].shape) # (2, 4) </code></pre> <p>Why is <code>x[4,:,i].shape</code> (2, 4) instead of (4, 2)?</p> <p>The indexing array with the 2 <code>True</code> values is after <code>:</code> which cor...
<python><numpy>
2024-02-17 10:52:41
0
2,017
Jeffrey Chen
78,011,718
13,798,993
Does jax save the jaxpr of jit compiled functions?
<p>Consider the following example:</p> <pre><code>import jax import jax.numpy as jnp @jax.jit def test(x): if x.shape[0] &gt; 4: return 1 else: return -1 print(test(jnp.ones(8,))) print(test(jnp.ones(3,))) </code></pre> <p>The output is</p> <pre><code>1 -1 </code></pre> <p>However, I thoug...
<python><jax><google-jax>
2024-02-17 10:22:53
1
689
Quasi
78,011,566
309,917
How to delete a Datastore database with Google App Engine search data in it without Python 2.7
<p>Trying to delete the <code>(defaut)</code> Datastore database I get this message:</p> <pre><code>400: Database contains Google App Engine search data. To delete this database you must first remove the search data. </code></pre> <p>This data is there, unused, from years and years ago when this project used the Pytho...
<python><google-app-engine><google-cloud-datastore>
2024-02-17 09:22:33
2
12,525
neurino
78,011,332
11,748,924
Construct list of possible sentences from given alphabet quota and wordlist.txt
<p>I have <code>wordlist.txt</code> that separated by new line.</p> <p>If I specify number of quotas to use for each alphabet for example</p> <pre><code>n: 1 e: 1 w: 1 b: 1 o: 2 k: 1 Remain alphabets quota is 0. </code></pre> <p>How to construct a sentence from given quotas of alphabet that must be spent all until zero...
<python><text><anagram>
2024-02-17 07:52:41
1
1,252
Muhammad Ikhwan Perwira
78,011,008
8,760,028
How to return multiline sql queries in Python
<p>I want to run a sql query in a server. And the query is too long, so I am not able to figure out how it should be broken down:</p> <p>The query looks something like this:</p> <pre><code>return(&quot;usr/&lt;path&gt; -e 'select val1 from table_name where val2 = (select val3 f rom another_table where val = 'abc')'&quo...
<python>
2024-02-17 05:11:01
1
1,435
pranami
78,010,889
12,461,032
Pandarallel cannot apply two transformations
<p>I have a pandas data frame (with ~57 million rows of floats) that I want to undergo two transformations.</p> <p>These are the two functions to apply the transformations:</p> <pre><code>def apply_feature_aggregation(df, weights, scale, shift, cores): #This runs without a problem t1 = time.time() pandarallel.i...
<python><pandas><pandarallel>
2024-02-17 03:41:55
0
472
m0ss
78,010,857
2,200,963
How can Metaflow FlowSpec instance be wrapped in a context manager without the context manager getting called twice?
<p>I'm trying to use a context manager to open an <a href="https://sshtunnel.readthedocs.io/en/latest/#example-1" rel="nofollow noreferrer">SSH tunnel forwarder</a> when Metaflow FlowSpec subclass instances are run locally, but somehow instantiating a FlowSpec instance in the context manager calls the context manager t...
<python><ssh-tunnel><contextmanager><netflix-metaflow>
2024-02-17 03:25:12
0
764
datasmith
78,010,770
826,112
How do I pass only a multiprocessing.Array?
<p>When using multiprocessing, why does this, from the <a href="https://docs.python.org/3/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow noreferrer">docs</a>, work...</p> <pre><code>from multiprocessing import Process, Value, Array def f(n, a): n.value = 3.1415927 for i in range(le...
<python><python-3.x><python-multiprocessing>
2024-02-17 02:28:54
1
536
Andrew H
78,010,668
3,788,939
Docker fastapi unable to connect to mysql
<p>I'm new to docker and fastapi and I'm trying to connect fastapi with mysql service but it always say that it cannot connect to mysql in the logs. What am I missing here?</p> <p><strong>.env file</strong></p> <pre><code> API_PATH='api' API_VERSION='v1' FASTAPI_CONTAINER_NAME='app_fastapi' FASTAPI_PORT=8000 REDIS...
<python><mysql><docker><docker-compose><fastapi>
2024-02-17 01:29:10
1
2,108
PenAndPapers
78,010,560
9,582,542
Selenium Driver Proxy wont connect to page Not Secure Error
<p>Using Selenium to try and connect to this page comes up with Internal Server Error. Next to the link on the address bar it says &quot;Not Secure&quot; and it has <strong>https</strong> Crossed out.</p> <pre><code>from zyte_smartproxy_selenium import webdriver browser = webdriver.Edge(spm_options={'spm_apikey': '&lt;...
<python><selenium-webdriver><proxy>
2024-02-17 00:26:41
1
690
Leo Torres
78,010,494
9,582,542
Selenium driver closed when used with a Proxy
<p>I am trying to use Selenium with a proxy to log into a company site. If I dont use Proxy the driver and code works perfectly fine. When I use the proxy the page opens and immediately closes.</p> <pre><code>from selenium import webdriver HOSTNAME = 'proxy.froxy.com' PORT = '9000' HEADLESS_PROXY = HOSTNAME + &quot;:...
<python><selenium-webdriver><proxy>
2024-02-16 23:52:21
1
690
Leo Torres
78,010,354
1,783,732
not able to check a key pressed in Python on macOS without echo
<p>In Python, I wanted to detect a key is pressed without using non-standard third-party libs, on macOS. Here is my test code:</p> <pre><code>import select import sys import termios from time import sleep def is_key_pressed(): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: new_s...
<python><macos><terminal>
2024-02-16 22:56:29
2
1,909
user1783732
78,010,311
1,132,544
Why is package pandas in Juyter unknown?
<p>I‘ve installed Jupyter with <code>brew install jupyterlab</code> on my M1 Mac. I started <code>jupyter lab</code> and created a new notebook. As kernel I‘ve chosen the only available IPython3. I‘ve then tried to import pandas and got unknown module. Afterwards I tried <code>!pip install pandas</code> and got that’s ...
<python><jupyter-notebook><jupyter><ipython>
2024-02-16 22:39:42
0
2,707
Gerrit
78,010,221
3,261,292
Encoding issue with parsing the same text using lxml.etree
<p>I am parsing an HTML script using lxml.etree library. I am facing a weird issue where when I parse the same exact script and get the content using a different XPATH, the encoding of the retrieved text becomes different.</p> <p>Here is a reproducible code:</p> <pre><code>from lxml import etree from io import StringIO...
<python><html><character-encoding><lxml><elementtree>
2024-02-16 22:05:52
0
5,527
Minions
78,010,154
6,466,366
OSError: [WinError 127] after gdal installation
<p>I have just finished installing gdal 3.6 on Windows, and it looks like my django project is getting the file correctly. But when I run django manage.py check, it gives me the following output:</p> <pre><code>File &quot;C:\users\rodri\dev\mymap\.mymap\Lib\site-packages\django\contrib\gis\gdal\libgdal.py&quot;, line 6...
<python><django><pip><gdal><geodjango>
2024-02-16 21:49:12
1
656
rdrgtec
78,010,048
11,665,178
How to make a successful http request in Flutter web from a Python Cloud Function?
<p>I have a very basic python Cloud Function (with CORS enabled) that looks like :</p> <pre><code>@functions_framework.http def function_with_cors_enabled(event): method = event.method endpoint = event.path route_key = method + &quot; &quot; + endpoint logging.info(f&quot;Route key : {route_key}&quot;) ...
<python><flutter><google-cloud-functions>
2024-02-16 21:18:33
1
2,975
Tom3652
78,009,928
1,847,702
use google.cloud python library insidr Github Actions
<p>I need to use the google cloud sdk on pthyon. The code works well on my local environment.</p> <pre class="lang-py prettyprint-override"><code>from google.cloud import translate client = translate.TranslationServiceClient() response = client.translate_text( request={ &quot;parent&quot;: projectI...
<python><google-cloud-platform><github-actions>
2024-02-16 20:44:12
1
833
Carlos Garces
78,009,785
1,616,528
Github action linkcheck not passing due to stackoverflow links
<p>In our documentation, compiled through Sphinx, we have a few links to Stack Overflow answers (to acknowledge the good suggestions found there). We run a link check Action to verify that we don't have broken links, and today all Stack Overflow links started being reported broken, with errors like:</p> <pre><code>Warn...
<python><github><github-actions><documentation><broken-links>
2024-02-16 20:12:00
0
329
matteo
78,009,635
13,086,128
Selecting a single column from a polars DataFrame giving a DataFrame?
<p>Does selecting a single column from a polars DataFrame using <strong><code>select</code></strong> give a DataFrame? If so how to get the series?</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame( { &quot;A&quot;: [1, 2, 3], &quot;B&quot;: [6, 7, 8], ...
<python><dataframe><python-polars>
2024-02-16 19:35:37
1
30,560
Talha Tayyab
78,009,621
1,961,574
run_in_executor causes a TimeoutError that was never retrieved
<p>I've created a program that processes a stream of data coming from a device and writes it to a websocket for consumption by a web app. The library I've written to read from said device and <code>yield</code> its computed values is a synchronous (ergo blocking) library. I don't want to re-write it in async, so I am u...
<python><python-asyncio><tornado>
2024-02-16 19:32:47
1
2,712
bluppfisk
78,009,526
2,107,632
pandas pythonic way of handling dependency on a previous row
<p>I'm facing (yet another time) a situation in <code>pandas</code> where, in a given column, a value in a row <code>n+1</code> depends on a value from the row <code>n</code>. This is quite common and easily handled in Excel, as in the picture attached, where the value in P8 builds on the value from P7.</p> <p>My quest...
<python><pandas><dataframe>
2024-02-16 19:09:46
2
4,998
Simon Righley
78,009,460
5,392,289
Add hyperlink to footer that directs to Table of Contents using ReportLab
<p>The following ReportLab code generates a starting template that I am (almost) pleased with. The missing piece of the puzzle is to add clickable &quot;Back To Contents&quot; text at the left hand side of the footer, on every page.</p> <p>Any footer wizards out there?</p> <pre><code>from datetime import datetime from ...
<python><pdf><footer><reportlab>
2024-02-16 18:56:28
0
1,305
Oliver Angelil
78,008,875
4,734,563
Jupyter AI : There seems to be a problem with the Chat backend,
<p>When I install <a href="https://github.com/jupyterlab/jupyter-ai" rel="nofollow noreferrer">Jupyter AI</a>, the <code>%%ai</code> magic command is working in the code cell, but the Chat user interface is not working and it shows the following message</p> <blockquote> <p>There seems to be a problem with the Chat back...
<python><jupyter><jupyter-lab>
2024-02-16 16:54:26
1
1,890
ASE
78,008,810
11,318,930
polars - processing of 7 GB parquet aborts with segmentation fault
<p>I have a 7 GB <code>.parquet</code> file with a 128M rows of accounting data (which I cannot share) and split in to 53 row groups. My task is to 'clean' the data by retaining in each cell, only specific words from a dictionary. The reading of the file is trouble free. The processing of the file ends in a segmenta...
<python><python-polars>
2024-02-16 16:41:03
0
1,287
MikeB2019x
78,008,758
17,800,932
How do I get multiple OID values in SNMP?
<p>I am using <code>pysnmp</code> installed by the <a href="https://github.com/lextudio/pysnmp" rel="nofollow noreferrer"><code>pysnmp-lextudio</code></a>. I chose this package because it is pure Python and thus cross-platform. Other libraries were either too hard for me to understand or not cross-platform or required ...
<python><snmp><net-snmp>
2024-02-16 16:32:13
1
908
bmitc
78,008,755
18,150,609
Is it safe to use the variable from dictionary comprehension during error handling?
<p>Consider the following example:</p> <pre><code>config_parameters = ['PARAM1', 'PARAM2', 'PARAM3'] sample_config = { 'PARAM1': 'Value1', 'PARAM2': 'Value2' } try: # Collects param values from the sample config config = {k: sample_config[k] for k in config_parameters} except KeyError as e: # Tries...
<python>
2024-02-16 16:31:39
1
364
MrChadMWood
78,008,563
11,167,163
.yml does not install packages from .requirements.txt in the dedicated environment
<p>I have the following which should install packages from <code>requirements.txt</code> in the environment <code>Env_Name</code> which has just been created</p> <pre><code>- script: | python -m venv Env_Name cd Env_Name .\scripts\Activate displayName: 'Create &amp; Activate Env_Name ' - script: | py...
<python><azure-devops><continuous-integration>
2024-02-16 15:56:06
2
4,464
TourEiffel
78,008,454
14,045,537
How to order angular & radial axis labels in Plotly scatter_polar chart?
<p>I have a time series data from which I'm extracting weekday hourly counts. And to visualize the data I came across an <a href="https://echarts.apache.org/examples/en/editor.html?c=scatter-polar-punchCard" rel="nofollow noreferrer">Echart example</a>. Is it possible to create something like the echart example using P...
<python><plotly><visualization><polar-chart>
2024-02-16 15:36:06
1
3,025
Ailurophile
78,008,394
3,224,483
How do I get the line numbers of a saxonc XPath match?
<p>I'm building a report that will show the line numbers of XML elements that match a set of XPaths. I need to support XPath 2.0. Sending the XML to a separate web based processor written in Java or C# is a valid solution, but one I'm avoiding because my entire team works in Python, I want my tool to still work offline...
<python><xpath><saxon><xpath-2.0><saxon-c>
2024-02-16 15:24:06
1
3,659
Rainbolt
78,008,188
7,470,925
Best practice to write Python exception in a log file
<p>I defined a <code>log_text()</code> function to print custom messages and write it in a log file. My project architecture is quite simple, with the main script calling functions from another file:</p> <pre><code>main.py | |--- functions.py -- log_text() </code></pre> <p>I would like to catch any Python exception and...
<python><logging>
2024-02-16 14:50:32
1
1,226
jeannej
78,008,134
10,353,865
What is the difference between these three ways of changing an element in a dataframe?
<p>In the code below please uncomment exactly one line with a hash. Do this for all three possible ways/cases and notice the following:</p> <ul> <li>All cases seem to imply that elements in the original dataframe are changed</li> <li>In my opinion they accomplish the same (except for the fact that the selected elements...
<python><pandas>
2024-02-16 14:42:13
0
702
P.Jo
78,008,086
5,661,667
Numpy slicing given row for each column
<p>I have an ... x n x m array, say <code>a</code>, where ... stands for an arbitrary number of additional dimensions. Let's call the n-dimension &quot;rows&quot; and the m-dimension&quot; columns for simplicity, even though the array is higher-dimensional.</p> <p>I also have a vector <code>v</code> of length n which c...
<python><arrays><numpy><indexing>
2024-02-16 14:32:27
2
1,321
Wolpertinger
78,008,025
11,170,382
How to use a config from pyproject.toml inside pre-commit-config.yaml
<p>I have a python repository which has a pyproject.toml and a pre-commit-config.yaml</p> <p>The pyproject.toml looks something like this</p> <pre class="lang-ini prettyprint-override"><code>[tool.poetry] name = &quot;projectname&quot; description = &quot;My project's description&quot; authors = [&quot;My Name &lt;my-n...
<python><pre-commit-hook><pre-commit><pre-commit.com><pyproject.toml>
2024-02-16 14:24:38
1
453
Saroopashree Kumaraguru
78,008,017
8,792,159
Can scipy.stats.bootstrap be used to compute confidence intervals for feature weighs in regression or classification tasks?
<p>I am interested in computing confidence intervals for my feature weights using a bootstrap approach. Is <code>scipy.stats.bootstrap</code> able to do this? Consider this classification task as an example (but same idea for regression tasks). We can get <code>coefficients</code> which will return a vector of feature ...
<python><scipy><bootstrapping>
2024-02-16 14:23:06
1
1,317
Johannes Wiesner
78,007,995
11,861,874
Clear Content of Excel Using Python
<p>I would like to clear the content of the Excel file using Python and re-write it at the end with different values. I would like to do it while Excel remains open and don't want to close before re-writing it again.</p> <pre><code>import pandas as pd Tab = pd.read_excel(&quot;abc.xls&quot;,sheet_name=&quot;Sheet1&quo...
<python><excel><openpyxl><xlwings>
2024-02-16 14:19:54
1
645
Add
78,007,939
1,023,390
Create numpy array of unit matrices
<p>I have a function that takes a numpy array as argument to represent a physical 3D vector (with <code>shape=(3,)</code>) or an array of such vectors (with <code>shape=(3,n)</code>). In that function I need to form the 3x3 unit matrix or an array of 3x3 unit matrices, depending on the input. Thus</p> <pre><code>def fu...
<python><numpy>
2024-02-16 14:09:55
6
45,824
Walter
78,007,916
7,422,392
Django i18n get_language_info_list and get_available_languages provide different language code
<p>With <code>{% get_current_language as CURRENT_LANGUAGE %} </code>, <code>{{ CURRENT_LANGUAGE }}</code> shows <code>nl-nl</code></p> <p>With <code>{% get_available_languages as AVAILABLE_LANGUAGES %} </code>, <code>{{ AVAILABLE_LANGUAGES }}</code> shows <code>[('nl-NL', 'Nederlands'), ('en', 'Engels')]</code></p> <p>...
<python><django>
2024-02-16 14:05:39
1
1,006
sitWolf
78,007,899
2,386,113
Converting flat indices to 3D indices in Python
<p>I have an array of flat indices and I want to get the corresponding 3D indices. I want to avoid using a for-loop to convert each flat index to a 3D index one by one.</p> <p>I tried to use the numpy's <code>np.unravel_index()</code> method to compute the 3D indices as shown below:</p> <pre><code> import numpy as np...
<python><numpy><indices>
2024-02-16 14:02:44
0
5,777
skm
78,007,858
1,162,465
PBKDF AES Encryption converting Java to python
<p>I have a java code that does encryption decryption , but however there is some issue in getting derivedKEK.</p> <p>In java it is done as</p> <pre><code>derivedKEK = PBKDF2(ENC_KEY, salt, dkLen=32, count=1000, prf=lambda p, s: HMAC.new(p, s, SHA512).digest()) </code></pre> <p>The value I get is of length 32 and the d...
<python><java><encryption>
2024-02-16 13:56:38
0
537
slaveCoder
78,007,791
1,559,401
EOFError while parsing .netrc in CI job for accessing GitLab PyPI package registry
<p>I have a CI job in repo <strong>A</strong> that builds an image (<code>Dockerfile</code> via Kaniko), which requires a package from a package repository from repo <strong>B</strong>.</p> <p>Since this is a task that will repeat in the future quite a bit, I created a GAT (group access token, rights: <strong>api</stro...
<python><gitlab><continuous-integration><.netrc>
2024-02-16 13:48:09
1
9,862
rbaleksandar
78,007,786
9,722,279
set location of .snakemake directory
<p>Is there a way to define where snakemake creates the <em>.snakemake</em> folder. I could change the whole working dic with <code>--directory</code>, however this also changes the storage location of every relative path.</p> <p>I thought <code>--shadow-prefix</code> is what I was hoping for, but <em>.snakemake/script...
<python><shell><symlink><snakemake>
2024-02-16 13:47:39
1
598
kEks
78,007,663
6,224,975
Pytorch reserving way more data than needed
<p>I'm trying to finetune a sentencetransformer.</p> <p>The issue is that I'm running into an OOM-error (I'm using google-cloud to train the model).</p> <p>I keep getting that pytorch reserves ~13GB (theres ~14GB) available thus there's no room for any batch.</p> <p>If I try to calculate the actual memory used, it's ar...
<python><memory><pytorch><sentence-transformers>
2024-02-16 13:24:34
1
5,544
CutePoison
78,007,647
9,506,773
Cannot mimic manual document split in Azure, programatically, using Azure SplitSkill
<p>I am going from a manual setup of my RAG solution in Azure to setting up everything programmatically using the azure python sdk. I have a container with a single <code>pdf</code>. When setting up manually is see that the Document count under the created index is 401 when setting the chunking to 256. When using my cu...
<python><azure-cognitive-services><azure-python-sdk>
2024-02-16 13:22:05
1
3,629
Mike B
78,007,627
17,778,275
Combining multiple sheets in excel file to one
<p>I have a use case where in I have multiple sheets in one excel file [can be any number of files], the columns in each sheets can be any, but I want only &quot;Roll Number&quot;, &quot;Brief&quot; from all the sheets combined with each sheet as a column in the new one.</p> <p>For eg.</p> <p>If &quot;ClassA&quot; is s...
<python><pandas><dataframe><group-by><merge>
2024-02-16 13:19:14
1
354
spd
78,007,405
6,485,881
Aggregating over subsets of columns in Numpy array
<p>I'm trying to compute the aggregate metrics (e.g. mean, median, sum) of column subsets in a numpy array.</p> <p>Take this array for example:</p> <pre><code>1 6 3 4 2 3 4 5 1 4 5 6 3 5 6 7 </code></pre> <p>I have a set of clusters, which are lists of column indices like this:</p> <pre class="lang-py prettyprint-overr...
<python><numpy>
2024-02-16 12:39:50
1
13,322
Maurice
78,007,299
1,009,823
How can I sample from a table with weights
<p>I have a table that looks like this:</p> <pre><code>view weight A 1 B 1 C 2 D 1 E 1 F 1 G 3 </code></pre> <p>I would like to sample from this table, but use the <code>weight</code> column to determine the probability of being chosen. For the above table, A, B, D, E, and F would a...
<python><mysql>
2024-02-16 12:22:18
2
7,617
Robert Long
78,007,071
13,803,549
Django ManyToMany not saving
<p>I have a ModelMultipleChoiceField that I try to save save as ManyToMany relationships and tried almost every solution on the internet but for some reason I can't get mine to save. I don't get any errors and the rest of the form submits just not the ManyToMany.</p> <pre class="lang-py prettyprint-override"><code> ...
<python><django><django-forms><many-to-many>
2024-02-16 11:39:14
1
526
Ryan Thomas
78,007,063
1,506,763
Chained expressions in polars not working
<p>I'm trying to learn a bit about using polars so I had a simple problem to test it out where I ultimately want to run a <code>group_by</code> operation on the data.</p> <p>While analysis the data I create a few extra series from the initial data by adding and then cumulating.</p> <p>I understand that when you want to...
<python><python-polars>
2024-02-16 11:37:42
1
676
jpmorr
78,006,992
4,634,965
very high level embedded Python in C / C++ application is not using Python from activated venv environment
<p>I followed the official Python documentation to do a very high-level Python runtime embedding in my C or C++ application.</p> <ul> <li><a href="https://docs.python.org/3/extending/embedding.html#very-high-level-embedding" rel="nofollow noreferrer">https://docs.python.org/3/extending/embedding.html#very-high-level-em...
<python><c++><c>
2024-02-16 11:25:02
0
693
bue
78,006,930
3,961,495
Matplotlib not plotting figure (not responding) on Windows 10 powershell when using "plt.ion()"
<p>I'm working Windows 10 and I have encountered an issue that I don't have on Ubuntu:</p> <p>From the command line in powershell I run <code>python myscript.py</code> where the scriptp has the following code:</p> <pre><code>from matplotlib import pyplot as plt plt.plot([1,2], [1,1]) plt.ion() plt.show() import pdb p...
<python><matplotlib><emacs><windows-10>
2024-02-16 11:13:05
1
3,127
Ytsen de Boer
78,006,685
19,556,055
Second kivy screen ScreenManager accepts only Screen Widget error
<p>I'm starting out with kivy and trying to write some simple little code to follow along with a video, but already I'm getting errors that he is not. I have the following code...</p> <p><strong>my_tours.kv</strong></p> <pre><code>&lt;MyTours&gt;: Button: text: &quot;Planned trips&quot; ...
<python><kivy>
2024-02-16 10:32:30
1
338
MKJ
78,006,568
10,334,846
Bash command calculates wrong time
<p>I am using bash script and want to do a for loop of time from 3 hours ago to 3 hours later. For example, the pseudo codes follow:</p> <pre><code>time_end = 2000010100 #YYYYMMDDHH time_beg = 1996010100 #YYYYMMDDHH for time_beg -le time_end # while time_beg&lt;=time_end time_tmp ...
<python><linux><bash><shell><datetime>
2024-02-16 10:12:20
0
325
Xu Shan
78,006,473
11,629,296
Find total no of days spent by people from entry and exit day in pandas/python
<p>I have a data frame like this,</p> <pre><code>day entry_persons exit_persons 1 4 0 2 2 1 3 3 4 4 5 0 5 0 1 </code></pre> <p>So basically for 5 days people are entering to and taking exit to a ca...
<python><pandas><dataframe>
2024-02-16 09:56:18
1
2,189
Kallol
78,006,347
4,883,949
Python program freezes when multiprocessing call follows sequential call
<p>I encountered a strange problem with a Python program processing images with the <code>pyvips</code> library. Here is a simplified version of my problem.</p> <p>I try to create a numpy array (coming from zeros in my simple example) several times (2 times in the example).</p> <p>When I do it sequentially, everything ...
<python><multiprocessing><vips>
2024-02-16 09:33:14
0
938
proprit
78,006,246
8,462,809
Pandas dataframe to BQ fail with timestamp column
<p>I encountered with the timestamp format.</p> <p>I want to retrieve current timestamp with a function and use it into a pandas dataframe as below:</p> <pre><code>df['CURRENT_TS'] = pd.Timestamp.now() </code></pre> <p>After that, the DF will be converted to CSV on a GCS bucket. Following this, the csv will be ingested...
<python><pandas><dataframe><google-bigquery>
2024-02-16 09:17:14
1
459
Jonito
78,006,234
1,559,401
Creating Python module from Fortan using CMake and make yields no errors but importing module in Python fails due to undefined symbol
<p>I am receiving</p> <pre><code>Python 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:43:22) [GCC 12.3.0] on linux Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&gt; import foo Traceback (most recent call last): File &quot;&lt;stdin&...
<python><c><cmake><fortran><f2py>
2024-02-16 09:14:58
1
9,862
rbaleksandar
78,006,150
4,704,065
Check element from 1 column is present in another dataframe with different lengths and names
<p>I have 2 DF with different names and lengths but few elements of 1 column from both DF are common.</p> <p>I want to check if a particular element is present in the second DF or not and if present copy the elements of that DF in first DF as a new column</p> <p><strong>result</strong> column in first DF indicates that...
<python><dataframe>
2024-02-16 09:02:07
1
321
Kapil
78,005,989
10,200,497
How to groupby a dataframe by using a column and the last row of the group?
<p>This is my DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame( { 'x': ['a', 'b', 'c', 'c', 'e', 'f', 'd', 'a', 'b', 'c', 'c', 'e', 'f', 'd'], 'y': ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'f', 'f', 'f', 'f', 'g', 'g', 'g'], } ) </code></pre> <p>And this is the output that I want:</p...
<python><pandas><dataframe>
2024-02-16 08:25:27
2
2,679
AmirX
78,005,759
14,388,247
Efficient way to combine two extremely long lists in python
<p>In python, we have two long lists each sorted and with more than around 20 million items and are <strong>different</strong> in <strong>only a few items</strong>.</p> <pre class="lang-py prettyprint-override"><code>list_1 = [ ..., ## 20 million items common between the two lists 'item_a', 'item_b', ] li...
<python><list>
2024-02-16 07:35:54
3
706
nino
78,005,435
14,250,641
How to randomly sample very large pyArrow dataset
<p>I have a very large arrow dataset (181GB, 30m rows) from the huggingface framework I've been using. I want to randomly sample with replacement 100 rows (20 times), but after looking around, I cannot find a clear way to do this. I've tried converting to a pd.Dataframe so that I can use df.sample(), but python crashes...
<python><pandas><large-data><pyarrow><huggingface-datasets>
2024-02-16 06:09:20
1
514
youtube
78,005,434
9,112,151
How to implement __init_subclass__ magic method properly?
<p>I've created a base class:</p> <pre><code>class BaseNewAdapter: def __init_subclass__(cls, /, base_url: str) -&gt; None: cls._base_url = base_url </code></pre> <p>But PyCharm gives me a warning:</p> <blockquote> <p>Signature of method 'BaseNewAdapter.<strong>init_subclass</strong>()' does not match sign...
<python>
2024-02-16 06:09:01
0
1,019
Альберт Александров
78,005,393
395,857
How can I find out the GPT-4 model version when using openai Python library and Azure OpenAI?
<p>I use GPT-4 via <code>openai</code> Python library and Azure OpenAI. How can I find out the GPT-4 model version by using the <code>openai</code> Python library (and not looking at <a href="https://portal.azure.com/" rel="nofollow noreferrer">https://portal.azure.com/</a> because for some Azure OpenAI instances I onl...
<python><version><openai-api><azure-openai><gpt-4>
2024-02-16 05:56:39
1
84,585
Franck Dernoncourt
78,005,200
1,712,287
How to solve problem of "scipy pip installation error in python
<p>When I went to install scipy following error has been found in python. Do you know any way how to solve this problem?</p> <pre><code>pip install scipy </code></pre> <pre class="lang-none prettyprint-override"><code>Collecting scipy Downloading scipy-1.12.0-cp312-cp312-win_amd64.whl.metadata (60 kB) ━━━━━━━━━━...
<python>
2024-02-16 04:39:59
1
1,238
Asif Iqbal
78,005,051
14,771,666
ModuleNotFoundError: No module named 'llama_index.graph_stores'
<p>I am trying to use the <code>NebulaGraphStore</code> class from <code>llama_index</code> via <code>from llama_index.graph_stores.nebula import NebulaGraphStore</code> as suggested by the <a href="https://docs.llamaindex.ai/en/stable/examples/index_structs/knowledge_graph/NebulaGraphKGIndexDemo.html" rel="nofollow no...
<python><langchain><large-language-model><llama-index><nebula-graph>
2024-02-16 03:32:18
2
368
Kaihua Hou
78,004,832
6,466,366
Could not find module 'C:\OSGeo4W\bin\gdal308.dll' (or one of its dependencies)
<p>I'm trying to use GeoDjango + gdal + PostGis in order to create a map application.</p> <p>OSGeo4W is completelly installed, and all the dll files are there</p> <p>When I run this command:</p> <pre><code>python3 manage.py check </code></pre> <p>I get the following result:</p> <pre><code> ^^^^^^^^^^^...
<python><django><postgis><gdal><geodjango>
2024-02-16 01:48:22
1
656
rdrgtec
78,004,822
1,036,582
PyTorch Model always returns Zero Accuracy
<p>I wanted to create a neural network to predict the hypotenuse of a triangle given the other two sides. For this, I use the pythagorean theorem to create 10,000 values which are used to train the model. The problem is that even though my average loss is 0.18, the accuracy is 0%. What am I doing wrong?</p> <pre><code>...
<python><machine-learning><pytorch><neural-network>
2024-02-16 01:41:18
1
373
Movieboy
78,004,735
12,704,700
Thoughts on improving the existing aggregate pyspark code
<p>Here is a spark dataframe i have,</p> <pre><code>+---+----------------------------------+----------+----------+ |id |timestamp |Fname |Lname | +---+----------------------------------+----------+----------+ |1 |2024-01-19T11:52:44.775205Z |Robert |Albert | |1 |2024-01-20T...
<python><performance><apache-spark><pyspark><aggregate>
2024-02-16 01:05:52
1
2,505
Sundeep
78,004,569
11,907,420
Getting exception when trying to delete entity in Milvis vector database using pymilvus
<p>I am working on the python application and I am storing data in Milvus vector database. I have written the following code to delete entity in n Milvus vector database using pymilvus library.</p> <pre><code>def delete_entities(self, collection_name, entity_id): expr = &quot;obj_id in [&quot; + entity_id + &qu...
<python><milvus>
2024-02-16 00:02:04
1
329
Usman Sajid
78,004,262
1,183,804
Loading Pytorch model in C# with Binary Reader
<p>I want to read and study the basic Model Structures of some of the Pytorch models on HuggingFace.</p> <p>NOTE: I do not want to convert the model to Onnx, this is not what I want.</p> <p>I have set the <code>gcAllowVeryLargeObjects</code> so I can load objects larger than 4Gb.</p> <pre><code>&lt;configuration&gt; ...
<python><c#><machine-learning><pytorch>
2024-02-15 22:25:05
0
2,710
Rusty Nail
78,004,175
2,658,228
Python Folium - Combine states in choropleth map of USA
<p>I want to create a custom choropleth map for USA in which instead of showing states individually, I'd like to combine some states together e.g. Louisiana, Mississippi, Alabama, and Arkansas.</p> <p>Below is some sample code with data from Folium github <a href="https://github.com/python-visualization/folium/tree/mai...
<python><python-3.x><folium><choropleth>
2024-02-15 22:04:29
3
2,763
Gautam
78,004,105
746,100
how do i fix PyQt6 import problem on macos?
<p>I'm trying to run my Python3 .pyw script on MacOS which used to run okay, but now gets error.</p> <p>(Could not find solution by Googling)</p> <p>THE CODE IN MY .pyw FILE ...</p> <pre><code>import os import signal from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QApplication import sys from include.BaseDia...
<python><pyqt><pyqt6>
2024-02-15 21:50:38
1
8,387
Doug Null
78,003,863
3,579,198
Dockerfile for azure-search-openai-demo App
<p>I am trying to Dockerise an app which uses the <a href="https://pypi.org/project/Quart/" rel="nofollow noreferrer">Quart</a> package.</p> <p><code>Dockerfile</code>:</p> <pre><code>FROM python:3.11 AS backend-build COPY backend /app/backend WORKDIR /app/backend RUN pip install -r requirements.txt EXPOSE 5000 CM...
<python><docker><dockerfile><quart>
2024-02-15 20:53:42
1
7,098
rp346
78,003,829
2,947,435
pyhon send data to bigquery returns a field mismatch
<p>i'm using python and pandas to push data to BigQuery. The script works well but I have an error:</p> <pre><code>object of type &lt;class 'str'&gt; cannot be converted to int File &quot;/**/bq.py&quot;, line 71, in post job = self.client.load_table_from_dataframe(df, File &quot;/**/tobq.py&quot;, line 99, in &lt;modu...
<python><pandas><google-bigquery>
2024-02-15 20:45:34
1
870
Dany M
78,003,706
4,398,966
How to add a print statement in a complicated expression?
<p>I have the following code:</p> <pre><code>prime_numbers = [ number for number in range(2, 101) if all(number % div != 0 for div in range(2, int(number**0.5) + 1)) ] </code></pre> <p>How would I add a print statement for number?</p>
<python>
2024-02-15 20:14:10
2
15,782
DCR