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,926,528
4,451,521
Why running fire shows a documentation?
<p>Let's reproduce this with a simple script</p> <pre><code>import pandas as pd import fire def nada(): data = { &quot;calories&quot;: [420, 380, 390], &quot;duration&quot;: [50, 40, 45] } #load data into a DataFrame object: df = pd.DataFrame(data) return df if __name__ == &quot;__m...
<python><pandas><jinja2><python-fire>
2024-08-29 07:06:35
1
10,576
KansaiRobot
78,926,325
3,337,089
Replacing stable diffusion v2.1 text encoder with image encoder
<p>I'm trying to replace the text encoder of Stable Diffusion with a corresponding image encoder, so that I can feed images instead of text. The <a href="https://huggingface.co/stabilityai/stable-diffusion-2-1-base" rel="nofollow noreferrer">stable diffusion hugging face documentation</a> says that it uses pretrained t...
<python><encoding><stable-diffusion><latent-diffusion>
2024-08-29 06:01:00
0
7,307
Nagabhushan S N
78,926,127
4,451,521
How can I use a project that has been installed with pip install -e .?
<p>I am using a project (originally from github) that in its readme says:</p> <blockquote> <p>To use:</p> <ol> <li>Clone the project</li> <li>Create a virtual environment</li> <li>Do <code>pip install --upgrade pip</code> and <code>pip install -e .</code></li> </ol> </blockquote> <p>I have tried the project, it is work...
<python><pip><python-venv><python-packaging>
2024-08-29 04:42:44
2
10,576
KansaiRobot
78,926,086
2,981,639
Parsing numeric data with thousands seperator in Polars
<p>I have a tsv file that contains integers with thousand separators. I'm trying to read it using <code>polars==1.6.0</code>, the encoding is <code>utf-16</code></p> <pre class="lang-py prettyprint-override"><code>from io import BytesIO import polars as pl data = BytesIO( &quot;&quot;&quot; Id\tA\tB 1\t537\t2,288 2\t3...
<python><dataframe><csv><python-polars>
2024-08-29 04:18:51
2
2,963
David Waterworth
78,926,051
22,407,544
How to stop a celery task if user unloads?
<p>My website allows users to translate files. I want to add a failsafe in case a user decides to unload the webpage(whether by reloading, navigating away or closing the tab). My backend is django plus celery[redis]. Currently, after a user begins the translation task my frontend polls the backend every 5 seconds to se...
<javascript><python><django><celery>
2024-08-29 03:57:21
1
359
tthheemmaannii
78,925,963
4,921,918
Unexpected value passed to LangChain Tool argument
<p>I'm trying to create a simple example tool that creates new user accounts in a hypothetical application when instructed to do so via a user prompt. The llm being used is llama3.1:8b via Ollama.</p> <p>So far what I've written works, but it's very unreliable. The reason why it's unreliable is because when LangChain c...
<python><langchain><large-language-model>
2024-08-29 02:57:57
1
376
wtfacoconut
78,925,731
4,867,193
Python Multiprocessing Queue, blocks with item remaining
<p>Running two threads with the Multiprocessing library in Python, putting items into a queue in the daughter thread and getting them from the parents, hangs on the last item.</p> <p>The question is why is that happening? And how do we get it to work?</p> <p>The complete code is here. It is for an old USB spectrometer...
<python><multiprocessing>
2024-08-29 00:33:14
1
2,587
DrM
78,925,696
7,583,953
When should I include the score benefit of a local decision when using minimax?
<p>In the <a href="https://leetcode.com/problems/stone-game/" rel="nofollow noreferrer">Stone Game</a> problem, Alice and Bob take turns picking a pile of stones from the start or the end. The goal is to maximize Alice's total</p> <pre><code>def play(turn, left, right): if left &gt; right: return 0 end...
<python><algorithm><minimax>
2024-08-29 00:03:26
2
9,733
Alec
78,925,467
11,163,122
How to have decorated function in a Python doctest?
<p>How can I include a decorated function inside a Python doctest?</p> <pre class="lang-py prettyprint-override"><code>def decorator(func): def wrapper() -&gt; None: func() return wrapper def foo() -&gt; None: &quot;&quot;&quot; Stub. Examples: &gt;&gt;&gt; @decorator &gt;...
<python><unit-testing><doctest>
2024-08-28 22:16:40
1
2,961
Intrastellar Explorer
78,925,465
10,161,315
Find rows where pandas dataframe column, which is a paragraph or list, contains any value in another list
<p>I have a Pandas DataFrame which contains information about various jobs. I am working on filtering based on values in some lists.</p> <p>I have no problem with single value conditional filtering. However, I am having difficulties doing conditional filtering on the <code>Job Description</code> field, which is essenti...
<python><pandas><dataframe><filter>
2024-08-28 22:15:29
1
323
Jennifer Crosby
78,925,432
2,893,712
Pandas Unpack List of Dicts to Columns
<p>I have a dataframe that has a field called <code>fields</code> which is a list of dicts (all rows have the same format). Here is how the dataframe is structured:</p> <pre><code>formId fields 123 [{'number': 1, 'label': 'Last Name', 'value': 'Doe'}, {'number': 2, 'label': 'First Name', 'value': 'John'}] </co...
<python><pandas><dataframe><series>
2024-08-28 22:04:24
3
8,806
Bijan
78,925,412
4,521,319
Finding the K-th largest element using heap
<p>I am trying to solve the leetcode problem: <a href="https://leetcode.com/problems/kth-largest-element-in-an-array/description/" rel="nofollow noreferrer">kth-largest-element-in-an-array</a></p> <p>I know a way to solve this is by using a heap. However, I wanted to implement my own <code>heapify</code> method for pra...
<python><data-structures><logic><heap>
2024-08-28 21:55:48
1
925
Hemanth Annavarapu
78,925,362
3,177,701
QueryObject.ComputeSignedDistanceToPoint with Expression type
<p>I'm trying to include a signed distance constraint/cost in my <code>MathematicalProgram</code> for obstacle avoidance of some predetermined obstacles. I understand from <a href="https://stackoverflow.com/questions/72020785/how-to-implement-collision-constraints-for-trajectory-optimization-in-pydrake">these</a> <a hr...
<python><drake>
2024-08-28 21:34:29
2
5,604
Rufus
78,925,300
7,290,845
Define DLT pipeline that depends on event log
<p>I want to define a table &quot;DEMO&quot; using DLT pipeline. This table includes data from the event log. Here is a simplified and anonymized example of what I want to do. I really need this information, to track my pipelines.</p> <pre><code>def event_log_update_id(): return spark.sql(&quot;select origin.update...
<python><databricks><azure-databricks><dlt>
2024-08-28 21:10:26
1
1,689
Zeruno
78,925,221
4,118,462
In docstring, how to give multiple parameters the same description (using EpyText tags)?
<p>For IDEs where hovering over a function call displays help (e.g. PyCharm), rather than create multiple lines with the same description for multiple parameters ... is there a way to simplify by tagging multiple parameters to use the same description?</p> <p>So instead of this (using EpyText tags) ...</p> <pre><code>d...
<python><pycharm><docstring><epytext>
2024-08-28 20:45:54
1
395
MCornejo
78,925,207
16,462,878
real and imaginary part of a complex number in polar form
<p>I am a bit confused about the proper way to deal with complex <em>number</em>s in polar form and the way to separate its real and imaginary part.</p> <p>Notice that I am expecting as real part the <strong>radius</strong>, as imaginary part the <strong>angle</strong>.</p> <p>The inbuilt <code>re</code> and <code>im</...
<python><sympy><complex-numbers><polar-coordinates>
2024-08-28 20:39:56
2
5,264
cards
78,925,095
12,466,687
How to swap values between two columns based on conditions in Python
<p>I am trying to <strong>switch values</strong> between the <code>Range</code> and <code>Unit</code> columns in the dataframe below based on the <strong>condition that if Unit contains</strong> <code>-</code>, then replace <code>Unit</code> with <code>Range</code> and <code>Range</code> with <code>Unit</code>. To do t...
<python><pandas>
2024-08-28 20:08:18
2
2,357
ViSa
78,924,952
3,753,826
How to scale subplots including images with different aspect ratios?
<p>A minimal version of my problem is the following plot. How do I scale the right panel to have the same height as the left one?</p> <pre><code>import matplotlib.pyplot as plt import numpy as np rnd = np.random.default_rng(123) dx1, dy1 = 3, 2 dx2, dy2 = 3, 4 im1 = rnd.random((dy1, dx1)) im2 = rnd.random((dy2, dx2)...
<python><matplotlib><subplot>
2024-08-28 19:14:37
1
17,652
divenex
78,924,835
20,591,261
Use polars .when() instead joins
<p>I have 3 polars dataframes, one that contains 2 IDS, and the other ones contains an ID and a value. I would like to join the 3 dataframes if the ID of the main table exists on one of the other tables and bring a values from a desired column.</p> <p>My current aproach its just rename each Table ID and then do a <code...
<python><dataframe><python-polars>
2024-08-28 18:40:30
2
1,195
Simon
78,924,831
233,928
How to extract text from a PDF file using python and PyMuPDF
<p>I am trying to write a converter for a pdf file, starting with just text. The goal is to extract:</p> <pre><code>the font the location of the start of each block of text each letter and the relative positions </code></pre> <p>additionally, if possible, I would like to get the current font, and to extract images. I d...
<python><pdf>
2024-08-28 18:39:06
0
8,644
Dov
78,924,799
1,870,832
I can't get Selenium Chrome to work in Docker with Python
<p>I have a classic &quot;it works on my machine&quot; problem, a web scraper I ran successfully on my laptop, but with a persistent error whenever I tried and run it in a container.</p> <p>My minimal reproducible dockerized example consists of the following files:</p> <p>requirements.txt:</p> <pre><code>selenium==4.23...
<python><docker><google-chrome><selenium-webdriver><web-scraping>
2024-08-28 18:31:08
2
9,136
Max Power
78,924,693
6,843,153
Pydantic custom datatype doesn't take values when validating
<p>I have the following <strong>Pydantic v1.10</strong> custom datatype:</p> <pre><code>class SelectionList(ABC): class_selection_list = [] datatype = None @classmethod def __get_validators__(cls): yield cls.validate @classmethod def __modify_schema__(cls, field_schema): field_...
<python><pydantic>
2024-08-28 18:01:11
1
5,505
HuLu ViCa
78,924,539
9,500,769
shadowsocks AttributeError: module 'collections' has no attribute 'MutableMapping'
<p>I was trying to set up an VPN on Vultr via Shadowsocks, and trying to run Shadowsocks service manually. I tried below in my bash:</p> <pre><code>sudo ssserver -c /etc/shadowsocks.json </code></pre> <p>It has error: <strong>AttributeError: module 'collections' has no attribute 'MutableMapping'</strong></p> <p>I am us...
<python><python-3.x><mutablemapping>
2024-08-28 17:18:53
1
2,492
Sky
78,924,379
880,874
Escaping double quotes in an INSERT statement for SQL Server
<p>Using Python 3 and the <code>re</code> module, how can I escape double quotes in an INSERT statement for SQL Server?</p> <p>I've tried a bunch of different ways but SQL Server always throws an error with the formatting.</p> <p>Here is an example:</p> <pre><code>INSERT INTO [events] VALUES ('&lt;span style=\&quot;fon...
<python><sql-server><regex>
2024-08-28 16:34:19
1
7,206
SkyeBoniwell
78,924,206
19,299,757
How to select a dropdown value in selenium python that has input html tags
<p>I am finding it bit difficult to select a value from a dropdown using selenium python. This dropdown has the below html.</p> <pre><code>&lt;input aria-invalid=&quot;true&quot; autocomplete=&quot;off&quot; id=&quot;asset-instrument-sub-type&quot; type=&quot;text&quot; class=&quot;MuiInputBase-input MuiInput-input Mu...
<python><selenium-webdriver>
2024-08-28 15:42:58
0
433
Ram
78,924,163
4,092,887
Get count of unique videos by channel in DataFrame
<p>I'm using Python for playing with some YouTube history data in Google Colab.</p> <p>My intention with this data is to get the <em><strong>amount of videos watched on every channel -counting only the unique videos</strong></em> - that is, a video might have been watched more than once.</p> <p>I've already debugged th...
<python><dataframe>
2024-08-28 15:32:35
1
2,675
Mauricio Arias Olave
78,923,753
5,269,892
Rapidfuzz critical error when using workers != 1
<p>When using the latest version 3.9.6 of <a href="https://rapidfuzz.github.io/RapidFuzz/index.html" rel="nofollow noreferrer">rapidfuzz</a>, I get a critical error when using <em>workers != 1</em>, i.e. I cannot use multi-processing to speed-up string comparisons:</p> <p><em>Process finished with exit code -1073741819...
<python><fuzzy-comparison><rapidfuzz>
2024-08-28 14:04:38
0
1,314
silence_of_the_lambdas
78,923,588
12,775,531
Argo workflow retry a workflow using rest service
<p>I am trying to rerun an Argo Workflow through REST endpoint call. However it says it is Not implemented. Does anyone know how to get around this? And when would this be implemented? As per <a href="https://argo-workflows.readthedocs.io/en/latest/swagger/" rel="nofollow noreferrer">apidocs</a>.</p> <p>The below shoul...
<python><argo-workflows><argo><data-engineering>
2024-08-28 13:25:01
1
2,872
s510
78,923,546
2,051,818
Accessing specific index out of N indices within multiple files with varying length of tensors
<p>Suppose that I have 20000 files, each has a tensor with a different length. the total length in all files is 3814139. I need to access the file that contains the specified index. So for example, if (<code>tensor length of file_0 is 320, tensor length of file_1 is 1036, tensor length of file_2 is 458, ......., tensor...
<python><data-structures><pytorch><pytorch-dataloader>
2024-08-28 13:17:37
1
371
HATEM EL-AZAB
78,923,525
7,471,830
How do I Inject Dependencies in FastAPI's Lifespan Context / startup event?
<p>I'm developing a backend service using FastAPI, and I'm facing issues with dependency injection when trying to perform data processing during the application's startup.</p> <p>Here's a simplified version of my setup:</p> <p>I have a <code>Repository</code> class that depends on a MongoDB database instance, injected ...
<python><dependency-injection><fastapi><inversion-of-control>
2024-08-28 13:11:41
1
831
OOD Waterball
78,923,520
865,220
Filter a pandas row if it is significantly larger than neighbours given that it starts with specific character
<p>I have a dataframe like this</p> <pre><code> Name Year Value 0 Mexico 1961 14357 1 Mexico 1961 15161 2 Mexico 1961 514658 3 Mexico 1962 15559 4 United States of America 1977 21911...
<python><pandas><dataframe>
2024-08-28 13:11:11
1
18,382
ishandutta2007
78,923,480
307,138
How to use @doc in BlackSheep API
<p>Use <code>blacksheep create</code> with the following options to create an example API:</p> <pre><code>✨ Project name: soquestion πŸš€ Project template: api πŸ€– Use controllers? Yes πŸ“œ Use OpenAPI Documentation? Yes πŸ”§ Library to read settings essentials-configuration πŸ”© App settings format YAML </code></pre> <p>This w...
<python><openapi><blacksheep>
2024-08-28 13:01:07
1
20,452
Ocaso Protal
78,923,442
7,713,770
How can I resolve the issue where Django migrations are not applying changes to the database?
<p>I have a Django app and I'm using PostgreSQL for the database. I've added some new properties to my models, and after making these changes, I ran the following commands:</p> <pre><code> python manage.py migrate python manage.py makemigrations </code></pre> <p>A new migration file, 0001_initial.py, was generated wit...
<python><django>
2024-08-28 12:52:12
1
3,991
mightycode Newton
78,923,338
312,140
How to fix the error when try to plot data with pandas?
<p>I have encountered an issue in python source code for <a href="https://github.com/facebookresearch/detr" rel="nofollow noreferrer">DETR model</a> from Facebook(Archived repository). The problem is with pandas when it tries to plot something. I did not see this error before, but I think the pre-installed Google Colab...
<python><pandas><matplotlib>
2024-08-28 12:29:18
1
3,031
Mahdi Amrollahi
78,923,301
1,035,897
How to get all alerts for an alert rule in azure using python client
<p>In my <strong>Python 3.11</strong> program I manage to fetch all <strong>alert_rules</strong> in <strong>Azure</strong> like so:</p> <pre><code>def alert_rules(self, tag:str = None): processed = list() try: rules = list() # List all Metric Alert Rules for rule in self.management_clien...
<python><azure><alert>
2024-08-28 12:20:26
1
9,788
Mr. Developerdude
78,923,273
4,614,404
Compare two boolean arrays considering a tolerance
<p>I have two boolean arrays, <code>first</code> and <code>second</code> that should be mostly equal (up to a <code>tolerance</code>). I would like to compare them in a way that is forgiving if a few elements are different.</p> <p>Something like <code>np.array_equal(first, second, equal_nan=True)</code> is too strict ...
<python><numpy><unit-testing>
2024-08-28 12:13:28
2
2,024
Victor Zuanazzi
78,923,158
1,866,605
Backtesting.py not 100% win rate when using data for AI model
<p>I have been working on a data model to train an AI, in order to ensure that the model is correct before training, etc, I run a backtest.py to make sure it will win all trades, as the data is already there to make it 100% win rate.</p> <p>So this is basically just a way to validate the data model before training. Str...
<python><pandas><back-testing>
2024-08-28 11:46:13
0
1,326
peterpeterson
78,922,304
1,444,073
Qt/PySide6: Add widget to QScrollArea during runtime, not showing up
<p>I have a window with a button and a <code>QScrollArea</code> widget. When the button is pressed, a <code>QLabel</code> is supposed to be added to the <code>QScrollArea</code> widget. However, it's not showing up.</p> <p>I know there are plenty of questions about similar issues. Most suggest using <code>setWidgetResi...
<python><qt><pyside>
2024-08-28 08:39:31
1
4,334
kostrykin
78,922,280
18,139,225
Python Particle simulator in Quan Nguyen's book: Python advanced programming. The code not working for me
<p>I have started reading &quot;Advanced Python Programming&quot;, 2nd ed of Quan Nguyen. The code to simulate particles' circular motion is not working for me. But according to the book, it should work: I wonder if I am missing something. I run it on Windows 11, Python 3.8.12 and VScode or JupyterLab. Nothing seems to...
<python><visual-studio-code><jupyter-lab>
2024-08-28 08:33:03
1
441
ezyman
78,922,047
17,729,094
Non-equi join in polars
<p>If you come from the future, hopefully <a href="https://github.com/pola-rs/polars/pull/18365" rel="noreferrer">this PR</a> has already been merged.</p> <p>If you don't come from the future, hopefully <a href="https://stackoverflow.com/a/78913145/17729094">this answer</a> solves your problem.</p> <p>I want to solve m...
<python><dataframe><python-polars>
2024-08-28 07:29:08
4
954
DJDuque
78,921,222
2,825,403
Polars - unexpected behaviour when using drop_nans() on all columns
<p>I have a simple Polars dataframe with some nulls and some NaNs and I want to drop only the latter. I'm trying to use <code>drop_nans()</code> by applying it to all columns and for whatever reason it replaces NaNs with a literal 1.0.</p> <p>I am confusion. Maybe I'm using the method wrong, but the docs don't have muc...
<python><nan><python-polars>
2024-08-28 01:19:18
1
4,474
NotAName
78,921,119
7,619,353
Python outputs Windows fatal exception: code 0x8001010
<p>I have an automation test framework that is using unittest python framework under the hood. It has been producing a segmentation fault. I isolated it to the usage of a DLL library.</p> <p>I ran my python program with faulthandler enabled to obtain more traceback information on the segmentation fault.</p> <p>My progr...
<python><python-3.x><comtypes><faulthandler>
2024-08-28 00:03:40
1
1,840
tyleax
78,920,958
10,108,726
Create smaller pdfs with pdfkit
<p>In my django project, i am creating pdfs in python using pdfkit library. However my pdfs with 15 pages have 16mb size.</p> <p>my lib</p> <pre><code>pdfkit==1.0.0 </code></pre> <p>How can I reduce its size, considering my code above:</p> <pre><code>import pdfkit from django.template.loader import render_to_string my...
<python><django><pdfkit><python-pdfkit>
2024-08-27 22:37:50
1
654
Germano
78,920,890
825,227
How to rank and reassign values to subset of Python dataframe
<p>Drawing a blank, please advise.</p> <p>Have a dataframe, <code>d</code>:</p> <pre><code> Position Operation Side Price Size 0 0 0 1 0.7288 -17 1 8 0 1 0.7297 -14 2 7 0 1 0.7296 -8 3 6 0 1 0.7295 -426 4 ...
<python><pandas><dataframe>
2024-08-27 22:04:08
0
1,702
Chris
78,920,840
22,407,544
Why does my XMLHttpRequest cancel my background task before reloading the page
<p>I'm trying to send a XMLHttpRequest to my backend if a user chooses to reload the webpage while a task is running on the backend. It is to function like this:</p> <ol> <li>The user starts the task(translation).</li> <li>If the user decides to reload the page or navigate away they should get an alert that the task wi...
<javascript><python><django><redis><celery>
2024-08-27 21:41:37
0
359
tthheemmaannii
78,920,706
25,874,132
finding the number of possible k non-attacking rooks in an NxM chessboard with forbidden tiles?
<p>I have an NxM incomplete chessboard (meaning an NxM chessboard with some tiles missing) and a number k (which is the number of non-attacking rooks I need to place on the board)</p> <p>the inputs of this function are an edge list (which can be thought of as a matrix that starts at index 1 and the top left is the &quo...
<python><permutation><combinatorics><montecarlo>
2024-08-27 20:48:57
1
314
Nate3384
78,920,562
23,260,297
CMake error when building exe with pyinstaller in visual studio 2019
<p>I am building an exe with pysinstaller and everytime I run the command it builds, but visual studio is throwing some warnings/errors at me.</p> <p>my pyinstaller command:</p> <pre><code>pyinstaller --onedir --add-data &quot;config.json;.&quot; file.py </code></pre> <p>The warnings include:</p> <pre><code>CMake Warni...
<python><cmake><visual-studio-2019><pyinstaller>
2024-08-27 20:02:49
0
2,185
iBeMeltin
78,920,522
1,074,942
Django-ninja Webhook Server - Signature Error/Bad Request
<p>I am working on a Django application where I have to develop a webhook server using Django-ninja. The webhook app receives a new order notification as described here: <a href="https://developer.wolt.com/docs/marketplace-integrations/restaurant-advanced#webhook-server" rel="nofollow noreferrer">https://developer.wolt...
<python><django><django-ninja>
2024-08-27 19:50:25
0
618
vsapountzis
78,920,271
11,608,962
Is there a best practice for defining optional fields in Pydantic models?
<p>I'm working with Pydantic for data validation in a Python project and I'm encountering an issue with specifying optional fields in my <code>BaseModel</code>.</p> <pre class="lang-py prettyprint-override"><code>from pydantic import BaseModel class MyModel(BaseModel): author_id: int | None # Case 1: throws err...
<python><fastapi><pydantic>
2024-08-27 18:17:26
2
1,427
Amit Pathak
78,920,262
1,337,007
Handling Custom Exceptions in step functions for glue
<p>I have a <code>glue</code> job in which I have created a <code>custom exception</code> named <code>RetryableException</code> and <code>NonRetryableException</code>. I want to retry only in case of <code>RetryableException</code> and <code>DLQ</code> for <code>NonRetryableException</code>. However according to the <a...
<python><amazon-web-services><pyspark><aws-glue><aws-step-functions>
2024-08-27 18:15:51
0
2,258
ghostrider
78,920,220
13,689,939
Why is .* not matching full string in Python regex?
<p>Running this code:</p> <pre><code>my_string = 'START\r\nwords\t&quot; Quoted Words&quot;\r\nmore12345\t$$symbols\r\n END' pattern = '(.*)' matches = re.match(pattern, my_string) matches.groups(0) </code></pre> <p>I expect the output:</p> <pre><code>('START\r\nwords\t&quot; Quoted Words&quot;\r\nmore12345\t$$symbols\...
<python><regex>
2024-08-27 17:58:43
1
986
whoopscheckmate
78,920,216
10,203,572
Optimizing Point Cloud to Voxel Grid with Max Sampling in NumPy
<p>I have two arrays that represent the point coordinates and values respectively. To max sample from this point cloud, I am initializing a grid with the desired size, and looping over each point to assign the max values:</p> <pre><code>N = 1000000 coords = np.random.randint(0, 256, size=(N, 3)) vals = np.random.rand(N...
<python><numpy><open3d>
2024-08-27 17:56:59
1
1,066
Layman
78,920,140
12,466,687
Unable to convert text into dataframe in python
<p>I am trying to convert a <code>text</code> into a <code>dataframe</code> using Python.</p> <p><strong>sample_text:</strong> <code>'This is \nsample text\n\nName|age\n--|--\n1.abc|45\n2.xyz|34'</code></p> <p><strong>Final Desired output:</strong></p> <p><a href="https://i.sstatic.net/zOfSy2Y5.png" rel="nofollow noref...
<python><pandas><markdown><pdf-parsing>
2024-08-27 17:38:17
3
2,357
ViSa
78,919,946
11,942,492
How to allow _inplacevar_ operations in RestrictedPython?
<p>Expressions such as:</p> <pre><code>total_impact += impact </code></pre> <p>in my restricted env are not allowed by default and they cause the error:</p> <blockquote> <p>NameError: name '_inplacevar_' is not defined</p> </blockquote> <p>but I would like to allow such expressions. Is there anything that I can add to ...
<python><in-place><restrictedpython>
2024-08-27 16:38:33
1
1,289
Menas
78,919,927
5,957,195
How to debug a dylib error or compiler bug in a Python-C-API function wrapper?
<p>I am writing a Python wrapper for a C function but I have some very strange behaviour. The C code is:</p> <pre class="lang-c prettyprint-override"><code>static PyObject* f12_wrapper(PyObject* self, PyObject* args, PyObject* kwargs) { PyObject* y_obj; void* y_data = NULL; int64_t y_shape[1]; int64_t y...
<python><c><macos><python-c-api>
2024-08-27 16:33:57
1
482
bourneeoo
78,919,818
15,297,204
Embedding using the LangChain_AWS is giving None value
<p>I am trying to embed a text using the <code>langchain_aws</code> <code>BedrockEmbeddings</code>, but when I invoke the function, I get a list with the <code>None</code> values.</p> <p>Here's the code:</p> <pre><code>from langchain_community.llms.bedrock import Bedrock from langchain_aws import BedrockEmbeddings imp...
<python><langchain><large-language-model><embedding><amazon-bedrock>
2024-08-27 16:05:02
1
521
Md Tausif
78,919,713
1,195,803
Yocto recipe for custom python module
<p>I'm having a very hard time trying to find an example of building in a custom python module into Yocto (more specifically Xilinx's Petalinux) that will install into the python site-packages directory so I can write Python scripts on-target using my module.</p> <p>This is what I have so far:</p> <h2>Directory tree</h...
<python><yocto><bitbake><petalinux>
2024-08-27 15:42:28
2
541
justynnuff
78,919,691
638,048
hvplot reset axis to range of selected data when using dropdown
<p>When using hvplot, the range of the y axis is calculated from all the data, which means that if you use the &quot;by&quot; keyword to get a dropdown option, the axis does not change. If one variable in your data has a numerically much smaller range than another, then you can't see the values of the variable with the...
<python><python-xarray><hvplot><holoviz>
2024-08-27 15:38:15
1
936
Richard Whitehead
78,919,675
1,176,573
How to plot bar graph with button for multiple categories?
<p>For a given dataframe, I am trying to create <code>plotly</code> plot a comparative bar graph with <code>q1,q2..</code> on the x-axis, and barline for each <code>stockname</code> and the figures on y-axis.</p> <p>Additionally, a button should have <code>[Sales, Net Profit]</code> selectors so that when an option is ...
<python><plotly>
2024-08-27 15:34:31
1
1,536
RSW
78,919,574
6,843,153
How to declare a Pydantic field which content is constrained by a list that is known until execution time
<p>I have the following <strong>Pydantic v1.10</strong> model:</p> <pre><code>from typing import Literal from pydantic import BaseModel, Field from connectors.snowflake.snowflake_connector import SnowflakeConnector conversion = SnowflakeConnector().get_conversion()[&quot;conversion_name&quot;].tolist() class MyMod...
<python><pydantic>
2024-08-27 15:12:11
2
5,505
HuLu ViCa
78,919,353
561,243
Ternary plot with python-ternary: unable to set axis label and set axis limits
<p>I am using <a href="https://github.com/marcharper/python-ternary" rel="nofollow noreferrer">python-ternary</a> to generate a ternary plot with some of my data.</p> <p>I have two problems. One rather simple, I guess, and one I can't really understand.</p> <p>Here below is my piece of code.</p> <pre class="lang-py pre...
<python><matplotlib>
2024-08-27 14:22:57
1
367
toto
78,919,274
3,873,799
Class method implemented in parent class returning the name of the child class
<p>I would like to create a class method, or an abstract method, in a parent class. This method should return the implementer class's name.</p> <p>For example, using a class method:</p> <pre class="lang-py prettyprint-override"><code>class TestParentClass(): somefield = &quot;&quot; # create a method to ge...
<python>
2024-08-27 14:05:12
3
3,237
alelom
78,919,150
2,950,593
Django store variable betrween user requests
<p><strong>Short version:</strong></p> <p>How do one store a variable in memory in django and make it shareable between different users ?</p> <p><strong>Long story:</strong></p> <p>I've written some api using django, and django-ninja This api uses third party library that helps me to connect to telegram account (librar...
<python><django>
2024-08-27 13:27:34
0
9,627
user2950593
78,918,962
8,264,792
How to ignore "unused expression" warning from Pylance when using bit-shift operator to compose relationships in airflow
<p>I am currently developing Airflow DAGs using Python. I am using:</p> <ul> <li>Mypy version: 1.8.0</li> <li>Python version: 3.11.9</li> <li>VSCode version: 1.92.2</li> <li>Pylance version: v2024.8.2</li> </ul> <p>When I use the bit-shift operator to compose the relationships between different Operators, I have this w...
<python><visual-studio-code><airflow>
2024-08-27 12:44:45
2
436
maje
78,918,674
7,337,491
why does the request work if I'm using Invoke-RestMethod but it doesn't if I'm using requests from python?
<p>The Invoke-RestMethod looks like:</p> <pre><code>Invoke-RestMethod -Uri 'url' -Method 'GET' -Headers $headers </code></pre> <p>The header contains a bearer token</p> <p>The python code looks like:</p> <pre><code>import requests url = &quot;some_url&quot; headers = { 'Authorization': 'Bearer &lt;token&gt;' } res...
<python><ssl><invoke-restmethod>
2024-08-27 11:36:51
0
1,340
cristian hantig
78,918,585
6,930,340
Count same consecutive numbers in list column in polars dataframe
<p>I have a <code>pl.DataFrame</code> with a column comprising lists with integers. I need to assert that each consecutive integer is showing up two times in a row at a maximum.</p> <p>For instance, a list containing <code>[1,1,0,-1,1]</code> would be OK, as the number 1 is showing up max two times in a row (the first ...
<python><dataframe><python-polars>
2024-08-27 11:11:45
3
5,167
Andi
78,918,540
2,228,771
How to fix/configure Python syntax highlighting?
<p>Python syntax highlighting has recently stopped working correctly, even without any extensions enabled.</p> <p>Is there a way to configure this? I cannot find any good resources on this, other than extensions providing custom syntax highlighting. This is something that is shipped with VSCode out of the box, so I wou...
<python><visual-studio-code>
2024-08-27 10:58:17
1
24,848
Domi
78,918,376
5,457,202
Measure temperature of raw image in DJI SDK
<p>I'm learning how to use the DJI SDK in Python scripts to analyse the content of thermographies (radiometric JPGs, R-JPG).</p> <p>According to the docs, calling the SKD with the &quot;measure&quot; option should produce a &quot;global temperature value image which pixel type is INT16 or FLOAT32.&quot;</p> <pre><code>...
<python><image><matplotlib><dji-sdk>
2024-08-27 10:21:20
1
436
J. Maria
78,918,133
1,652,631
Django Viewflow - Passing field values via urls upon process start
<p>Is it possible *<strong>*</strong>, to pass a value to a process via the startup url/path.</p> <p>I have a process model with a <code>note</code> field.</p> <p>I want to start a new process flow and pass the note to the url e.g.</p> <p><code>http://server.com/my_process/start/?note=mynote</code></p>
<python><django><django-viewflow>
2024-08-27 09:31:22
1
3,731
Tooblippe
78,918,066
7,850,808
Using Jax Jit on a method as decorator versus applying jit function directly
<p>I guess most people familiar with jax have seen this example <a href="https://jax.readthedocs.io/en/latest/faq.html#how-to-use-jit-with-methods" rel="nofollow noreferrer">in the documentation</a> and know that it does not work:</p> <pre class="lang-py prettyprint-override"><code>import jax.numpy as jnp from jax impo...
<python><python-decorators><jax>
2024-08-27 09:14:31
1
527
Stackerexp
78,917,944
10,115,847
Can I "extract" python virtualenv site-packages from one machine to another to avoid using pip?
<p>I wish to create python virtual environment on different Linux machines that do have <code>python-venv</code> module installed but no pip, and no internet access.</p> <p>My idea is to create python virtual-env using <code>python3 -m venv --without-pip my-venv-name</code> for python3 or <code>python -m virtualenv --n...
<python><python-3.x><pip><virtualenv><python-venv>
2024-08-27 08:51:08
1
3,920
Or Yaacov
78,917,847
1,788,712
TypeError: 'DataLoader' object is not subscriptable in SuperGradients Trainer
<p>I've created DataLoader objects for my training and validation datasets, but when I try to pass them to the trainer.train() method, I get the following error:</p> <p>Log summary:</p> <pre><code>TypeError: 'DataLoader' object is not subscriptable </code></pre> <p>Full log trace:</p> <pre><code>[2024-08-27 07:35:44] W...
<python><machine-learning><deep-learning><pytorch><dataloader>
2024-08-27 08:28:38
2
721
Jonathan Molina
78,917,766
5,931,672
Tensorflow in pip list but fail to import
<p>I built, with much effort, tensorflow 2.10.1 from source.</p> <pre><code>$ pip list -v | grep tensorflow tensorflow 2.10.1 /home/abarrachina/.local/lib/python3.9/site-packages pip tensorflow-estimator 2.10.0 /home/abarrachina/.local/lib/python3.9/site-packages pip ...
<python><tensorflow><build>
2024-08-27 08:09:21
1
4,192
J Agustin Barrachina
78,917,424
20,732,098
Remove Gaps in Chart
<p>I have the following diagram: <a href="https://i.sstatic.net/VOV8ekth.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VOV8ekth.png" alt="enter image description here" /></a></p> <pre><code>data = { 'start': ['2024-08-02 08:00', '2024-08-02 09:00', '2024-08-02 18:50'], 'ende': ['2024-08-02 09:...
<python><plotly>
2024-08-27 06:37:20
2
336
ranqnova
78,917,359
6,649,616
How to delete a Django model file without restarting the server and trigger migrations?
<p>I'm working on a Django application where I need to programmatically delete a model file (e.g., <em>my_app/models/my_model.py</em>) and then run migrations, all without restarting the server. However, after deleting the file and running makemigrations, Django doesn't recognize any changes and doesn't generate a migr...
<python><django><django-models>
2024-08-27 06:17:25
1
321
johnny94
78,917,252
7,700,802
Creating columns from a column that contains a list of dictionaries
<p>I have a dataframe that has a column with a list of dictionaries that look like this object</p> <pre><code>[{'MetricName': 'test:mean_wQuantileLoss', 'Value': 1.0935583114624023, 'Timestamp': datetime.datetime(2022, 10, 20, 7, 45, 6, tzinfo=tzlocal())}, {'MetricName': 'train:loss:batch', 'Value': 3.0625627040...
<python><pandas><dictionary-comprehension>
2024-08-27 05:33:50
1
480
Wolfy
78,917,115
139,150
Count of pages found in google search
<p>I am looking for the count of pages where search term &quot;indieea&quot; is found. Visited this page:</p> <p><a href="https://www.google.com/search?q=%22indieea%22" rel="nofollow noreferrer">https://www.google.com/search?q=%22indieea%22</a></p> <p>Goto the last page in search results. You get this line...</p> <pre>...
<python><web-scraping><playwright><playwright-python>
2024-08-27 04:25:59
2
32,554
shantanuo
78,917,083
8,176,763
dockerfile pip error cannot find versions for packages in requirements.txt
<p>I have a dockerfile like this:</p> <pre><code>FROM nexus3/docker-hub/apache/airflow:slim-2.10.0-python3.11 ENV PIP_CONFIG_FILE=/home/airflow/pip.conf ENV AIRFLOW_VERSION=2.10.0 RUN --mount=type=secret,id=pip,target=/home/airflow/pip.conf,uid=50000,required=true \ --mount=type=bind,source=requirements.txt,targe...
<python><docker><pip><airflow>
2024-08-27 04:07:29
0
2,459
moth
78,917,073
1,559,401
How to resolve relative module imports in Python when calling from an arbitrarily located script?
<p>I have a submodule that I would like to use. The structure of my project can be boiled down to</p> <pre><code>*/ β”œβ”€β”€ samples/ β”œβ”€β”€ scripts/ β”‚ └── script.py # contains &quot;from ai_model import AiModel&quot; β”œβ”€β”€ model/ # submodule, branch=main β”œβ”€β”€ models/ # with __init__.py β”‚ β”œβ”€β”€ base_model.py β”‚ ...
<python>
2024-08-27 04:03:14
1
9,862
rbaleksandar
78,916,962
4,852,094
Using an enum to allow for a class instance to be using as a Generic Value
<p>I noticed mypy will not raise an error when you provide a class instance for a generic type if you set the instance to an enum value first. At times it would be useful to provide a literal class instance to identify the type of an object.</p> <pre class="lang-py prettyprint-override"><code>class MyKlass(): pass...
<python><enums><python-typing>
2024-08-27 03:00:34
0
3,507
Rob
78,916,879
3,155,240
Cryptography Fernet prevents my windows service from starting
<p>As per the title - here is my reproducible example (be sure to change the path to the logging file):</p> <p><em>my_service.py</em></p> <pre><code>import logging logging.basicConfig(filename=r'C:\path\to\where\windows\service\is\service_log.txt', level=logging.DEBUG) import os import sys import time import multiproc...
<python><python-3.x><cryptography><windows-services>
2024-08-27 02:35:44
1
2,371
Shmack
78,916,760
2,084,503
Does PyPI no longer allow uploads with username and password?
<p>I've just republished one of my packages, but to do so, I had to give the username as <code>__token__</code> and use an API Token I generated from the website as my password. Is there another way to authenticate when I publish? The error reads</p> <pre><code>100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.1/19.1 kB...
<python><pypi>
2024-08-27 01:31:01
1
1,266
Pavel Komarov
78,916,679
14,222,808
Best way to deal with Nulls in python
<p><strong>Background</strong>: I have a Python data frame with some null values. I'm trying to impute the value of the nulls in a repeatable/automated way.</p> <p><strong>Details</strong>: I have a data frame of inflation values for 2000 products in 150 countries. Unfortunately, I have a lot of null values. I can a...
<python><pandas><null>
2024-08-27 00:38:48
2
315
Jonathan Hay
78,916,677
3,782,816
Using python AST to traverse code and extract return statements
<p>I have a python script that I am trying to &quot;decode&quot; as it were so that I can cast it as an xml, but for this exercise I am just trying to get my head around using ast.walk() and how best to get info out of it. Below is a very simple function that I wrote to simple_if.py and what I am trying to do is extrac...
<python><abstract-syntax-tree>
2024-08-27 00:37:34
2
301
user3782816
78,916,455
1,475,548
What is the correct syntax for an sshtunnel from Python?
<p>I am trying to open an ssh tunnel from Python, but I cannot seem to get the syntax correct.</p> <p>Essentially, I want to do the following, except from within Python:</p> <pre><code>ssh -i /path/to/my/private.ca.key -L 3306:127.0.0.1:3306 user@ourserver.com </code></pre> <p>When I enter that line directly in bash it...
<python><ssh-tunnel>
2024-08-26 22:17:47
1
8,335
Octopus
78,916,428
13,764,824
Parallel requests gets slow when the list grows
<p>I have created an application using FastAPI that basically exposes a POST route and execute few external requests for each incoming request.</p> <p>The code is really simple:</p> <pre><code>from fastapi import FastAPI from src.utils.logger import create_logger import aiohttp import asyncio logger = create_logger(_...
<python><python-asyncio><aiohttp>
2024-08-26 22:06:58
0
949
placplacboom
78,916,373
6,843,153
How to know which fields in pydantic model are flagged as 'exclude=True'
<p>I need to create a data object in execution time that maps the schema of a <strong>Pydantic v1.10</strong> model that might vary depending on user inputs. This is the example of one of those models:</p> <pre><code>class MyModel(BaseModel): field_1: str = Field(alias=&quot;Field 1&quot;) field_2: str = Field(...
<python><pydantic>
2024-08-26 21:43:22
1
5,505
HuLu ViCa
78,916,293
7,700,802
sagemaker list_training_jobs not returning all completed jobs
<p>I wrote this function</p> <pre><code>def list_completed_training_jobs(): &quot;&quot;&quot;Lists completed SageMaker training jobs.&quot;&quot;&quot; sagemaker = boto3.client('sagemaker', region_name=&quot;us-east-1&quot;) response = sagemaker.list_training_jobs( StatusEquals='Completed', ...
<python><boto3><amazon-sagemaker>
2024-08-26 21:05:19
1
480
Wolfy
78,916,247
13,944,524
`assert_never()` fails on match-casing a custom class with an enum field
<p>Here is the code to reproduce:</p> <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass from enum import StrEnum, auto from typing import assert_never class RGBColor(StrEnum): RED = auto() BLUE = auto() GREEN = auto() @dataclass class FooData: number: int color: RGB...
<python><pattern-matching><python-typing><mypy><pyright>
2024-08-26 20:48:10
0
17,004
S.B
78,916,208
1,329,652
Whye does Python ctypes GetClassInfoW return corrupt class name?
<p><code>GetClassInfoW</code> accessed via ctypes on Python 3.12.5 returns a corrupt class name:</p> <pre><code> wndclassa = WNDCLASSA() user32.GetClassInfoA(hInstance, b'BarClass', wndclassa) print(wndclassa.lpszMenuName) print(wndclassa.lpszClassName) wndclassw = WNDCLASSW() user32.GetClas...
<python><windows><winapi><ctypes>
2024-08-26 20:35:44
0
99,011
Kuba hasn't forgotten Monica
78,915,972
1,914,781
drop row with 3 columns value equal
<p>I would like to drop the row with all three columns have equal value. e.g.</p> <pre><code>import pandas as pd data = [ ['A',2,2,2], ['B',2,2,3], ['C',3,3,3], ['D',4,2,2], ['E',5,5,2] ] df = pd.DataFrame(data,columns=['name','val1','val2','val3']) print(df) </code></pre> <p>In above example...
<python><pandas>
2024-08-26 19:11:42
2
9,011
lucky1928
78,915,951
6,930,340
Find the index of the first non-null value in a column in a polars dataframe
<p>I need to find the first non-null value in a column over a grouped <code>pl.DataFrame</code>.</p> <pre><code>import polars as pl df = pl.DataFrame( { &quot;symbol&quot;: [&quot;s1&quot;, &quot;s1&quot;, &quot;s2&quot;, &quot;s2&quot;], &quot;trade&quot;: [None, 1, -1, None], } ) shape: (4, ...
<python><dataframe><python-polars>
2024-08-26 19:04:18
1
5,167
Andi
78,915,940
1,473,517
Correct code to do golden section search over integers
<p>I have an expensive function <code>f</code> which is unimodal and I want to find its minimum. However f is only defined at integer values. I read that <a href="https://en.wikipedia.org/wiki/Golden-section_search" rel="nofollow noreferrer">golden section search</a> is the right thing to do. My implementation which i...
<python><optimization><minimization>
2024-08-26 18:59:30
1
21,513
Simd
78,915,880
4,473,615
Transpose a column in pandas DataFrame
<p>I have a below dataframe, I'm trying to transpose the data based on the column Place. For each list of value in Place column, I need to generate a each row.</p> <pre><code>Language Capital Place Tamil Chennai ['Chennai', 'Vellore', 'Trichy', 'Madurai'] Kerala Kochi ['Kochi', 'Trivandrum'] </code><...
<python><pandas><dataframe><transpose>
2024-08-26 18:34:38
2
5,241
Jim Macaulay
78,915,747
2,383,070
How to right split n times in python polars dataframe (mimic pandas rsplit)
<p>I have a column of strings where the end portion has some information I need to parse into its own columns. Pandas has the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.rsplit.html" rel="nofollow noreferrer">rsplit</a> function to split a string from the right, which does exac...
<python><python-polars>
2024-08-26 17:53:38
3
3,511
blaylockbk
78,915,695
1,361,752
Python temporary directory "access is denied" error for external subprocesses on Windows
<p>I want to create a temporary folder on windows using <code>tempfile.TemporaryDirectory</code>, and use <code>subprocess</code> to execute an external program that will use that temporary directory. This does not seem to work starting in python 3.12 (I have done most testing in 3.10 without issue, and a quick check o...
<python><windows><subprocess><temporary-files><python-3.12>
2024-08-26 17:37:36
0
4,167
Caleb
78,915,581
14,130,365
Extracting text from a pdf file with differents strcuture failed how to properly do it Not all texts is extracted , just a portion is extracted
<p>I am trying to extract text from CV in pdf extension. I come up with this script but I have a problem. The script does not extract all the text and I have problem to identify different block of the document. Here is the script below following by the result and the pdf file as an example.</p> <pre><code> import fitz ...
<python><pdf><text-extraction><pymupdf>
2024-08-26 17:01:23
0
363
emma
78,915,499
2,223,505
Poetry Pytest - ModuleNotFoundError databricks extras
<p>I hit a confusing difficulty running pytest where a package has a 'package extras' dependency:</p> <pre class="lang-bash prettyprint-override"><code>poetry add &quot;databricks-sql-connector[sqlalchemy]&quot; </code></pre> <p>This module is imported in my package like so:</p> <pre class="lang-py prettyprint-override...
<python><pytest><databricks><python-poetry>
2024-08-26 16:37:32
1
2,017
Merlin
78,915,360
769,933
create polars array series sharing data with numpy array, with unpredictable offsets
<p>I'm working with &quot;records&quot; that are represented by ~1,000 sample arrays. I have millions of these records, so they take up a fairly significant amount of memory, often exceeding what is available on a pc if one is not careful. I would like to work with polars dataframe with a column with the array datatype...
<python><arrays><numpy><python-polars><pyarrow>
2024-08-26 16:02:18
2
2,396
gggg
78,915,342
6,654,730
Multi-architecture docker image with Python / Selenium / Chrome or Firefox
<p>I'm trying to install selenium / chromedriver on my Python image for an app. I've tried many different iterations, but nothing seems to work.</p> <p>requirements.txt</p> <pre><code>selenium==4.23.1 webdriver-manager==4.0.2 </code></pre> <p>I'm on Apple silicon. This is my Dockerfile. It's a bit of a mess now, becaus...
<python><selenium-webdriver>
2024-08-26 15:57:37
2
7,670
M3RS