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
76,159,149
11,602,367
Debugging Dash clientside callback
<p>I have the following Dash app (simplified). It displays text boxes and a list of words (buttons). You click the buttons that have text to add the corresponding text to the text box (this is the part I want a client-side callback for). There is another callback with the same output (now that that's permitted with Das...
<javascript><python><plotly-dash>
2023-05-02 21:59:22
1
551
acciolurker
76,159,107
4,500,155
Is it possible to use Flatgeobuf in Python?
<p>I would like to read from / write to <a href="https://github.com/flatgeobuf/flatgeobuf" rel="nofollow noreferrer">flatgeobuffers</a> from a Python GIS application. My understanding is that this technology can only be used so in JavaScript and TypeScript (of course the compilation stage is language-agnostic insofar a...
<python><gis><flatbuffers>
2023-05-02 21:50:10
1
544
WhyNotTryCalmer
76,159,055
1,985,211
Convert numpy array of strings to datetime
<p>I am shocked at how long I've been running around down various rabbit holes trying to figure this problem out which (I thought) should be relatively simple.</p> <p>I have a numpy array of strings saved as variable <code>t</code> with some associated data as raw_data:</p> <pre><code>t = array(['20141017000000','20141...
<python><numpy><date><datetime><type-conversion>
2023-05-02 21:40:03
2
669
Darcy
76,159,050
9,718,879
Heroku migrations refuse being made
<p>I deployed a django rest application on Heroku but I noticed when I went to the api route, I see a <code>no such table</code> error. I figured I needed to do</p> <ol> <li>heroku run python manage.py makemigrations</li> <li>heroku run python manage.py migrate</li> <li>heroku run python manage.py createsuperuser</li> ...
<python><django><heroku><django-rest-framework>
2023-05-02 21:39:04
0
1,121
Laspeed
76,159,000
3,366,592
invalid results of process_time() when measuring model.fit() performance
<p>I use the snippet below to measure and output the time spent during model fitting.</p> <pre><code>perf_counter_train_begin = time.perf_counter() process_time_train_begin = time.process_time() model.fit(data, ...) perf_counter_train = time.perf_counter() - perf_counter_train_begin process_time_train = time.process_...
<python><performance><tensorflow><keras>
2023-05-02 21:29:16
1
449
user3366592
76,158,929
15,008,906
aiokafka exits when running in a multiprocessing class
<p>I've been banging my head against the wall today trying to figure out why this isn't working. I created this multiprocessing class:</p> <pre><code>class Consumer(multiprocessing.Process): def __init__(self, topic, **kwargs): self.topic = topic super(Consumer, self).__init__(**kwargs) def _deserializer(seria...
<python><python-asyncio><python-multiprocessing><aiokafka>
2023-05-02 21:15:43
1
413
Jon Hayden
76,158,821
5,420,333
Blazepose Mediapipe: Differences between Python and Javascript implementation
<p>I was building a system that processes poses from videos using Python, and then, a Javascript (react) application that estimates the user pose on webcam in real time, and compares it with the Python processed poses.</p> <p>The thing is that I started encountering very different results on the coordinates... I made a...
<javascript><python><computer-vision><mediapipe><pose>
2023-05-02 20:58:01
1
471
Dhiogo Corrêa
76,158,814
1,056,563
How to structure a nested "x if condition else y" so Black will leave it legible?
<p>For a double nested <code>x if condition else y</code> it was legible before <code>black</code> got into the fray. It loses the nice indentations I had placed and now it's just a <em>Wall of Code</em>:</p> <pre><code> clause = ( (f&quot;{self.colname} &quot; if self.colname else &quot;&quot;) + se...
<python><python-black>
2023-05-02 20:56:50
1
63,891
WestCoastProjects
76,158,797
1,292,652
Why is mypy/PyCharm/etc not detecting type errors for Type[T]?
<p>Consider the following code:</p> <pre><code>def verify(schema: Type[T], data: T) -&gt; None: pass verify(int, &quot;3&quot;) verify(float, &quot;3&quot;) verify(str, &quot;3&quot;) </code></pre> <p>I would expect the first two <code>verify()</code> calls to show up as a type error, and the last one to not.</p> ...
<python><pycharm><python-typing><mypy>
2023-05-02 20:54:17
1
4,580
Yatharth Agarwal
76,158,756
21,376,217
How to convert integer number and arrays of bytes to each other in C?
<p>After using Python, I found that its struct module can package numbers into byte strings or unpack byte strings into numbers.</p> <p>the code is like this:</p> <pre class="lang-py prettyprint-override"><code>import struct struct.pack('&gt;I', 13934) # b'\x00\x006n' struct.pack('&gt;Q', 12345678901234567890) # b'\x...
<python><c><struct>
2023-05-02 20:47:44
2
402
S-N
76,158,646
13,689,939
How to Convert Pandas any Function with mean into SQL (Snowflake)?
<p><strong>Problem</strong></p> <p>I'm converting a Python Pandas data pipeline into a series of views in Snowflake. The transformations are mostly straightforward, but some of them seem to be more difficult in SQL. I'm wondering if there are straightforward methods.</p> <p><strong>Question</strong></p> <p>How can I wr...
<python><sql><pandas><migration><snowflake-cloud-data-platform>
2023-05-02 20:31:36
2
986
whoopscheckmate
76,158,640
978,288
matplotlib Annotation: how to get bbox only for text
<p>I would like to <em>test annotation objects</em> in my graph <em>for overlapping</em> and, if one object covers another, move them accordingly.</p> <p>However <code>box = ann.get_window_extent(renderer)</code> gets the box for whole Annotation object and it does not help.</p> <p>Is it possible to get the <code>bbox<...
<python><matplotlib><annotations>
2023-05-02 20:30:53
0
462
khaz
76,158,635
7,247,147
How to efficiently filter out duplicate objects in a list based on multiple properties in Python?
<p>I'm working on a Python project where I have a list of custom objects, and I need to filter out duplicates based on multiple properties of these objects. Each object has three properties: <code>id</code>, <code>name</code>, and <code>timestamp</code>. I want to consider an object as a duplicate if both the <code>id<...
<python>
2023-05-02 20:29:56
3
1,115
user7247147
76,158,570
7,090,501
Break list of words into whole word chunks under a max token size
<p>Let's say I have a long list of names that I would like to feed into an LLM in chunks. How can I split up my list of names so that each group is a list with <code>&lt; max_tokens</code> items without repeating or breaking up a any individual entries in the list? I know from the <a href="https://platform.openai.com/d...
<python><openai-api>
2023-05-02 20:20:26
1
333
Marshall K
76,158,457
11,498,718
Why is my Python class memoizing by default?
<p>Context: I am running Python 2.7 (I am restricted to this version because reasons.)</p> <p>I have a Python class, that looks something like this:</p> <pre class="lang-py prettyprint-override"><code>class MyClient( object ): def __init__(self, my_dict): self.value = my_dict def run(): # do so...
<python><python-2.7>
2023-05-02 20:01:33
1
494
Klutch27
76,158,220
10,603,191
Python Playwright, how to fill data into these boxes
<p>I am writing a Python script using the Playwright package to auto-complete a questionnaire. <a href="https://ee.kobotoolbox.org/x/cmKGMgos" rel="nofollow noreferrer">Here is a dummy version of the form</a>, and here is my code so far:</p> <pre class="lang-py prettyprint-override"><code>import asyncio from playwright...
<python><web-scraping><playwright><playwright-python>
2023-05-02 19:23:21
1
459
Chris Browne
76,158,219
2,725,810
Method inheritance for DRF views
<p>Consider:</p> <pre class="lang-py prettyprint-override"><code>class CourseListViewBase(): def list(self, request, format=None): # whatever class CourseListView(generics.ListAPIView, CourseListViewBase): permission_classes = [IsAuthenticated] def list(self, request, format=None): # Why can't I omit th...
<python><django><django-rest-framework><multiple-inheritance>
2023-05-02 19:23:18
1
8,211
AlwaysLearning
76,158,147
5,091,720
Pandas - groupby ValueError: Cannot subset columns with a tuple with more than one element. Use a list instead
<p>I was updated my Pandas from I think it was 1.5.1 to 2.0.1. Any how I started getting an error on some code that works just fine before.</p> <pre><code>df = df.groupby(df['date'].dt.date)['Lake', 'Canyon'].mean().reset_index() </code></pre> <blockquote> <p>Traceback (most recent call last): File &quot;f:...\My_pyt...
<python><pandas><dataframe>
2023-05-02 19:13:20
2
2,363
Shane S
76,158,142
7,339,624
What is the point of class-level type hints in Python?
<p>I'm trying to understand the point of class-type hints. I know that we can use type hints in the <code>__init__</code> method of a class, like this:</p> <pre><code>class Foo: def __init__(self, x: int): self.x = x </code></pre> <p>However, I came across another way of defining type hints at the class lev...
<python><python-typing>
2023-05-02 19:12:41
1
4,337
Peyman
76,158,139
8,028,981
Getting WinError 6 (invalid handle) when trying to mute the output of an f2py process
<p>I want to suppress the console output from an f2py extension module. Standard approaches like the following don't work, because the Fortran output comes from another place than standard Python print commands (?) So the Fortran output will still be printed to the console.</p> <pre><code>from contextlib import redirec...
<python><stdout><f2py>
2023-05-02 19:12:24
0
1,240
Amos Egel
76,158,045
6,500,048
Split column list into rows without duplicating data
<p>I have a dataframe where the first column is a list, how can I iterate through the list and add a value to the relevant pre defined column:</p> <pre><code>workflow cost cam gdp ott pdl ['cam', 'gdp', 'ott'] $2,346 ['pdl', 'ott'] $1,200 </code></pre> <p>should convert to:</p>...
<python><pandas>
2023-05-02 18:58:29
6
1,279
iFunction
76,158,026
8,283,848
What is the proper way to use raw sql in Django with params?
<p>Consider that I have a <em>&quot;working&quot;</em> PostgreSQL query -</p> <pre><code>SELECT sum((cart-&gt;&gt; 'total_price')::int) as total_price FROM core_foo; </code></pre> <p>I want to use the raw query within Django, and I used the below code to get the result-</p> <pre class="lang-py prettyprint-override"><co...
<python><sql><django><postgresql><django-3.0>
2023-05-02 18:55:58
1
89,380
JPG
76,157,949
13,381,632
Update Python Package in Mamba vs. Conda
<p>I am attempting to update a Python package in Mamba, specifically to a version of <code>boto3=1.26.63</code>. I am trying to do so using the syntax</p> <pre><code>mamba update boto3=1.26.63 </code></pre> <p>but receive an error stating:</p> <blockquote> <p>Encountered problems while solving: -nothing provides reque...
<python><anaconda><command-line-interface><boto3><mamba>
2023-05-02 18:44:07
0
349
mdl518
76,157,885
864,245
Match pair of numbers against dictionary containing pairs of numbers
<p>(Using Python 3.9, but can upgrade to newer)</p> <p>I have two numbers - CPU (in vCPU) and RAM (in GB) - the resource requirements of an application.</p> <p>From a list of instance sizes, I am trying to find the closest match that my application can run on - as long as the instance has enough CPU and RAM.</p> <p>Her...
<python><python-3.x>
2023-05-02 18:35:02
3
1,316
turbonerd
76,157,876
1,907,631
Can you read HDF5 dataset directly into SharedMemory with Python?
<p>I need to share a large dataset from an HDF5 file between multiple processes and, for a set of reasons, mmap is not an option.</p> <p>So I read it into a numpy array and then copy this array into shared memory, like this:</p> <pre><code>import h5py from multiprocessing import shared_memory dataset = h5py.File(args....
<python><shared-memory><hdf5><h5py><hdf>
2023-05-02 18:33:32
1
319
monday
76,157,864
8,040,369
Python script run from AirFlow job takes UTC time
<p>I have an AirFlow job scheduled and running. It calls a Python script where I am using the <code>datetime.now()</code> function to get the Date and Time values and store it in a SQL table.</p> <p>Since it runs via AirFlow, the time that gets saved in the SQL table is in UTC.</p> <p>Is there a way to pass the current...
<python><datetime><airflow>
2023-05-02 18:32:20
0
787
SM079
76,157,847
2,056,201
Sharing data between React elements through a Route
<p>I am trying to exchange several data variables between multiple elements in React, essentially the equivalent of passing a pointer to a struct in C++ between various classes/functions</p> <p>I am following this tutorial <a href="https://react.dev/learn/sharing-state-between-components" rel="nofollow noreferrer">http...
<javascript><python><html><reactjs><flask>
2023-05-02 18:28:54
2
3,706
Mich
76,157,845
21,113,865
Can you force derived class from a bass class to define specific member variables in python?
<p>If I have a class say:</p> <pre><code>class BaseClassOnly(): def __init__(self): self._foo = None def do_stuff(self): print(&quot;doing stuff with foo&quot; + self._foo) </code></pre> <p>I want to force all classes derived from BaseClassOnly to provide a value for 'self._foo' so that the inh...
<python><inheritance><base-class><python-class><abstract-base-class>
2023-05-02 18:28:21
1
319
user21113865
76,157,763
16,898,766
How do I set the figsize and dpi in matplotlib so that the image has the required size and quality?
<p>I need to combine the images into one. I would like the resulting image to consist of 7 rows and 9 columns. Each component image has dimensions of 256 x 256. I would like these images not to be resized, that is, I would like the resulting image to have dimensions of at least 9 * 256 x 7 * 256 = 2304 x 1792. The easi...
<python><python-3.x><matplotlib><image-processing><latex>
2023-05-02 18:17:06
1
333
nietoperz21
76,157,724
3,103,957
__call__() method in meta-class in python
<p>I am having the following piece of code.</p> <pre><code>class CustomMetaClass(type): def __call__(self, *args, **kwargs): print(&quot;Custom call method is invoked from custom meta class.&quot;) class Sample(metaclass=CustomMetaClass): def method(self): print(&quot;Printing from a method&quo...
<python><call><metaclass>
2023-05-02 18:12:24
1
878
user3103957
76,157,711
5,651,603
How can we properly mock/stub async methods of a mocked class?
<p>I want to mock/stub the async methods of the <code>Connect</code> class returned by <code>websockets.client.connect</code>; such as <code>send</code> and <code>recv</code>. I succeed in testing the instantiation of the class, but I can't seem to setup the methods?</p> <p>The complete code is in <a href="https://gist...
<python><python-3.x><python-asyncio><python-unittest><python-unittest.mock>
2023-05-02 18:11:08
0
1,080
LFLFM
76,157,577
7,386,830
Correct method to build a multiple polynomial regression model
<p>I am using Statsmodels (Python) library to develop a multi-polynomial regression model. I have 6 variable columns and 1 target column.</p> <p>One method for example in Statsmodel, there is an in-built function such as following (for power 2):</p> <pre><code>from sklearn.preprocessing import PolynomialFeatures pf = P...
<python><machine-learning><regression><statsmodels><polynomials>
2023-05-02 17:49:54
0
754
Dinesh
76,157,511
11,999,957
How do I find where in CSV file does error occur when importing using Pandas?
<p>Let's say I try to import CSV file using <code>pd.read_csv()</code> and get this error.</p> <pre><code>'utf-8' codec can't decode byte 0x93 in position 214567: invalid start byte </code></pre> <p>How do interpret the error message and find in the CSV file what character is causing the issue? Is it the 214567th char...
<python><pandas><csv>
2023-05-02 17:40:34
3
541
we_are_all_in_this_together
76,157,451
3,324,136
FFprobe, python and Lambda: Unable to get dimensions of video using FFprobe
<p>I am using ffprobe and python on Lambda and trying to get the dimensions of a video. I have the code that grabs the localized source file.</p> <pre><code># Download the source file from S3 source_object = s3.Object(source_bucket_name, find_file_name) print(f'The source object is {source_object}') source...
<python><amazon-s3><aws-lambda><ffprobe>
2023-05-02 17:32:23
0
417
user3324136
76,157,347
11,391,711
Converthing datetime64[ns] into a Timestamp object
<p>I am reading date information from an Excel file which is stored as <code>datetime64[ns]</code>. However, I need this information stored as <code>Timestamp</code> object since the function to which I pass the date information does not properly work with <code>datetime64[ns]</code>.</p> <p>Here is how I read the date...
<python><pandas><datetime><datetime-format>
2023-05-02 17:19:04
1
488
whitepanda
76,157,295
3,553,024
How to install pycurl on Apple M1 Silicon using pip v23.1+
<p>Installing <code>pycurl</code> on computers with Apple M1 chips has always been a struggle. I have been using this command to install <code>pycurl</code> with OpenSSLv3 using <code>pip</code>:</p> <pre><code>brew update &amp;&amp; brew install openssl export LDFLAGS=&quot;-L/opt/homebrew/opt/openssl@3/lib&quot; expo...
<python><pip><apple-m1><pycurl>
2023-05-02 17:10:19
2
1,874
jdesilvio
76,157,266
12,894,926
What is difference between Pyarrow arguments for Pandas readers?
<p><a href="https://pandas.pydata.org/docs/user_guide/pyarrow.html#i-o-reading" rel="nofollow noreferrer">Pandas' documentation explains how to use <code>PyArrow</code> as the backend for IO methods.</a> However, I couldn't understand from it the difference between these two options:</p> <pre class="lang-py prettyprint...
<python><pandas><pyarrow>
2023-05-02 17:06:48
1
1,579
YFl
76,157,247
17,231,480
Unable to load my static files in Django production environment
<p>I am deploying my Django application to Railway.</p> <p>I am following this guide, <a href="https://docs.djangoproject.com/en/4.2/howto/static-files/deployment/#how-to-deploy-static-files" rel="nofollow noreferrer">https://docs.djangoproject.com/en/4.2/howto/static-files/deployment/#how-to-deploy-static-files</a>. T...
<python><django><deployment><static><railway>
2023-05-02 17:04:17
1
349
jethro-dev
76,157,217
1,761,521
Take elements from each group in Polars where the groups are not even
<p>How do I take the first <code>n</code> elements of a group where <code>n</code> &gt; <code>G</code> and <code>G = number of items in group</code>?</p> <p>For example,</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df = pl.DataFrame(dict(x=[1,1,1,2,3,3,3], y=[1,2,3,4,5,6,7])) df.group_by(&qu...
<python><python-polars>
2023-05-02 17:00:56
1
3,145
spitfiredd
76,157,159
6,595,551
OpenTelemetry exporter logs/errors in AWS Lambda, Invalid type NoneType for attribute, Invalid type <class 'NoneType'> of value None, etc
<p>Context:</p> <p>I'm using a couple of tools to send metrics from an AWS Lambda function to the ADOT collector. Overall, I deployed my API service (FastAPI) with AWS Lambda.</p> <p>Tools:</p> <ol> <li>AWS Lambda</li> <li>Python==3.9</li> <li>opentelemetry-sdk==1.17.0</li> <li><code>arn:aws:lambda:us-east-1:9019205704...
<python><amazon-web-services><aws-lambda><open-telemetry>
2023-05-02 16:54:12
0
1,647
Iman Shafiei
76,156,942
11,734,659
Want to run a Python "print()" script from Java, but getting no output
<p>I have a simple Python script:</p> <pre><code>def main(): print(&quot;Hello world&quot;) if __name__ == &quot;__main__&quot;: main() </code></pre> <p>And I want to get the response in Java. The endpoint is:</p> <pre><code>@RestController @CrossOrigin(origins = &quot;http://localhost:4200&quot;) public class...
<python><java>
2023-05-02 16:26:22
1
582
Programmer2B
76,156,772
6,195,489
Process only files with filename above a certain number
<p>I have a single directory full of millions of files with file names such as e.g.:</p> <pre><code>234.txt 235.txt 236.txt </code></pre> <p>I would like to work through the files with a name that has an integer prefix above a certain value, which is determined by the last file processed in a previous run and fetched f...
<python><os.walk>
2023-05-02 16:03:39
0
849
abinitio
76,156,688
1,454,316
Apply Callable to NDArray
<p>I am new to Python and I have done a fair share of just trying things to see if it works. In this case, when I apply a Callable to an NDArray, I get a result, just not what I expected.</p> <pre><code>from typing import Callable from typing import Tuple import numpy as np callable : Callable[[float], Tuple[float, fl...
<python><numpy><numpy-ndarray><callable-object>
2023-05-02 15:51:35
1
841
Little Endian
76,156,645
5,675,125
AWS EC2 python not creating folders and then also folders deleting
<p>So this is a weird one (for me). I am trying to download audio files to my AWS EC2 instance. after which I will upload them to s3 (if I get passed this part)</p> <p>The first problem I am having is with python.</p> <p>I am importing <code>tempfile</code> package and using it like so:</p> <pre><code>self._tempdir = t...
<python><amazon-web-services><amazon-ec2><temporary-files>
2023-05-02 15:46:48
0
1,603
JamesG
76,156,601
1,860,222
Representing a complex object as a pyqt model class
<p>I'm trying to create a model/view for a complex object in pyqt. All of the examples I have found so far assume the data will be in a repeating element like a table or list. Does anyone know of a good example or tutorial that demonstrates working with something more complicated?</p> <p>For example lets say I have a c...
<python><model-view-controller><pyqt>
2023-05-02 15:42:17
0
1,797
pbuchheit
76,156,599
4,507,596
How to correctly use cv2.bitwise_and() with Meta AI Segment-Anything Model (SAM) generated masks?
<p>I am using Meta AI Segment-Anything Model (SAM) to generate masks:</p> <pre><code>masks, scores, logits = mask_predictor.predict( box=box, multimask_output=True) for i, (mask, score) in enumerate(zip(masks, scores)): print (&quot;image.shape&quot; + str(image.shape)) # image.shape(506, 447, 3) print (&...
<python><opencv>
2023-05-02 15:42:03
1
446
Will
76,156,557
6,849,363
Pytorch runs on GPU without CUDA
<p>I'm scratching my head a bit. I just got a new work computer and am trying to actually set up a clean CUDA environment this time. So far all I've done is the following:</p> <p>Downloaded pytorch with <code>pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117</code></p> <p>Run ...
<python><tensorflow><pytorch>
2023-05-02 15:37:55
1
470
Tanner Phillips
76,156,551
4,121,487
How to pass list of strings to a CFFI extension?
<p>I would like to pass a list of strings to a CFFI extension which expects a <code>char**</code> as input parameter.</p> <p>Example:</p> <p><code>extension.h</code>:</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stddef.h&gt; void sort_strings(char** arr, size_t string_count); </code></pre> <p><code>...
<python><c><python-cffi>
2023-05-02 15:37:19
1
447
MaxGyver
76,156,335
10,907,172
Django/Docker/pyaudio: pip install failed beaucause of #include "portaudio.h"
<p>I am using Django on Docker with python:3.8.3-alpine image and want to use pyaudio librairy but pip install failed because of portaudio dependency</p> <blockquote> <p>rc/pyaudio/device_api.c:9:10: fatal error: portaudio.h: No such file or directory 9 | #include &quot;portaudio.h&quot; | ^~~~~~~~~~~~~</p> </...
<python><django><docker><pyaudio>
2023-05-02 15:13:54
1
683
SLATER
76,156,170
11,155,419
How to programmatically share a Google Sheet with an email, via Python API?
<p>I have list of Google Sheets that I would like to modify, such that a specific email is granted an <code>Editor</code> access. However, instead of doing this manually, I would like to be able to do it programmatically, using the Google Python client.</p> <p>I am aware I can potentially use the Drive API,</p> <pre><c...
<python><google-sheets><google-cloud-platform><google-drive-api>
2023-05-02 14:55:23
1
843
Tokyo
76,156,101
11,994,733
Running PyCharm Unittests sequentially for packages while running tests within each package in parallel
<p>I'm writing unit tests for a published web application. This web application has a variable that changes the functionality of the app and this variable is persistent across all of a user's sessions.</p> <p>I want to take advantage of running multiple tests in parallel, but I can't have two tests expecting different ...
<python><parallel-processing><pycharm><python-unittest>
2023-05-02 14:47:42
1
2,426
Mandelbrotter
76,155,889
8,930,751
Subscribing to multiple partitions in Azure Event Hub using Python
<p>I have created a event hub namespace. Inside the event hub namespace I created a event hub with 8 partitions. It has one consumer group - $Default.</p> <p>I have written the receiver code in Python which looks like this.</p> <pre><code>import asyncio from azure.eventhub.aio import EventHubConsumerClient from azure....
<python><azure><events><azure-eventhub>
2023-05-02 14:24:14
0
2,416
CrazyCoder
76,155,851
7,237,062
Diart (torchaudio) on Windows x64 results in torchaudio error "ImportError: FFmpeg libraries are not found. Please install FFmpeg."
<p>I am giving a try to a speech <em>diarization</em> project named <a href="https://github.com/juanmc2005/diart" rel="nofollow noreferrer"><strong>diart</strong></a> (based on <a href="https://huggingface.co/" rel="nofollow noreferrer">hugging face</a> models)</p> <p>I follow the instructions using a <code>miniconda</...
<python><pytorch><conda><torchaudio><diarization>
2023-05-02 14:19:23
3
3,347
LoneWanderer
76,155,734
4,357,631
Properly typed factory for FastAPI and Pydantic
<p>I have been developing my first API using FastAPI/SQLAlchemy. I have been using the same four methods (Get One, Get All, Post, Delete) for multiple different entities in the database, thus creating a lot of repeated code. For example, the code below shows the methods for a Fungus entity.</p> <pre class="lang-py pret...
<python><sqlalchemy><fastapi><python-typing><pydantic>
2023-05-02 14:08:01
1
309
Skalwalker
76,155,694
10,346,275
Telethon sending of messages gets stuck for a while then continues
<p>i am try to send messages to the groups that i have joined using telethon. everything works fine but most of the times, it gets stuck for about 1min-1min 30s then it continues. this issue occurs multiple times during the process. also its really slow. please help</p> <pre class="lang-py prettyprint-override"><code>f...
<python><telegram-bot><telethon>
2023-05-02 14:03:17
1
604
Spidy
76,155,574
3,575,623
Calculate distance between columns of two data frames
<p>I have two data frames that contain values for different people in each column:</p> <pre><code>import numpy as np import pandas as pd import math df1 = pd.DataFrame({ &quot;Anna&quot;:[1.5,-2,2.5], &quot;Bob&quot;:[2.5,-3,3.5], &quot;Cam&quot;:[3.5,-4,4.5]}) df2 = pd.DataFrame({ &quot;Dave&quot;:[1,...
<python><pandas><dataframe><distance>
2023-05-02 13:53:43
2
507
Whitehot
76,155,369
19,155,645
OSRM API: find distance to nearest emergency station
<p>I have a typescript project and I am trying to get the distance to the nearest police station (and later I also add fire station). I'm using typescript for this</p> <p>I tried this url I found in the internet:<code>https://router.project-osrm.org/route/v1/driving/${lon},${lat};nearest?annotations=distance&amp;exclud...
<python><typescript><google-maps-api-3><openstreetmap>
2023-05-02 13:28:27
1
512
ArieAI
76,155,172
3,531,792
django Request aborted Forbidden (CSRF token missing.) channels websockets
<p>I'm new to django and I'm trying to get a realtime chat app using channels websockets up and running. I've tried building the chat page myself as well as copy pasting the relevant chat code from the tutorial itself. Still I get &quot;CSRF verification failed. Request aborted.&quot; and &quot;Forbidden (CSRF token mi...
<python><django><channel>
2023-05-02 13:04:48
1
613
Kenshima
76,155,163
12,684,429
Create new column which is max of other columns with conditions
<p>I would like to make a new column which is the max of two things;</p> <p>The first is the average of two columns, the second is one of those two columns.</p> <p>So I essentially want forecast to be the max of the following:</p> <pre><code> df3['forecast'] = df3[['A', 'B']].mean(axis=1) df3['forecast'] = df3[['A']] ...
<python><pandas><max>
2023-05-02 13:03:50
1
443
spcol
76,155,130
16,436,095
markdownify don't remove comment from tag
<p>I try to convert HTML to Markdown using <code>markdownify</code>. This lib don't remove comment from style tag and I try to understand it.</p> <p>One of methods of MarkdownConverter class is <code>process_tag</code>, and I think that key somewhere here. See below (I add some prints to check):</p> <pre><code>def proc...
<python><markdown>
2023-05-02 13:00:43
1
370
maskalev
76,155,119
12,559,770
Merge different duplicated row based on one column in pandas
<p>I have a table such as :</p> <pre><code>Chrs pos value Chr1 1 9 Chr1 2 11 Chr1 3 13 Chr1 4 13 Chr1 5 13 Chr1 6 13 Chr1 7 14 Chr1 8 14 Chr1 9 14 </code></pre> <p>Does someone have an idea using pandas to transform it as :</p> <pre><code>Chrs start end value Chr1 ...
<python><python-3.x><pandas>
2023-05-02 12:59:46
3
3,442
chippycentra
76,155,091
635,799
np.uint32 != np.uintc on Windows
<p>On my Windows machine:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; np.dtype(np.uint32).itemsize 4 &gt;&gt;&gt; np.dtype(np.uintc).itemsize 4 &gt;&gt;&gt; np.uint32 == np.uintc False </code></pre> <p>But on my Mac:</p> <pre class="lang-py prettyprint-ove...
<python><numpy><types>
2023-05-02 12:56:53
1
898
Chang
76,155,063
815,612
Thread.join's timeout does not work when thread is computing a sum
<p>In the following code:</p> <pre><code>import threading def infinite_loop(): while True: pass def huge_sum(): return sum(range(2**100)) thread = threading.Thread(target=huge_sum) thread.start() thread.join(1) print(&quot;Done&quot;) </code></pre> <p>I expect the script to print &quot;Done&quot; af...
<python><multithreading>
2023-05-02 12:54:06
2
6,464
Jack M
76,155,052
1,040,718
Getting a random element in a QuerySet - Python Django
<p>I have the following query in Django:</p> <pre><code>vms = VM.objects.filter(vmtype=vmtype, status__in=['I', 'R']) .annotate(num_jobs=Count('job')) .order_by('num_jobs') </code></pre> <p>it will return a QuerySet of vms based on the number of jobs run...
<python><python-3.x><django><django-models>
2023-05-02 12:52:46
1
11,011
cybertextron
76,154,826
19,467,973
By what principle will it be correct to distribute queues in celery and rabbitmq?
<p>I have a small pet project that is an api written in fastpic and using postgresql and sqlalchemyORM. Recently I came across such a thing as Celery and decided to add it to my project, but I ran into the problem that I don't understand a little on what principle it is best for my project to apply it.</p> <p>Briefly a...
<python><rabbitmq><celery><fastapi>
2023-05-02 12:26:32
0
301
Genry
76,154,814
2,986,042
How to print variable from Multi core Trace32 with Python command
<p>I want to get both static variables and local variable from a function in trace32 with python script. I have got some useful reference from <code>trace32</code> site with python script. with below documents, I have written some script to control the trace32 with <code>python remote API's</code>.</p> <p><a href="http...
<python><python-3.x><trace32><lauterbach>
2023-05-02 12:24:54
1
1,300
user2986042
76,154,751
7,253,901
Pandas-on-spark API throws a NotImplementedError even though functionality should be implemented
<p>I am facing a weird issue with pyspark-on-pandas. I am trying to use regex to replace abbreviations with their full counterparts. The function I am using is the following (Simplified it a bit):</p> <pre><code>def resolve_abbreviations(job_list: pspd.Series) -&gt; pspd.Series: &quot;&quot;&quot; The job title...
<python><apache-spark><pyspark><pyspark-pandas>
2023-05-02 12:16:45
1
2,825
Psychotechnopath
76,154,376
4,022,609
python's asyncio exchange data between 2 coroutines - one of them executing synchronous and cpu-intensive code
<p>I have problems getting 2 routines cooperating, now even to the point that I've started asking myself if it's possible to do it with asyncio...</p> <p>I have 2 routines. The first routine performs (only) synchronous and cpu-intensive processing. The second one performs (&quot;proper&quot;) asyncio code. The first on...
<python><python-asyncio><synchronous>
2023-05-02 11:25:40
1
316
sudo
76,154,142
274,460
What is a fernet key exactly?
<p>According to the documentation for the <code>cryptography.fernet</code> module, fernet keys are:</p> <blockquote> <p>A URL-safe base64-encoded 32-byte key</p> </blockquote> <p>Yet this doesn't work:</p> <pre><code>import secrets from cryptography import fernet f = fernet.Fernet(secrets.token_urlsafe(32)) </code></p...
<python><cryptography><python-cryptography><fernet>
2023-05-02 10:56:42
1
8,161
Tom
76,154,140
5,852,692
Networkx creating a graph from dictionary where dict shows the connections
<p>I have a dictionary, and I would like to create a networkx DiGraph with it. The dictionary shows the downstream nodes:</p> <pre><code>dict_ = {0: [1], 1: [], 2: [], 3: [0, 1], 4: [0, 1, 2]} </code></pre> <p>The important thing, here is <code>(1)</code> and <code>(2)</code> are end...
<python><dictionary><graph><networkx><edges>
2023-05-02 10:56:37
1
1,588
oakca
76,154,105
3,762,284
How can I ignore empty log messages?
<p>I use sanic framework.</p> <p>I add log module and saw strange logs like this:</p> <pre class="lang-none prettyprint-override"><code>[2023-05-02 19:25:40 +0900] - (sanic.access)[INFO][127.0.0.1:34844]: GET http://127.0.0.1/api/v1/ta?idtype=1 200 7559 [2023-05-02 19:25:40,969] [INFO] [2023-05-02 19:25:40 +0900] - (...
<python><logging><python-logging>
2023-05-02 10:51:42
1
556
Redwings
76,154,062
253,898
Set timeout in Opensearch search method gives error
<p>I'm using Opensearch-py to handle interaction with an OpenSearch. However I'm having some issues with setting a timeout to fix a timeout issue when searching an index.</p> <pre><code>self.get_client().search( index=index, body=search_body, scroll=scroll, ignore=ignore, size=si...
<python><opensearch>
2023-05-02 10:45:18
3
11,088
Linora
76,153,917
3,521,180
how to get value based on matched key value pair from a single list of dictionaries in python?
<p>Below is the list of dictionaries where the first dictionary has all keys based on which matching has to be done on remining dictionaries.</p> <pre><code>tier_information= [ { &quot;NaN&quot;: &quot;From&quot;, &quot;From&quot;: &quot;To&quot;, ...
<python><json><python-3.x>
2023-05-02 10:24:11
1
1,150
user3521180
76,153,855
4,349,869
Paramiko "OSError: Failure" when trying to put large file to SFTP server
<p>My task is to perform some action on data queried from a database and then store the output on an SFTP server.<br /> The script performing all of this is executed on a VM running Windows Server 2016 Standard through task scheduler.</p> <p>There are a total of 4 files which I should copy at the end of the script from...
<python><sftp><paramiko>
2023-05-02 10:14:19
1
545
andrea
76,153,647
1,581,090
How to select a control element from `print_control_identifiers` in `pywinauto`?
<p>When using <code>pywinauto</code> with an application I can print out the control identifiers uwing the method <code>print_control_identifiers</code>. An example output is as follows:</p> <pre><code> | | | | ListItem - '02.05.2023 11:31:53 - Retrieved tree structure' (L599, T1033, R1756, B1050) | ...
<python><pywinauto>
2023-05-02 09:45:21
2
45,023
Alex
76,153,606
6,695,041
Dialogflow doesn't return training phrases
<p>I am trying to get an overview of the training phrases per intent from Dialogflow in python.</p> <p>I have followed <a href="https://cloud.google.com/python/docs/reference/dialogflow/latest/google.cloud.dialogflow_v2.services.intents.IntentsClient#google_cloud_dialogflow_v2_services_intents_IntentsClient_list_intent...
<python><dialogflow-es>
2023-05-02 09:39:40
3
409
Hav11
76,153,599
11,973,820
returning oracle cursor results to json python
<p>I am working with python oracle connection. But i have a issue returning date with the cursor result as json.</p> <p>below is the json result of the cursor, the issue is format of create_dttm. When creating a dataframe from this it is not changing the format. Any suggestion</p> <pre><code>result = cursur.execute(&qu...
<python><json><oracle-database>
2023-05-02 09:38:48
2
859
Jai
76,153,438
8,863,055
should I call declarative_base() multiple times?
<p>I participate in a legacy project which is python Flask API with sqlalchemy. In this project I can see there are many calls to <code>declarative_base()</code> for creating base for db classes.</p> <pre class="lang-py prettyprint-override"><code>from sqlalchemy.ext.declarative import declarative_base Base = declarati...
<python><flask><sqlalchemy>
2023-05-02 09:20:06
0
462
Marek Kamiński
76,153,402
3,165,737
Azure Functions won't publish Python function
<p>I'm trying to create an Azure functions using Python code, v2 model, version 3.10.</p> <p>Below are the contents of my <code>requirements.txt</code> file:</p> <pre><code>azure-functions requests beautifulsoup4 html5lib pyjq extruct js2py </code></pre> <p>The dependency of <code>pyjq</code> has been an issue, as it d...
<python><azure-functions>
2023-05-02 09:14:20
1
8,605
DocZerø
76,153,219
2,646,505
Distinguish default or command-line argument
<p>Consider</p> <pre class="lang-py prettyprint-override"><code>import argparse parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(&quot;--foo&quot;, type=str, default=&quot;bar&quot;, help=&quot;description&quot;) args = parser.parse_args() </code></pre> <p>No...
<python><argparse>
2023-05-02 08:51:02
1
6,043
Tom de Geus
76,153,040
10,413,428
Disabling custom button inside QDialogButtonBox
<p>I have a QDialogButtonBox that contains the two custom buttons Start and Cancel. According to <a href="https://stackoverflow.com/questions/31290792/how-to-change-the-caption-of-a-button-in-a-qdialogbuttonbox">this answer</a>, the best way to add these buttons is as follows:</p> <pre class="lang-py prettyprint-overri...
<python><qt><pyside><pyside6><qt6>
2023-05-02 08:28:09
1
405
sebwr
76,152,806
7,745,011
How to add custom labels to a torchdata datapipe?
<p>I am trying to load image data for model training from a self-hosted S3 storage (MinIO). Pytorch provides <a href="https://pytorch.org/data/beta/generated/torchdata.datapipes.iter.S3FileLoader.html#torchdata.datapipes.iter.S3FileLoader" rel="nofollow noreferrer">new datapipes with this functionality in the torchdata...
<python><torch><pytorch-datapipe><torchdata>
2023-05-02 07:56:04
1
2,980
Roland Deschain
76,152,720
10,215,160
How to replace certain values in a Polars Series?
<p>I want to replace the <code>inf</code> values in a polars series with 0. I am using the polars Python library.</p> <p>This is my example code:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl example = pl.Series([1,2,float('inf'),4]) </code></pre> <p>This is my desired output:</p> <pre><cod...
<python><python-polars>
2023-05-02 07:43:49
2
1,486
Sandwichnick
76,152,464
880,783
How can I annotate an untyped import?
<p>I'd like to add type annotations to an untyped import. How should I do that? This does not work:</p> <pre class="lang-py prettyprint-override"><code>from typing import Callable, TypeVar, cast, reveal_type from funcy import retry # bug.py:5: note: Revealed type is &quot;Any&quot; reveal_type(retry) F = TypeVar(&quo...
<python><import><python-typing>
2023-05-02 07:04:10
1
6,279
bers
76,152,283
1,581,090
How to check if some specific text exists in an application/window with pywinauto?
<p>I want to use <code>pywinauto</code> to check if some specific text exists in an application/window. I used the search engine &quot;google&quot; to search for &quot;pywinauto check text&quot; but did not find anything useful. Also, the <a href="https://pywinauto.readthedocs.io/en/latest/index.html" rel="nofollow nor...
<python><pywinauto>
2023-05-02 06:35:40
1
45,023
Alex
76,152,242
10,639,239
Vs Code skips Breakpoints after "import"
<p>When debugging my code, my breakpoints are ignored by visual studio code, once I use these lines of code:</p> <pre><code>from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds from brainflow.data_filter import DataFilter, FilterTypes, DetrendOperations, AggOperations </code></pre> <p>No error Mes...
<python><visual-studio-code>
2023-05-02 06:27:48
1
365
G.M
76,152,193
3,391,549
Find indices of nan elements in nested lists and remove them
<pre><code>names=[['Pat','Sam', np.nan, 'Tom', ''], [&quot;Angela&quot;, np.nan, &quot;James&quot;, &quot;.&quot;, &quot;Jackie&quot;]] values=[[1, 9, 1, 2, 1], [1, 3, 1, 5, 10]] </code></pre> <p>I have 2 lists: <code>names</code> and <code>values</code>. Each value goes with a name, i.e., <code>Pat</code> corresponds ...
<python><list><nested-lists>
2023-05-02 06:19:00
7
9,883
Adrian
76,152,159
1,581,090
Where to find proper documentation for `pywinauto`?
<p>On the documentation page for <code>pywinauto.application.Application</code> <a href="https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=pywinauto.window#pywinauto.application.Application" rel="nofollow noreferrer">HERE</a> you find some methods, but it seems not all are mentioned. ...
<python><pywinauto>
2023-05-02 06:13:30
1
45,023
Alex
76,152,065
9,880,480
Find the coordinates of a 3D point given the euclidean distance and rotation to another known point
<p>Imagine a 3D point (Point 1) with coordinates to origin <code>x,y,z=1,2,3</code> and quaternion rotation values to origin: <code>w,x,y,z=0.8,0.1,0.1,0.1</code> (which can be converted to rotation matrices). Further, imagine another 3D point (Point 2) that has a known euclidean distance from Point 1 equal to <code>2<...
<python><math><rotation><quaternions><coordinate-systems>
2023-05-02 05:56:28
1
397
HaakonFlaar
76,151,787
800,735
In Apache Beam/Dataflow multi-output DoFns, how do you assign type hints to specific tags
<p>I have a multi-output DoFn:</p> <pre><code>class DoFn1: def process(self, row) -&gt; Iterable[Union[Dict[str, Any], pvalue.TaggedOutput]]: if something: yield some_dict(...) else: yield pvalue.TaggedOutput(&quot;bad&quot;, ...) </code></pre> <p>And another DoFn that consum...
<python><google-cloud-dataflow><apache-beam><type-hinting>
2023-05-02 04:43:54
1
965
cozos
76,151,629
3,398,324
How to interpret predictions from LightGBM
<p>I am trying to obtain predictions from my LightGBM model, simple min example is provided in the first answer <a href="https://stackoverflow.com/questions/62555987/lightgbm-ranking-example/67621253#67621253">here</a>. When I run the provided code from there (which I have copied below) and run model.predict, I would e...
<python><pandas><lightgbm>
2023-05-02 03:57:11
1
1,051
Tartaglia
76,151,617
10,964,685
Export Plotly scatter as kml - python
<p>Is it possible to export a Plotly scatter figure as a kml file? I've got an example below using <code>matplotlib</code> but is it possible to execute the same output using Plotly?</p> <p>The Plotly figure is a scatter plot. Can it be converted to a kml output? I'm returning an error when trying to export as a kml.</...
<python><matplotlib><plotly><kml>
2023-05-02 03:54:34
1
392
jonboy
76,151,427
12,875,823
Uvicorn reload options are not being followed
<p>I have three directories: app, config, and private</p> <p>I'm running uvicorn programmatically like this with WatchFiles installed:</p> <pre class="lang-py prettyprint-override"><code>uvicorn.run( &quot;app.main:fast&quot;, host=host, port=port, log_level=log_level, reload=rel...
<python><fastapi><uvicorn>
2023-05-02 02:44:22
2
998
acw
76,151,347
14,385,814
Get the fields of Foreign key values in Django
<p>I'm confused why the values I fetch in foreign key is missing or not pops in Ajax result , all I want is to get the value name through the foreign key id using <strong>ajax</strong>, I tried many ways like <code>select_related()</code> but it doesn't work.</p> <p>The image below shows the result of the ajax through ...
<javascript><python><jquery><django><ajax>
2023-05-02 02:23:19
2
464
BootCamp
76,151,211
4,648,873
Unable to import python dependencies that come with miniconda in a Docker run
<p>I am trying to run a python script inside a dockerized miniconda environment. The issue I am facing is that when I <code>docker run</code> interactively(-it) and run the script manually inside, it works great. But when I <code>docker run</code> non-interactively, the modules that come with miniconda installation lik...
<python><docker><miniconda>
2023-05-02 01:39:43
1
1,792
A.R.K.S
76,151,197
18,551,983
Filter one DataFrame by another
<p>I have two DataFrames, <code>df1</code> and <code>df2</code>, with the same columns and where the indices of <code>df2</code> is a subset of the indices in <code>df1</code>.</p> <p>I want to output a DataFrames with the indices from <code>df1</code>, but with all cells set to 0, except cells having the value 1 in <c...
<python><python-3.x><pandas><dataframe>
2023-05-02 01:34:03
2
343
Noorulain Islam
76,151,112
6,087,667
pandas expanding with custom function for aggregation
<p>I am trying to understand why does this code throws an error. Even if the first 30 rows after <code>expanding</code> is of <code>np.nan</code> that still should allow numeric operations. Why does it fail? How should I fix this?</p> <pre><code>import pandas as pd import numpy as np i = pd.date_range('2000-01-01', '2...
<python><pandas><group-by><aggregate><apply>
2023-05-02 01:00:57
2
571
guyguyguy12345
76,151,111
15,632,586
What should I do to load my images with D3-Graphviz and Flask?
<p>I am trying to load my files that I have defined on a JavaScript file (with D3-Graphviz) to a Flask server. Here is my current server structure:</p> <pre><code>static --images --File.png --Actor.png --System.png --Service.png --background.jpg --style.css --visualisation.js temp...
<javascript><python><flask><d3.js><d3-graphviz>
2023-05-02 01:00:30
0
451
Hoang Cuong Nguyen
76,151,098
5,790,653
python email send to list one by one
<p>I have a list of emails like this:</p> <pre><code>emails = ['a@a.a', 'b@b'b', 'c@c.c', 'd@d.d'] </code></pre> <p>And this is my <code>for</code> loop:</p> <pre><code>for email in emails: message['To'] = email # ... other codes to send email </code></pre> <p>The problem is when I receive all three emails:</p>...
<python><email>
2023-05-02 00:58:00
1
4,175
Saeed
76,151,051
2,647,447
How to add background image to only selected page in ktinter of Python?
<p>I am trying to add a &quot;page under construction&quot; png file to only 1 of the 3 pages under my release menu which has &quot;release 1&quot;, &quot;release 2&quot;, and &quot;release 3&quot;.</p> <pre><code>{def underConstruction(): my_img = ImageTk.PhotoImage(Image.open('c/path/to/my/png/file') my_label...
<python><tkinter>
2023-05-02 00:45:42
1
449
PChao