QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
⌀
77,846,354
1,645,339
LLAMAINDEX - /pytorch/aten/src/ATen/native: indexSelectSmallIndex: block: [18,0,0], thread: [31,0,0] Assertion `srcIndex < srcSelectDimSize` failed
<p>I have problem with LLAMAINDEX</p> <blockquote> <p>/opt/pytorch/pytorch/aten/src/ATen/native/cuda/Indexing.cu:1237: indexSelectSmallIndex: block: [18,0,0], thread: [31,0,0] Assertion <code>srcIndex &lt; srcSelectDimSize</code> failed.</p> </blockquote> <p>loading data</p> <pre><code>from llama_index import SimpleDir...
<python><pytorch><llama><llama-index>
2024-01-19 13:18:12
1
7,777
venergiac
77,846,264
5,616,309
jpype dbapi2 : ClassNotFoundException error on python
<p>I want to run SQL on an IBM i database from <strong>python</strong>, with jpype and jdbc. The problem I have must be from jpype, all seems correct (the informations that I print from my program), but I have a &quot;ClassNotFoundException'. I downloaded and installed in my folder IBM's jar (jt400-20.0.6.jar) Then I ...
<python><ibm-midrange><jpype>
2024-01-19 13:01:37
0
1,129
FredericP
77,846,176
10,576,777
Pytest not working in VSCODE, after installing the package in venv
<p>I'm trying to run pytest which worked in pycharm, but can't manage to run it on vscode.</p> <p>First I'm doing:</p> <pre><code>python -m venv env </code></pre> <pre><code>env\Scripts\activate </code></pre> <pre><code>python -m pip install --upgrade pip </code></pre> <pre><code>pip install selenium webdriver-manager ...
<python><visual-studio-code><pytest>
2024-01-19 12:46:56
2
447
A-Makeyev
77,846,144
353,337
np.argsort with duplicate entries: make deterministic?
<p>When <code>argsort</code>ing a numpy entry with duplicate entries, the output isn't deterministic, e.g., from</p> <pre class="lang-py prettyprint-override"><code>import numpy as np print(np.argsort([4, 2, 0, 6, 4, 3, 7, 6, 5, 7, 1, 2])) </code></pre> <p>I sometimes get</p> <pre class="lang-py prettyprint-override">...
<python><numpy><sorting>
2024-01-19 12:39:58
0
59,565
Nico Schlömer
77,846,105
8,916,031
One-liner to delete any line that starts with a number not followed by a delimiter
<p>This two-line python code works. Can it be made concise? Thanks.</p> <pre><code>temp_test_001 = ''' Test 1,2,3, 41 Test 5,6,7, 8800 8800 8800 8800. 8800.0 8,800 Test 9,10 Test 11,12 '''.split('\n') lines = '' for line in enumerate(temp_test_001): lines += [line[1] + '\n',''][line[1].isnumeric()] print(lines) Tes...
<python><regex><windows><text><sed>
2024-01-19 12:32:57
2
1,503
Krantz
77,845,942
1,222,823
Avoid adding file and folder names to a module's namespace
<p>Is there a way to avoid adding file and folder names to a module's namespace? With the following structure:</p> <pre><code>├── pkg │   ├── __init__.py │   ├── folder │   │   └── func2.py │   └── func1.py </code></pre> <p><code>__init__.py</code>:</p> <pre><code>from .func1 import a from .folder.func2 import b </code...
<python><import><module><subdirectory>
2024-01-19 12:05:28
1
345
mrtasktat
77,845,848
13,147,413
GroupBy, column selection and mean in Polars
<p>I'm trying to translate this pandas statement:</p> <pre><code> df.groupby(['X', 'Y'])['Z'].mean() </code></pre> <p>to polars, but i'm stuck at this point:</p> <pre><code> df.group_by(['X', 'Y'], maintain_order=True).select(pl.col('Z').mean()) </code></pre> <p>where i get this error:</p> <pre><code> AttributeError...
<python><dataframe><python-polars>
2024-01-19 11:50:10
1
881
Alessandro Togni
77,845,797
11,149,943
Count how many unique values there are in each row of a matrix (2d array) in Python
<p>I have a 2d array and I would like find how many unique values there is in each row. For example:</p> <pre><code>arr = np.array([[3,4,4,4,3,4], [4,4,4,4,4,4], [3,3,3,2,3,2], [2,3,3,1,2,2]]) </code></pre> <p>Then the output that I desire to obtain would be:</p> <pre><...
<python><numpy><matrix><multidimensional-array><unique>
2024-01-19 11:42:42
3
331
Diego Ruiz
77,845,774
8,176,763
bulk insert into postgres db using fastapi and returing ids
<p>My goal is to insert values in a db table using fastapi <code>post</code> method and return the primary key <code>id</code> from the db auto generated ids as a response model. I have successfully executed the post method but I'm not returning anything, how can i return this data ?</p> <p>This is my <code>models.py</...
<python><fastapi><pydantic>
2024-01-19 11:38:31
1
2,459
moth
77,845,666
7,054,518
trying to place two pyspark dataframes side by side
<p>I'm trying to join to dataframes side by side, they don't have any column in common</p> <p>I have tried below code but doesn't seem to get proper output</p> <pre><code>from pyspark.sql.functions import monotonically_increasing_id df_assembled = df_assembled.withColumn(&quot;id&quot;,monotonically_increasing_id() ) o...
<python><apache-spark><pyspark><apache-spark-sql>
2024-01-19 11:18:34
1
463
yashaswi k
77,845,509
14,954,262
openpyxl - get real values of cells when create a list
<p>I have this code to read a .xlsx file :</p> <pre><code>wb1 = openpyxl.load_workbook('test.xlsx') ws1 = wb1.worksheets[0] content = list(ws1.iter_rows(values_only=True) </code></pre> <p>But the format of datas inside the <code>content</code> list contains some <code>'None'</code> and some <code>'datetime.date...
<python><list><openpyxl>
2024-01-19 10:51:00
0
399
Nico44044
77,845,472
16,077,901
How to get tuya bluetooth devices with python?
<p>I used this module</p> <p><a href="https://pypi.org/project/tinytuya/" rel="nofollow noreferrer">https://pypi.org/project/tinytuya/</a></p> <p>to work with my wifi tuya devices.</p> <p>Recently, I added a bluetooth device (temperature &amp; humidity sensor) that works well on my androïd app smartlife and did not fou...
<python><python-3.x><linux><bluetooth><tuya>
2024-01-19 10:44:15
0
1,331
Dri372
77,845,370
536,262
How can I find out what is causing namespace error and verify modules from pip
<p>I'm using the package pyJWT extinsively to inspect and manipulate jwts, but suddenly all newly build containers start failing saying <code>jwt.decode()</code> do not exists.</p> <p>I suspect the jwt namespace has been injected from something else, or the cache has been poisoned.</p> <pre class="lang-py prettyprint-o...
<python><pip>
2024-01-19 10:25:44
1
3,731
MortenB
77,845,362
201,657
What is the correct procedure for installing the Snowflake Python API
<p>I would like to use Python to interact with my Snowflake account. To get started I am following the <a href="https://quickstarts.snowflake.com/guide/getting-started-snowflake-python-api/index.html#1" rel="nofollow noreferrer">Getting started with the Snowflake Python API</a> quickstart which clearly states to run th...
<python><snowflake-cloud-data-platform>
2024-01-19 10:24:08
2
12,662
jamiet
77,845,045
726,730
python virtual devices - How to reuse camera in more than one application?
<p>Is there any available way to register a camera and a microphone as a virtual camera and virtual microphone using python, so i can reuse theme in more than one application?</p>
<python><virtual>
2024-01-19 09:35:05
1
2,427
Chris P
77,845,041
9,797,207
MyPy Type Check Error: No attribute found in Base class for subclass methods
<p>I'm facing an issue with MyPy type checking, and I would appreciate some guidance on resolving it. I have a base class Base and two subclasses Sub1 and Sub2. Each subclass has its own methods (b and c, respectively).</p> <pre><code>class Base: def a(self) -&gt; None: print(&quot;a&quot;) class Sub1(Base...
<python><inheritance><casting><mypy><python-typing>
2024-01-19 09:34:42
0
467
saibhaskar
77,844,971
4,405,942
Django: Unknown command: 'collectstatic' when using call_command
<p>I have a Django project with <code>&quot;django.contrib.staticfiles&quot;</code> in <code>INSTALLED_APPS</code>. Therefore, I can run <code>./manage.py collectstatic</code>. But I need to use <a href="https://docs.djangoproject.com/en/5.0/ref/django-admin/#running-management-commands-from-your-code" rel="nofollow no...
<python><django><manage.py><collectstatic>
2024-01-19 09:23:35
0
2,180
Gerry
77,844,778
1,901,071
Converting Polars to Pandas raises error DLL load failed while importing lib
<p>I am practicing Pythons using Polars. I have a data-frame which I have generated a bunch of calculations in my data-frame and then want to convert it to a Pandas data-frame so that I can apply an isolation forest to the the dataset. I have installed polars and pyarrow and pandas using</p> <p>My Code and version of t...
<python><pandas><anaconda><python-polars>
2024-01-19 08:53:25
2
2,946
John Smith
77,844,740
7,253,993
How to match specific Unix shell-style strings using Python's fnmatch?
<p>I would like to create a Unix shell-style pattern that will only match strings with specific suffixes. The pattern in question starts with <code>0.1</code> and can finish with <code>test</code> or <code>alpha</code> or <code>.</code> .</p> <p>This means that <code>0.1test</code> and <code>0.1alpha</code> should matc...
<python><regex><fnmatch>
2024-01-19 08:45:38
1
6,300
kingJulian
77,844,696
18,136,808
Compression of ordered integer list
<p>I'm reading the book <a href="https://nlp.stanford.edu/IR-book/information-retrieval-book.html" rel="nofollow noreferrer">&quot;Introduction to information retrieval&quot;</a> and I have some practical doubt. In the book there is a <a href="https://nlp.stanford.edu/IR-book/pdf/05comp.pdf" rel="nofollow noreferrer">c...
<python><encoding><binary><compression><information-retrieval>
2024-01-19 08:36:13
1
359
carlo97
77,844,483
4,521,319
LeetCode - Minimum Falling Path Sum - question on memoization
<p>I am trying to solve this leetcode problem: <a href="https://leetcode.com/problems/minimum-falling-path-sum/description" rel="nofollow noreferrer">https://leetcode.com/problems/minimum-falling-path-sum/description</a></p> <blockquote> <p>Given an n x n array of integers matrix, return the minimum sum of any falling ...
<python><recursion><dynamic-programming><memoization>
2024-01-19 07:53:35
1
925
Hemanth Annavarapu
77,844,417
6,364,117
Cannot read hx-includes value on flask view using hx-put
<p>I cannot read the value of a select element via a htmx PUT <code>hx-put</code>, method to the flask view function. The select is in a modal body. I am almost certain I need to read the PUT value from the <code>request.get_json()</code> function. The put executes and I can print the <code>request</code> object in the...
<python><flask><htmx>
2024-01-19 07:40:12
2
1,422
godhar
77,843,824
18,926,992
pyttsx3 delays print statement on the previous line
<p>I've noticed a weird bug when using <code>pyttsx3.speak()</code> after a print statement that has the <code>end=''</code> argument set. Take a look at my code.</p> <p>I've done a bit of research, and I couldn't find anything that's related to this issue. And I couldn't find a reason why exactly this is happening. Th...
<python><printing><output><newline><pyttsx3>
2024-01-19 05:06:14
1
470
eternal_white
77,843,784
13,496,839
real-time text input issues in PyQt5 with Tamil99 keyboard layout
<p>I am working on a PyQt5 application with three QLineEdit widgets and one QListWidget. The first QLineEdit is for English (US) input, the second uses the Tamil Phonetic input method, and the third uses the Tamil99 keyboard layout. The application runs on Windows 10.</p> <p>The issue arises when using the Tamil99 keyb...
<python><pyqt5><qlineedit>
2024-01-19 04:52:31
0
686
Bala
77,843,738
8,726,488
Python group by values using itertools groupby function
<p>Python code is below.</p> <pre><code>from itertools import groupby data = [('a', 1), ('b', 2), ('b', 3), ('c', 4), ('c', 5)] _sorted_data = sorted(data,key= lambda element : element[0]) _res = groupby(_sorted_data,key=lambda x : x[0]) for key,value in _res: print(key,list(value)) </code></pre> <p>Got below resul...
<python><python-3.x><python-itertools>
2024-01-19 04:37:55
1
3,058
Learn Hadoop
77,843,685
23,190,147
Printing an image in python
<p>I'm trying to print an image, literally to the python shell. This is only for the &quot;see if it is possible&quot; purposes, I'm not actually using this for anything, just a fun project of mine. Of course, I already know how to display images and have done a few projects in the past involving images, but I want to ...
<python><image><printing>
2024-01-19 04:14:34
1
450
5rod
77,843,672
8,792,060
Find k smallest values of of a 2D array slice of a 3D Array?
<p>I've read through other questions where other people are trying to find the <em>k</em> smallest values with <code>np.partition</code> or <a href="https://stackoverflow.com/questions/31642353/find-the-n-smallest-items-in-a-numpy-array-of-arrays"><code>np.argpartition</code></a>. However, these seem like simple 1D or ...
<python><arrays><numpy><sorting>
2024-01-19 04:10:38
1
553
superasiantomtom95
77,843,561
8,460,470
Parsing a string input into a lambda function with multiple parameters
<p>How can I parse a string input into the proper form which could be used as the first <strong>callable</strong> parameter of <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow noreferrer">scipy.optimize.curve_fit</a>?</p> <pre class="lang-python prettyprint-ove...
<python>
2024-01-19 03:29:27
1
460
Shannon
77,843,483
3,250,110
How to check if object in nested array contains a value
<p>In Python, this works:</p> <pre><code>for site in userSites: for role in site.roles: if role.role == Role.ADMIN: return True return False </code></pre> <p>I am looking for a way to do this in a single line that can check a nested array to see if any of the user's sites contain the admin role.</p>
<python>
2024-01-19 02:57:33
1
801
Zach
77,843,154
3,491,653
boto3 list only objects of a specific storage class in s3 bucket
<p>This is an efficiency problem. I am using <code>boto3</code> to selectively download files from an S3 bucket. The problem is that I have about 50k records in a folder and over 70% of them are in <strong>GLACIER</strong>/<strong>DEEP_ARCHIVE</strong>. I am using <code>list_objects_v2</code> to iterate the files.</p> ...
<python><amazon-web-services><amazon-s3><boto3>
2024-01-19 00:45:52
0
614
i_use_the_internet
77,843,038
395,857
How can use Haystack to identify the top k sentences that are the closest match to a user query, and then returns the docs containing these sentences?
<p>I have a set of 1000 documents (plain texts) and one user query. I want to retrieve the top k documents that are the most relevant to a user query using the Python library <a href="https://github.com/deepset-ai/haystack" rel="nofollow noreferrer">Haystack</a> and <a href="https://github.com/facebookresearch/faiss" r...
<python><indexing><information-retrieval><faiss><haystack>
2024-01-18 23:57:05
1
84,585
Franck Dernoncourt
77,842,996
3,555,115
Add multiple columns and assign values to a dataframe from another dataframe columns based on condition
<p>I have a dataframe</p> <pre><code>df1 = Instance_name counter_name counter_value A bytes_read 0 A bytes_written 90 B bytes_read 100 ...
<python><pandas><dataframe>
2024-01-18 23:42:52
1
750
user3555115
77,842,863
2,873,090
Get unique features for each set in a collection of sets
<p>I'm struggling to search how to do this; maybe there's a word for this set operation I'm not aware of.</p> <p>I have several sets with overlapping elements, and I'd like to find which elements are unique to each given set. For example:</p> <pre class="lang-py prettyprint-override"><code>sets = { 'rat': {'a', 'b'...
<python><set>
2024-01-18 22:56:49
9
891
catleeball
77,842,724
1,028,270
I can't get logging.config to load my custom class
<p>I have a custom formatter defined in my log_conf.py.</p> <pre><code># log_conf.py class Custom(jsonlogger.JsonFormatter): def add_fields(self, log_record, record, message_dict): super().add_fields(log_record, record, message_dict) log_record[&quot;new_field&quot;] = log_record[&quot;levelname&quo...
<python><python-logging>
2024-01-18 22:22:08
1
32,280
red888
77,842,706
9,779,999
ValidationError: 1 validation error for RetrievalQA
<p>Here is my code:</p> <pre><code>from langchain.document_loaders import PyPDFLoader from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_openai import OpenAIEmbeddings from langchain_community.vectorstores import Chroma openai_api_key= 'xxx' loader = PyPDFLoader('xxx.pdf') text = loader...
<python><langchain><data-retrieval><chromadb>
2024-01-18 22:16:29
0
1,669
yts61
77,842,692
9,599,098
Why will my local Python Script work perfectly but then fail as soon as I try to run in Lambda?
<p>I am essentially at the point of trying to run a Hello World application because I cannot figure this out.</p> <p>My local Env is Python 3.12.0. My Lambda Function is Python 3.12.0..</p> <p>I have followed both methods in the official AWS documentation for creating my zip file to load to Lambda.</p> <p><a href="http...
<python><amazon-web-services><aws-lambda><openpyxl>
2024-01-18 22:13:20
0
784
user68288
77,842,670
477,969
How to consume bokeh with mypy
<p>I am using bokeh library and it states that it uses mypy internally. Thus, I infer it has good typing information which I have confirmed looking the source code.</p> <p>However, I notice that using mypy in my own project that imports bokeh still produces errors. How I should configure mypy in my side to gracefully a...
<python><python-3.x><bokeh><mypy>
2024-01-18 22:08:21
0
2,114
JairoV
77,842,667
11,618,586
labeling segments of data based on multiple conditions
<p>I have an indexed pandas dataframe with values like so:</p> <pre><code>data = {'ID':[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 'column1': [15, 16, 17, 14, 13, 5, 3, 2, 1.9, 1.2, 1, 0.8, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 2, 3, 4, 5, 6], 'column2': [10, 11,...
<python><python-3.x><pandas><indexing>
2024-01-18 22:07:44
1
1,264
thentangler
77,842,516
58,347
MyPy: How to type an argument that will forward to isinstance()
<p>I'm writing a predicate function. Among other things, it can take an argument that is compatible with <code>isinstance()</code>, such that if you called <code>my_pred(val, types)</code>, it would return <code>isinstance(val, types)</code>.</p> <p>However, I'm not sure how to type that second argument correctly when ...
<python><python-3.x><mypy>
2024-01-18 21:32:16
1
18,453
Tab Atkins-Bittner
77,842,479
593,487
How to split transformation matrix into steps for animation?
<p>I have a 4D transformation matrix (rotation, translation and scale) that I can use to do <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.affine_transform.html" rel="nofollow noreferrer">affine transform</a> of a 3D numpy array, from where I take a slice and display it. This part works and...
<python><numpy><animation>
2024-01-18 21:22:45
0
18,451
johndodo
77,842,461
3,606,412
TypeError: cannot unpack non-iterable TreeNode object
<p>I am learning to use a deque to check if two binary trees are the same. However, I can't figure out why n1 and n2 (as node1 and node2) can't be unpacked. I tried to put them in a list and a tuple, unpacking, etc, but can't unpack successfully. I'm thinking it's something else. Could anyone help? Here is the cod...
<python><python-3.x><tree><queue><binary-tree>
2024-01-18 21:17:44
1
1,383
LED Fantom
77,842,458
2,706,344
Extracting maximum number from DataFrame of strings (and some NaN values)
<p>Look at the DataFrame:</p> <pre><code>import pandas as pd import numpy as np data=pd.DataFrame(['random 15 numbers 128 and 12 letters','12-5','page 65'],columns=['text']) </code></pre> <p><a href="https://i.sstatic.net/GNX1j.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GNX1j.png" alt="enter image d...
<python><pandas><regex>
2024-01-18 21:17:01
1
4,346
principal-ideal-domain
77,842,438
856,804
Why does mypy complain when a subtype is returned when using TypeVar?
<p>I wonder why this example doesn't pass mypy check:</p> <pre class="lang-py prettyprint-override"><code>from typing import Optional, TypeVar class A: pass class B(A): def __init__(self) -&gt; None: print(&quot;B&quot;) T = TypeVar(&quot;T&quot;, bound=A) def foo(x: T) -&gt; Optional[T]: if...
<python><mypy><python-typing>
2024-01-18 21:12:32
1
9,110
zyxue
77,842,223
3,555,115
Pivoting based on multiple columns and rearrange data in Python Dataframe
<p>have a python dataframe.</p> <pre><code>df1 Load Instance_name counter_name counter_value 0 A bytes_read 0 0 A bytes_written 90 0 B bytes_read 100...
<python><pandas><dataframe>
2024-01-18 20:26:22
1
750
user3555115
77,842,181
7,347,925
How to speed up creating Point GeoSeries with large data?
<p>I have two 1D arrays and want to combine them into one Point GeoSeries like this:</p> <pre><code>import numpy as np from geopandas import GeoSeries from shapely.geometry import Point x = np.random.rand(int(1e6)) y = np.random.rand(int(1e6)) GeoSeries(map(Point, zip(x, y))) </code></pre> <p>It costs about 5 seconds ...
<python><pandas><geopandas><shapely>
2024-01-18 20:15:35
1
1,039
zxdawn
77,842,097
1,795,927
How to insert Blob in oracle db in python
<p>I am new to python and i am trying to insert a blob to an oracle db table. but its failing with 'TypeError: oracledb.base_impl.DbType object is not callable</p> <pre><code>import oracledb from datetime import datetime # Connection details (replace with your credentials) username = &quot;username&quot; password = &q...
<python><oracle-database><python-oracledb>
2024-01-18 19:55:31
1
856
Nevin Thomas
77,841,985
1,474,895
Python Requests Giving Me Missing Metadata When Trying To Upload Attachment
<p>I am trying to upload an attachment via an API. I can make it work in the software's Swagger environment with this:</p> <pre><code>curl -X 'POST' \ 'https://demo.citywidesolutions.com/v4_server/external/v1/maintenance/service_requests/9/attached_files' \ -H 'accept: */*' \ -H 'Content-Type: multipart/form-data...
<python><python-requests><attachment>
2024-01-18 19:31:44
2
1,483
Cody Brown
77,841,857
7,563,454
Pygame: Get an image from the average mixture of multiple images
<p>I have an number of images with the same resolution in a list... they're generated and painted from the code with with <code>pygame.Surface</code> though that shouldn't be relevant for this question, will mention they're part of a multi-sampling system with each image representing one render. I want to merge them in...
<python><python-3.x><pygame>
2024-01-18 19:04:05
3
1,161
MirceaKitsune
77,841,821
6,836,950
Set state attribute for request object in fastapi/starlette test client
<p>I have a GET endpoint that proxies another endpoint and it expects to extract Bearer token from request's state attribute. This is my endpoint</p> <pre><code> from fastapi import Depends, Request from starlette.requests import Request from starlette.status import HTTP_200_OK from starlette.testclient import TestClie...
<python><python-3.x><fastapi><starlette>
2024-01-18 18:57:09
0
4,179
Okroshiashvili
77,841,796
15,279,420
Boto3 not really starting an instance
<p>I'm running Python code on an instance and I'm trying to start an EC2 instance using boto3 <code>start_instances</code>. The code works and gives the following response:</p> <pre><code>Response: {'StartingInstances': [{'CurrentState': {'Code': 0, 'Name': 'pending'}, 'InstanceId': 'i-&lt;id&gt;', 'PreviousState': {'C...
<python><amazon-web-services><amazon-ec2><boto3>
2024-01-18 18:51:28
2
343
Luis Felipe
77,841,654
3,557,485
Ranking objects by absolute occurrence
<p>I have a list of dictionaries which contains contains floats. My goal is to rank these objects with considering the occurrence the duplicates.</p> <h2>Example</h2> <p>If the highest value is <code>19.93</code> and it occurs three times in the raw list, we will have three <code>{&quot;rank&quot;:1}</code>'s, and as w...
<python><python-3.x>
2024-01-18 18:27:00
2
3,360
rihekopo
77,841,645
11,030,722
Python Cloud Function - How to Query Firestore with documentID? (where)
<p>I am attempting to filter my data based on the <code>documentId</code>. My objective is to retrieve a random document. Unfortunately, I am unable to find a way to achieve this within a Python cloud function.</p> <p>My current code looks like this:</p> <pre class="lang-py prettyprint-override"><code>result = firestor...
<python><firebase><google-cloud-firestore><google-cloud-functions>
2024-01-18 18:25:05
0
479
Luca Köster
77,841,392
2,410,605
Selenium Python How Do I Loop Through Menu Items and See If A Specific Menu is Open
<p>I'm new to Selenium Python and trying to loop through a list of menu items, and when I get to a specific menu item I want to see if it's expanded or not. Based on how the code is set up, the only way I can see to do this is see if the aria-expanded element is set to true.</p> <p>So my problem is two-fold: 1) How do ...
<python><selenium-webdriver>
2024-01-18 17:37:02
1
657
JimmyG
77,841,343
11,578,996
How to format/access inner boxplots of a violin catplot in seaborn?
<p><a href="https://i.sstatic.net/RUmAk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RUmAk.png" alt="seaborn catplot with kind=violin" /></a></p> <p>I'm looking to change the formatting of the inner boxplots for the violin plots within this catplot. I have tried using the violinplot parameter <code>in...
<python><seaborn><violin-plot><catplot>
2024-01-18 17:28:28
0
389
ciaran haines
77,841,256
1,711,271
group dataframe by column, process values and normalize other column based on processed values
<p>I have a dataframe <code>df</code> with two columns, <code>foo</code> and <code>bar</code>:</p> <pre><code> foo bar 0 2410_030_GCD 0.012093 1 2410_030_GCD 0.012789 2 2410_030_GCD 0.014205 3 2410_010_GCD 0.016280 4 2410_010_GCD 0.019738 5 6122_020_LCM 0.025806 6 6122_020_LCM 0.0...
<python><pandas><group-by><python-re>
2024-01-18 17:13:08
4
5,726
DeltaIV
77,841,234
13,142,245
Stan dimensions mismatch
<p>PyStan (imported as Stan) is giving me an unexpected error</p> <pre><code>import stan # Load data (replace X and y with your actual data) X = np.linspace(1,100,100).reshape([100,1]) y = np.random.randint(0,2,100).reshape([100,1]) N = y.shape[0] K = X.shape[1] data = {'N': N, 'K': K, 'X': X, 'y': y} # Compile Stan...
<python><stan><pystan>
2024-01-18 17:09:38
0
1,238
jbuddy_13
77,841,192
13,147,413
Replacing values from a given column with the modified values from a different column in python-polars
<p>I need to update the values of a column (X) in correspondance with certain values ('v') of another column Y with values from another column (Z) times some numbers and then cast the obtained column to int:</p> <p>In pandas the code is as follow:</p> <pre><code>df.loc[df[&quot;Y&quot;] == &quot;v&quot;, &quot;X&quot;]...
<python><dataframe><python-polars>
2024-01-18 17:03:29
1
881
Alessandro Togni
77,841,164
1,668,622
Where does the limitation to 100 connections to docker.socket (using aiodocker) come from?
<p>I'm using the Python-package <a href="https://github.com/aio-libs/aiodocker" rel="nofollow noreferrer">aiodocker</a> do monitor running Docker containers using <code>container.stats()</code> like this:</p> <pre><code>async for stats in container.stats(): do_something(...) </code></pre> <p>And this works as expec...
<python><docker><sockets>
2024-01-18 16:59:56
1
9,958
frans
77,840,942
6,435,921
Computing Matrix-vector product between submatrices of multidimensional arrays
<p>I have an array <code>A</code> of shape <code>(1000, 54, 50)</code> and another array <code>x</code> of shape <code>(1000, 54)</code>. For every <code>i=0, ..., 999</code> I. would like to compute <code>A[i, :, :] @ (A[i, :,:].T @ x[i])</code>. What is the fastest way that leverages NumPy's vectorisation capabiliti...
<python><numpy><numpy-ndarray>
2024-01-18 16:26:14
1
3,601
Euler_Salter
77,840,804
11,703,579
Install Neurolab for Python 3.11
<p>I´m trying to install the <code>neurolab</code> package to my <code>Python 3.11</code> environment. I use <code>Anaconda</code> with <code>Python version 3.11</code>. The available versions of <code>Neurolab</code> found on <code>Anaconda</code> page are those:</p> <p><a href="https://i.sstatic.net/VxWrl.png" rel="n...
<python><machine-learning><anaconda><neurolab>
2024-01-18 16:04:02
1
569
gbossa
77,840,657
893,254
VS Code Pylance - Import ".XXX" could not be resolved
<p>The below screenshot shows the contents of an <code>__init__.py</code> file which Pylance thinks has some missing imports.</p> <p>Why are some of the imports resolvable and some are not?</p> <p>The directory containing this <code>__init__.py</code> file contains the files listed in the import statements:</p> <ul> <l...
<python>
2024-01-18 15:42:27
1
18,579
user2138149
77,840,585
893,254
Building a Python Library - are fully qualified import statements required?
<h1>Additional context added later</h1> <p>I wrote this question when I had less experience with Python and now I have some recommendations to make:</p> <ol> <li>Do not put library code in a <code>src</code> directory</li> <li>Do not put &quot;executable&quot; Python code in a seperate <code>bin</code> directory</li> <...
<python>
2024-01-18 15:31:34
1
18,579
user2138149
77,840,560
16,813,096
Why opacity in tkinter widgets not supported?
<p>So I searched for opacity in individual tkinter widgets and I found that it is not possible with tkinter.</p> <p>However, there is transparent attribute in macosx and windows which makes a color fully transparent (<a href="https://stackoverflow.com/questions/75594687/how-to-apply-transparent-background-in-tkinter-wi...
<python><python-3.x><tkinter><tkinter-canvas><customtkinter>
2024-01-18 15:28:49
1
582
Akascape
77,840,397
2,729,831
Error "data is invalid" for Custom SSL certificate Google App Engine
<p>I am trying to install a custom SSL certificate for google app engine but I get this error: <code>&quot;The certificate data is invalid. Please ensure that the private key and public certificate match.&quot;</code> So I checked with the commands:</p> <pre><code>openssl x509 -noout -modulus -in concat.crt | openssl m...
<python><ssl><google-cloud-platform><google-app-engine><ssl-certificate>
2024-01-18 15:05:22
0
473
blob
77,840,287
6,435,921
NumPy - Fill each subdiagonal of an array, with rows from another array leveraging vectorisation
<p>I have a numpy array <code>A</code> of shape <code>(N, M, M)</code> and another numpy array <code>B</code> of shape <code>(N, M)</code>. I want to fill each of the <code>N</code> diagonals of the submatrices <code>A[i, :, :]</code> with the rows in <code>B</code>. I want to do this as fast as possible using Numpy's ...
<python><numpy><numpy-ndarray>
2024-01-18 14:49:49
3
3,601
Euler_Salter
77,840,285
6,184,153
Email test does not work in Django if django-allauth sends the email
<p>I use the <strong>Django 5.0.1 with django-allauth</strong>. With real smtp email backend, email confirmation works. Django's email testing features are also working if django-allauth is not involved, like in the <a href="https://docs.djangoproject.com/en/5.0/topics/testing/tools/#email-services" rel="nofollow noref...
<python><django><email><testing><django-allauth>
2024-01-18 14:49:36
1
361
Roland
77,840,135
6,345,518
Python regex substitute string in code file
<p>I try to use Python v3.12.0 regex to reformat <strong>strings in a code source file</strong> to resemble C++ raw string format.</p> <h3>Sample input file</h3> <p>F.i. the following code in file <code>myclassA.txt</code> (code is in a <strong>C++-like dialect, please mind the special way of declaring multi-line strin...
<python><regex>
2024-01-18 14:27:49
2
5,832
JE_Muc
77,840,099
512,480
VSCode Python: Error while enumerating installed packages
<p>My long-successful VSCode Python setup broke inexplicably.</p> <p>Please, what does the error below mean? First the recommended Python 3.12 can't find _tkinter. I try an older installed version and get this. I can't use pip either, it says &quot;externally managed environment&quot;. I'm lost.</p> <pre class="lang-n...
<python><visual-studio-code><pip>
2024-01-18 14:21:53
4
1,624
Joymaker
77,839,982
8,324,480
How to include an online forms in a sphinx-build website
<p>I have a python package and website which is build with <code>sphinx</code>. I'm looking to include a page containing a form that can be filled:</p> <pre><code>e-mail (*): question 1: question 2: ... Validate </code></pre> <p>Upon validation, the form should be converted in a nice formatting and sent by mail. Befor...
<python><forms><python-sphinx>
2024-01-18 14:03:26
1
5,826
Mathieu
77,839,886
9,846,650
How to run commands in postgres inside docker using python script?
<p>I have wrote a script to download a postgresql image in docker and run certain commands inside the docker.</p> <p>I am able to successfully download the container and enter inside it after getting the container id using script.</p> <pre class="lang-py prettyprint-override"><code> import subprocess, os import docker ...
<python><postgresql><docker>
2024-01-18 13:47:21
1
712
mad_lad
77,839,844
13,518,907
Langchain RetrievalQA: Missing some input keys
<p>I have created a RetrievalQA Chain, but facing an issue. When calling the Chain, I get the following error: <code>ValueError: Missing some input keys: {'query', 'typescript_string'} </code></p> <p>My code looks as follows:</p> <pre><code>from langchain_community.embeddings import HuggingFaceEmbeddings embeddings = ...
<python><python-3.x><langchain><py-langchain><retrieval-augmented-generation>
2024-01-18 13:41:11
3
565
Maxl Gemeinderat
77,839,774
6,194,597
Randomly select from a list while ensuring the selected elements value must be x apart
<p>Say I have a list</p> <pre><code>l = [0, 0, 0, 1, 1, 2, 3, 4, 5, 5, 5, 5, 6, 6, 7] </code></pre> <p>Given the list above, I have 15 elements, 8 unique elements, I need to sample n number of indices of the elements that are random but are <strong>at least x apart in value</strong>. For example, if <code>n = 4</code> ...
<python>
2024-01-18 13:30:47
4
1,139
Gregor Isack
77,839,743
5,696,601
Reproducing a treemap in Plotly from a repository of dash samples
<p>I want to reproduce <a href="https://dash-example-index.herokuapp.com/modal-treemap" rel="nofollow noreferrer">a treemap in Plotly from a repository of dash samples</a>.</p> <p><a href="https://i.sstatic.net/fl2Fu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fl2Fu.png" alt="enter image description ...
<python><plotly><plotly-dash>
2024-01-18 13:25:58
1
1,023
Stücke
77,839,589
1,612,369
How to make Python scripts available anywhere in PowerShell
<p>Currently working with Python in WIndows 10.</p> <p>I am trying to setup PowerShell so that Python would find scripts even if I am currently in different folder. Simply speaking, I would like to run script as follows</p> <pre><code>python myscript.py </code></pre> <p>instead of</p> <pre><code>python D:\aaa\bbb\myscr...
<python><powershell><path>
2024-01-18 12:57:30
1
2,691
Celdor
77,839,540
15,283,859
Pandas hierarchy/complex conditions to drop duplicates
<p>I have a large dataset of locations - there is a sample below.</p> <p>I need to find and drop duplicates. There are some obvious duplicates, which have the same address, name and borough, but also some almost equal rows, which identify 2 different locations (such as the last 2 rows of the sample below). To complicat...
<python><python-3.x><pandas><dataframe><numpy>
2024-01-18 12:50:27
1
895
Yolao_21
77,839,384
1,554,114
python win32com with Inventor seems to be missing methods
<p>I am trying to translate sample VBA code from Inventor over to python.<br /> Most things, like modifying parameters work really well. But unfortunately, export to STL is failing.</p> <p>It seems, that methods of the &quot;STL Exporter Plugin&quot; that should be there are just missing.<br /> In my case: <code>HasSav...
<python><win32com><autodesk-inventor>
2024-01-18 12:27:10
1
4,731
Nippey
77,839,358
9,490,769
Full height main div in dash
<p>I have created a very simple dash application, but I cannot get the main div to stretch to the full page height.</p> <p>Here is the python code</p> <pre class="lang-py prettyprint-override"><code>import dash from dash import html app = dash.Dash(__name__) page = html.Div(id='page', children=[html.H...
<python><html><css><plotly-dash>
2024-01-18 12:24:26
1
3,345
oskros
77,839,338
5,790,653
python yaml openstack how to access element of one group
<p>I have a yaml file like this:</p> <pre class="lang-yaml prettyprint-override"><code>clouds: all: gr1: id: '202401' gr2: id: '202402' gr3: id: '202403' gr4: id: '202404' group1: gr1: id: '202401' group2: gr2: id: '202402' group34: gr3: id: '202403' gr4: id: '202404' </c...
<python><openstack>
2024-01-18 12:21:09
1
4,175
Saeed
77,838,950
988,279
Parse URL parameter and create a dictionary
<p>I want to have the URL parameters as a &quot;real&quot; dict. How can I achieve that? I don't want to use <code>params.split()</code> multiple times.</p> <pre><code>from urllib.parse import urlparse url = 'http://nohost.com?params=depth:1,width:500,size:small' the_url = urlparse(url) url_part, params = the_url.pat...
<python>
2024-01-18 11:14:05
1
522
saromba
77,838,888
231,934
Overriding nested values in polyfactory with pydantic models
<p>Is it possible to provide values for complex types generated by polyfactory?</p> <p>I use pydantic for models and pydantic ModelFactory. I noticed that <code>build</code> method supports kwargs that can provide values for constructed model, but I didn't figure if it's possible to provide values for nested fields.</p...
<python><pydantic><polyfactory>
2024-01-18 11:05:12
1
3,842
Martin Macak
77,838,496
2,913,106
How to manually set axis offset with custom tick labels?
<p>Consider the plot below. Both axis have custom labels, to label the rows and columns in an <code>imshow</code>-plot. The problem now is that the y-axis has very large values. Ideally I'd like to manually set an axis-offset (i.e. on top of the axis somethng like <code>1e5</code>) such that the ticks are only show a s...
<python><matplotlib><axis><xticks>
2024-01-18 10:04:42
2
11,728
flawr
77,838,382
936,269
How to correctly get file path using QUrl on windows
<p>So need to allow users to select a file path via QT application. For this I use <a href="https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#PySide6.QtWidgets.PySide6.QtWidgets.QFileDialog.getOpenFileUrl" rel="nofollow noreferrer">getOpenFileUrl</a>.</p> <p>Then I take the resulting <a href="https://d...
<python><qt><pyqt6>
2024-01-18 09:44:45
0
2,208
Lars Kakavandi-Nielsen
77,838,272
9,957,594
Polars - get hour from Time column
<p>I have a Polars df with a column 'Checkout Time' in a string format, e.g '17:54'.</p> <p>I'm converting to a time format with: <code>df = df.with_columns(pl.col('Checkout Time').str.to_time('%H:%M'))</code></p> <p>How would I then get the actual hour of the time as an integer?</p> <p>I could do it with map_rows but ...
<python><dataframe><python-polars>
2024-01-18 09:27:03
1
350
tcotts
77,838,245
8,444,568
Is it safe to add inheritance relationship for a pickled object?
<p>I have some old pickle files that store object <code>d</code>:</p> <pre><code>class D(): def __init__(self, val): self._val = val def val(self): return self.val d = D() pickle.dump(d, file_store_obj_d) </code></pre> <p>Now, I want to do some refactor and add a base interface class for <code>D</code>:</...
<python><pickle>
2024-01-18 09:23:45
0
893
konchy
77,838,169
11,702,196
Installing opencv in docker and run into compilation errors?
<p>I've been trying to build this repo and install it inside docker. <a href="https://github.com/Silvicek/baselines" rel="nofollow noreferrer">https://github.com/Silvicek/baselines</a></p> <p>I am installing it in dockerfile with <code>pip3 install -e .</code>. And there is a compilation problem in opencv.</p> <p>My do...
<python><c++><docker><opencv><ubuntu>
2024-01-18 09:11:26
1
391
Yv Zuo
77,837,914
9,743,391
Snap to the nearest or previous datetime point value every interval
<p>I am hoping to downsample the dataset with uneven sub-hour intervals to 6-hourly, with fixed time points of 00H, 6H, 12H and 18H. If data at these time points exist, keep. If not, use the observation from the nearest previous datapoint <strong>without data manipulation</strong>, keeping original records.</p> <pre><c...
<python><pandas><dataframe>
2024-01-18 08:28:06
2
626
Jane
77,837,887
1,220,538
How to run Py_Initialize in embedded python with virtualenv using C API?
<p>In my C++ application I am using embedded python interpreter using the stable C API to execute python scripts. It works well, but I want to extend this functionality to be able to configure a virtualenv path to use that instead of the system's python packages.</p> <p>What I gathered is that I have to set some variab...
<python><c++><python-3.x><virtualenv>
2024-01-18 08:23:25
0
329
Lord Gamez
77,837,807
15,063,526
How to use function from 1 jupyter notebook in another jupyter notebook?
<p>There are two python notebooks:</p> <ul> <li><code>trading.ipynb</code> (1st)</li> <li><code>monitorTrades.ipynb</code> (2nd)</li> </ul> <p>While the execution of the main block is in the first notebook, a function has to be executed in the second notebook (at the same time). This function must have 2 arguments (whi...
<python><jupyter-notebook><jupyter>
2024-01-18 08:09:29
1
341
Sanchay Kasturey
77,837,732
3,555,115
Compare Timestamps from columns and remove entries based on condition
<p>I have a dataframe</p> <pre><code>df1 = Instance sort_begin cop_begin ded_begin a 04:19:07 04:31:56 04:32:32 a 04:19:07 02:34:22 02:34:22 f 05:19:07 02:31:26 04:32:32 f ...
<python><pandas><dataframe>
2024-01-18 07:54:23
1
750
user3555115
77,837,695
3,618,999
Retry post request Mechanism in Backend in python flask
<p>Context: I have one API, where inside the API 3 different external POST APIs are called. And behaviour should be if all 3 APIs give success response, then only overall API should be success. And even if 1 failed we do the rollback on the POST call. Now the issue is with one external API that has very high response t...
<python><flask><design-patterns><architecture><system-design>
2024-01-18 07:47:57
1
579
ratnesh
77,837,585
3,314,925
Correct way to call helper function in a class
<p>Is there a 'correct' way to call a helper function when using an instance method in a class? Both functions <strong>calc_age</strong> and <strong>calc_age_v2</strong> work, is there a preferred method? This is a toy example, the real code has more complex functions.</p> <pre><code>#%% def calc_age(self): age=202...
<python><class><arguments><self><instance-methods>
2024-01-18 07:29:07
1
1,610
Zeus
77,837,583
5,166,312
STM32L0xx MCU: J-Link EraseChip Issues via Jlink_X64.dll
<p>I need help with erasing an <strong>STM32L083</strong> using a J-Link. I have the Jlink_X64.dll library and I am calling its functions from Python. However, when I call <strong>JLINK_EraseChip()</strong>, it returns a <em>pylink.errors.JLinkEraseException: Failed to erase sector error</em> and the MCU does not get e...
<python><dll><stm32><segger-jlink>
2024-01-18 07:28:53
1
337
WITC
77,837,392
3,187,537
APIConnectionError: Connection error. in langchain vector search
<p>I am trying to implement a RAG solution using Azure OpenAI and Azure AI Search.</p> <p>This is my <code>requirements.txt</code> file:</p> <pre><code>azure-core==1.29.6 azure-common==1.1.28 azure-identity==1.15.0 azure-keyvault-keys==4.8.0 azure-keyvault-secrets==4.7.0 azure-search-documents==11.4.0 openai==1.8.0 lan...
<python><azure-cognitive-search><langchain><azure-openai><azure-ai-search>
2024-01-18 06:49:19
0
1,732
Saurabh Jain
77,837,305
5,938,276
Running Juypter Notebook remotely
<p>I have connected to my Rasp Pi using VSCode from Windows so I can run a Juypter Notebook on the Rasp Pi.</p> <p>However the Rasp Pi has venv installed and when I try to run the notebook I get a message:</p> <p><code>Running cells with /usr/bin/python' requires ipykernel package.</code></p> <p><a href="https://i.ssta...
<python><visual-studio-code><python-venv><vscode-remote>
2024-01-18 06:29:14
1
2,456
Al Grant
77,837,301
1,230,724
Get closest parent dtype of two ndarray's
<p>I'd like to convert potentially mixed (i.e. <code>dtype==object</code>) numpy arrays to the closest parent dtype (as per the hierarchy shown here <a href="https://numpy.org/doc/stable/reference/arrays.scalars.html" rel="nofollow noreferrer">https://numpy.org/doc/stable/reference/arrays.scalars.html</a>).</p> <p><a h...
<python><numpy>
2024-01-18 06:28:36
0
8,252
orange
77,837,297
8,076,158
Create an empty TypedDict with Tuple values in Numba
<p>I want to initialise a dict with string keys and heterogenous tuple values. This is what I have. Any ideas..?</p> <pre><code>from numba import types, typed, njit, typeof, from_dtype TypeMyTuple = types.Tuple([types.unicode_type, types.float16, types.int16]) my_dict = typed.Dict.empty(key_type=types.unicode_type, v...
<python><numba>
2024-01-18 06:27:34
1
1,063
GlaceCelery
77,837,062
4,564,080
Overriding method in subclass with a parameter type hint that is a subclass of the type hint used in the parent's method
<p>I have the following structure of a parent class and a child class which inherits from parent. The constructor of the parent takes a parameter of type <code>ParentType</code>, and the constructor of the child class takes the same parameter, but of type <code>ChildType</code>, which is a subclass of <code>ParentType<...
<python><python-typing>
2024-01-18 05:22:41
1
4,635
KOB
77,837,023
134,044
Use str.format to format numbers with a minimum of 1 decimal place without rounding and without adding additional trailing zeroes
<h4>Context</h4> <p>I am receiving numbers as strings in <strong>Python 3</strong> and want to transmit them as strings in order to preserve accuracy so that the upstream server can convert the numbers-as-strings to <code>decimal.Decimal</code> without loss of accuracy.</p> <p>[<em>Admins: I have repeatedly searched St...
<python><python-3.x><decimal><string-formatting>
2024-01-18 05:09:22
3
4,109
NeilG
77,836,728
2,597,213
Polars, compute new column by cross referencing two dataframes
<p>First of all I have to say this is my first time using any DataFrame module.</p> <p>I have need to process FEM simulation results that I have loaded into polars dataframe, which produce two DataFrames:</p> <pre><code>nodes_df = pl.DataFrame( {&quot;node&quot;:[1,2,3,4,5,6,7,8,9,10], &quot;x&quot;:[4.5,-4.6...
<python><dataframe><python-polars>
2024-01-18 03:28:12
1
4,885
efirvida
77,836,616
23,190,147
Count number of ways to pair integers 1-14 under constraint
<p>Consider the following problem:</p> <p>How many ways are there to split the integers 1 through 14 into 7 pairs such that in each pair, the greater number is at least 2 times the lesser number?</p> <p>This is obviously a math problem, and there are several solutions to it. I wondered if there is a way to write a pyth...
<python><math><set><combinations>
2024-01-18 02:45:27
2
450
5rod