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
75,022,951
3,656,056
Storing yaml into AWS SSM store
<p>I have the following YAML file(sample content in the below section) which I would like to store in AWS-SSM. Each property in YAML should be kept as a key/value pair in the AWS parameter store.</p> <pre><code> doe: &quot;a deer, a female deer&quot; ray: &quot;a drop of golden sun&quot; pi: 3.14159 xmas: true fren...
<python><amazon-web-services><yaml><aws-ssm>
2023-01-05 18:37:08
1
3,973
VelNaga
75,022,838
12,014,637
NotImplementedError: Cannot convert a symbolic tf.Tensor to a numpy array
<p>I have a tensorflow custom layer that I want to use with functional API for training. But I get a weird error that I don't know how to fix. Here is the code:</p> <pre class="lang-py prettyprint-override"><code>import math import numpy as np import tensorflow as tf from tensorflow.keras.layers import Input from tenso...
<python><tensorflow><keras><deep-learning>
2023-01-05 18:26:49
0
618
Amin Shn
75,022,789
491,894
I've loaded a yaml file with `!ENV SOME_VAR` and replaced the string with the value. How do I save the original string and not the changed string?
<p>I'm using python 3.x and pyyaml. I'm not married to pyyaml if I need to replace it.</p> <p>There are a number of questions (with answers) on how to replace a value in a yaml file with the value of an environment variable.</p> <p>E.g. <code>db_password: !ENV DB_PASSWORD</code> becomes <code>db_password: s00p3rs3kr3t<...
<python><yaml>
2023-01-05 18:22:54
1
1,304
harleypig
75,022,784
8,968,801
Dynamically Setting the Output Type of Python Function
<p>Okay, I have a set of dictionaries that contain a key/ID and a function. Said dictionaries are used as identifiers that point to a specific cache key and function to update said cache key's associated data.</p> <pre class="lang-py prettyprint-override"><code>from typing import TypedDict, List class CacheIdentifier(...
<python><python-typing>
2023-01-05 18:22:05
1
823
Eddysanoli
75,022,631
1,877,527
Add a grouping level to an existing Pandas groupby object
<p>Let's say I have a frame with a dozen columns, <code>col1</code> through <code>col12</code>. This frame is large, so I want to minimize time spent in grouping.</p> <p>So, I'd like to first group by 3 columns then by a 4th column. I'm using the aggregated data set and using the group as an entire object. So,</p> <pre...
<python><pandas>
2023-01-05 18:07:35
1
732
Philip Kahn
75,022,532
15,171,387
Dealining with missing values in multiple columns of a dataframe in Python
<p>I am dealing with a huge dataframe with hundreds of columns with possibility of missing values in each of the columns. Here is sample:</p> <pre><code>import pandas as pd import numpy as np data = {'a': [1,1,0,1,1], 'b': [&quot;a&quot;, &quot;b&quot;, np.nan, 'c', np.nan], 'c': ['b1','b2',np.nan, 'c...
<python><pandas><missing-data>
2023-01-05 17:58:46
1
651
armin
75,022,459
14,517,622
Get Album Art of a music using ffmpeg in Webp
<p>I am struggling to output thumbnail of an mp3 file in webp format</p> <p>Tried this but it did not worked for .webp</p> <p>I am running this command in AWS lambda function to extract album Art and save in S3.</p> <p><code>ffmpeg -i input.mp3 -an -vcodec copy cover.webp</code></p> <p><a href="https://i.sstatic.net/NY...
<javascript><python><linux><audio><ffmpeg>
2023-01-05 17:50:50
0
847
Arihant Jain
75,022,215
4,247,704
Routing requests to a specific Heroku Dyno
<p>I built an real-time collaboration application with <a href="http://prosemirror.net" rel="nofollow noreferrer">Prosemirror</a> that uses a centralised operational transform algorithm (described <a href="https://marijnhaverbeke.nl/blog/collaborative-editing.html#centralization" rel="nofollow noreferrer">here</a> by M...
<python><heroku><prose-mirror><operational-transform>
2023-01-05 17:27:20
1
427
nehalem
75,022,209
1,833,945
Why this Apache Beam pipeline reading an Excel file and creating a .CSV from it is not working?
<p>I am pretty new in Apache Beam and I am experiencing the following problem with this simple task: I am trying to create a new <strong>.csv</strong> file staring from an <strong>.xlsx</strong> Excel file. To do this I am using Apache Beam with Python 3 language and <strong>Pandas</strong> library. I admit that are al...
<python><pandas><apache-beam><apache-beam-io>
2023-01-05 17:26:54
1
43,315
AndreaNobili
75,022,186
715,036
The git process never exits when running as a Python subprocess
<h2>Background</h2> <p>I'm writing a Python program to process LFS error messages as I have some repos with missing LFS files in Bitbucket Server. The output when running <code>git lfs fetch --all</code> isn't very helpful when you want to find out which LFS files are missing from a repo. That's why I'm making a tool f...
<python><python-3.x><git><subprocess><git-lfs>
2023-01-05 17:25:03
1
721
cb2
75,021,988
2,482,149
Unable to Loop Over Nested Dictionary in Stored Procedure: Psycopg2
<p>I'm trying to add the values of a nested dictionary within a list to a table using a stored procedure in <code>psycopg2</code>. This is the schema I receive from a JSON application:</p> <pre><code>[ { &quot;team_id&quot;: 236, &quot;lineup&quot;: [ { &quot;player_id&qu...
<python><sql><postgresql><stored-procedures><psycopg2>
2023-01-05 17:06:51
1
1,226
clattenburg cake
75,021,969
15,176,150
How does VSCode's Python Extension use the Paths you set?
<p>I'm troubleshooting an issue with VSCode's <a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python" rel="nofollow noreferrer">Python extension</a> trying to load the wrong version of Python.</p> <p>I'd like to know how this extension uses the Path variables you give it in its settings. For exam...
<python><visual-studio-code><python-extensions>
2023-01-05 17:04:35
1
1,146
Connor
75,021,923
7,975,962
pandas - DataFrame.groupby.head with different values
<p>I have two dataframes. One of them has session ids and their cut-off points. The other dataframe has multiple rows for each session and I want to take first n rows of each session and n is the cut-off point from the other dataframe. This is a screenshot of two dataframes.</p> <p><a href="https://i.sstatic.net/ImMAs....
<python><pandas><numpy><group-by>
2023-01-05 17:00:41
1
974
gunesevitan
75,021,879
3,575,623
make install using a conda environement
<p>I'm trying to install <a href="https://bitbucket.org/dmarnetto/haplostrips/src/master/" rel="nofollow noreferrer">HaploStrips</a>, which requires python 2.7 and pip (and a few other libraries). The author suggests to create an anaconda environment using <code>conda create -n haplostrips python=2.7 pandas=0.22 pysam<...
<python><python-2.7><makefile><anaconda>
2023-01-05 16:56:47
0
507
Whitehot
75,021,798
15,176,150
How does VSCode's Python Extension handle a missing .env file?
<p>I'm trying to troubleshoot an issue with VSCode's <a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python" rel="nofollow noreferrer">Python extension</a> loading the wrong version of Python and I'd like to rule out incorrect environment variables being an issue.</p> <p>In the Python Extension's...
<python><visual-studio-code><python-extensions>
2023-01-05 16:49:32
1
1,146
Connor
75,021,750
12,127,578
DeltaTable schema not updating when using `ALTER TABLE ADD COLUMNS`
<p>I'm currently playing with <a href="https://docs.delta.io/latest/index.html" rel="nofollow noreferrer">Delta Tables</a> on my local machine and I encountered a behavior that I don't understand. I create my DeltaTable like so:</p> <pre class="lang-py prettyprint-override"><code>df.write \ .format('delta') \ ....
<python><apache-spark><pyspark><delta-lake>
2023-01-05 16:45:57
1
678
wtfzambo
75,021,685
9,261,745
how to save the picture in a URL into azure blob storage ADLS gen2 in python
<p>I would like to save the picture in some URL into a blob storage directly by python. I tried to use the code in <a href="https://stackoverflow.com/questions/56645082/download-web-images-by-url-from-excel-and-save-to-folders-in-python">Download web images by URL from excel and save to folders in Python</a>. This is h...
<python><pandas><url><azure-blob-storage>
2023-01-05 16:40:28
1
457
Youshikyou
75,021,620
2,237,820
How to select which request from the queue to get the resource in Simpy
<p>I am working on simulating a scheduling algorithm in Simpy. What I need to do is to choose from the queue which requests to get the resource. I have read the examples provided on the Simpy website and the documentation. However, I could not find anything regarding selecting requests from the queue to serve. Priority...
<python><simpy>
2023-01-05 16:35:07
1
551
Alaa
75,021,559
8,261,345
How do I prevent Google Cloud Functions caching results to calls?
<p>I have a simple flask app in a Google Cloud Function that returns different data based on the user's authorization, specified by a token in the header:</p> <pre class="lang-py prettyprint-override"><code>@functions_framework.http def main(request): token = request.headers['Authorization'] data: List[str] = m...
<javascript><python><firebase><google-cloud-platform><google-cloud-functions>
2023-01-05 16:30:19
0
694
Student
75,021,498
4,265,321
conda-provided gfortran cannot compile MPI program
<p>I have an account on a cluster which I access through SSH. The cluster uses Red Hat. My account does not have root privileges.</p> <p>I do not have gfortran installed but I need it to compile a program that I will be using. This program is a Python wrapper of a Fortran code, which uses MPI.</p> <p>I followed <a href...
<python><fortran><mpi><gfortran>
2023-01-05 16:23:51
0
1,343
johnhenry
75,021,371
5,024,631
SKLearn & ElasticNet: Cross validation fails when using Accuracy as a metric
<p>I have a binary classification problem. I've been using <code>cross validation</code> to optimize the <code>ElasticNet</code> parameters. However ElasticNet only seems to work when I supply <code>roc_auc</code> as the scoring method to be used during CV, However I also want to test out a wide range of scoring method...
<python><scikit-learn><classification><elasticnet>
2023-01-05 16:13:27
1
2,783
pd441
75,021,259
9,415,280
how continue recording evolution trainning on tensorflow model in same history file eachtime
<p>I train a big tensorflow model with a lot of data. I need to stop/save and reload it to continu trainning on new data.</p> <p>If I save the history file, can I (and how?) start again the trainning and continu compilling result on the same history file?</p> <p>My two reasons:</p> <p>Keep complete evolution tracking o...
<python><tensorflow><resuming-training>
2023-01-05 16:04:05
1
451
Jonathan Roy
75,021,051
12,968,928
Convert pandas series of strings to a series of lists
<p>For iinstance I have a dataframe as below</p> <pre><code>import pandas as pd df = pd.DataFrame({&quot;col&quot;:['AM RLC, F C', 'AM/F C', 'DM','D C']}) |col -------------------| 0 |&quot;AM RLC, F C&quot; | 1 |&quot;AM/F C&quot; | 2 |&quot;DM&quot; | 3 |&quot;D C&quot; | </code></p...
<python><pandas>
2023-01-05 15:48:25
4
1,511
Macosso
75,020,740
11,644,523
dbt postgres - all models appending schema public_ to output
<p>I am testing a local setup of dbt-postgres. I have a simple model, but for some reason, any table created is being placed in a schema with the prefix <code>public</code> appended to it.</p> <p>Desired output table: <code>public.test</code></p> <p>Current output table: <code>public_public.test</code></p> <p>As you ca...
<python><postgresql><dbt>
2023-01-05 15:25:25
1
735
Dametime
75,020,695
5,680,286
Getting TypeError: 'NoneType' object is not iterable while iterating multi level JSON object
<p>I have following JSON get response:</p> <pre><code>{ &quot;id&quot;: &quot;mov_BO381oEATXonG6bj&quot;, &quot;object&quot;: &quot;movement&quot;, &quot;amount&quot;: 59400, &quot;post_date&quot;: &quot;2020-04-17T00:00:00.000Z&quot;, &quot;description&quot;: &quot;Traspaso de:Fintoc SpA&quot;, &quot;transaction_date&...
<python><json>
2023-01-05 15:22:00
1
317
Bernardo Troncoso
75,020,628
278,638
Avoid formatting issues when warnings.captureWarnings(True) is set
<p>I have created a log handler which logs to a database table, and I wanted to also capture warnings issued by the program into a different table, so used <code>warnings.captureWarnings(True)</code></p> <p>I had some issues with the message formatting in the <code>py.warnings</code> logger - the message always showed ...
<python><logging><sqlalchemy><warnings><python-logging>
2023-01-05 15:17:02
1
2,126
Stev_k
75,020,542
17,487,457
pandas: extract time-of--the day as feature for classification
<p>I have a time series data, with a unix seconds column (among other columns):</p> <pre class="lang-py prettyprint-override"><code>df = pd.DataFrame( { 'user': [3,3,3,3,3,6,6,6], 'timestamp': [1459467971, 1459468020, 1459468026, 1459468031, 1459468036,1513974852, 1513974853, ...
<python><pandas><dataframe>
2023-01-05 15:11:12
2
305
Amina Umar
75,020,539
10,731,820
Number of deleted messages is twice as many as received messages
<p>I created SQS service with terraform</p> <pre><code>resource &quot;aws_sqs_queue&quot; &quot;ses_queue&quot; { name = &quot;ses_queue&quot; message_retention_seconds = 86400 receive_wait_time_seconds = 1 visibility_timeout_seconds = 15 } resource &quot;aws_lambda_event_source_mapping...
<python><amazon-web-services><aws-lambda><terraform><amazon-sqs>
2023-01-05 15:11:05
2
853
psowa001
75,020,279
14,720,380
PyBind11: How to implement Vector of Shared Pointers of Classes with Inheritence? Unable to load a custom holder type from a default-holder instance
<p>I have a base class in c++ that looks like:</p> <pre class="lang-cpp prettyprint-override"><code>class EdgeAttributePipelineStep { public: virtual void setAttributes(Edge&amp; edge) = 0; }; </code></pre> <p>And then some classes that inherit from this class:</p> <pre class="lang-cpp prettyprint-override"><code>c...
<python><c++><pybind11>
2023-01-05 14:51:21
1
6,623
Tom McLean
75,020,276
5,437,090
Drop Duolicates in a Panda DataFrame for timestampe in a certain threshold
<p>I have a Dataframe as follows and would like to remove duplicates with respect to three columns: <code>user</code>, <code>url</code> and <code>timestamp</code> (only if it is less than or equal <code>&lt;= 10 sec</code> of last occurrence). Here I elaborate rows with <code>#</code> comment:</p> <pre><code> timest...
<python><pandas><dataframe><duplicates><mask>
2023-01-05 14:51:15
2
1,621
farid
75,020,272
8,933,502
Calculating an average, when only some "checkpoints" are known
<p>I'm trying to wrap my head around pandas/numpy to do something that should probably be simple (but my lack of knowledge...)</p> <p>The series looks something like this:</p> <pre><code> 2022-01-01 | 100 2022-01-02 | nan 2022-01-03 | nan 2022-01-04 | 200 2022-01-05 | nan 2022-01-06 | nan 202...
<python><pandas><numpy><time-series><series>
2023-01-05 14:51:09
1
842
Samuel GIFFARD
75,020,251
18,205,996
Adding values to cells in a specific column in HTML
<p>I am creating a very basic table in HTML for my Django project. I got some help from <a href="https://stackoverflow.com/questions/75011084/generating-new-html-rows-for-each-document-from-firestore-in-python-django/75011558#75011558">Here</a> to learn how to pass a list from my Django app to my HTML and generate rows...
<python><html><django>
2023-01-05 14:49:27
2
597
taha khamis
75,020,244
3,139,811
Pywin32 COM not able to set attribute keyerror
<p>I'm trying to automate something using its com interface. There are some problems which I can't get my head around.</p> <pre><code>app = DispatchEx('CANoe.Application') configs = app.Configuration.TestConfigurations config = configs.Item(1) unit = config.TestUnits.Item(1) unit.Name unit.Enabled </code></pre> <p>Unti...
<python><com><pywin32><canoe>
2023-01-05 14:49:08
1
857
John
75,020,192
13,994,829
Python-MultiThreading: Can MultiThreading improve "for loop" performance?
<p>As far as my understanding:</p> <ul> <li>MultiThread is an ideal option for <strong>I/O</strong> applications.</li> </ul> <p>Therefore, I test a &quot;for loop&quot; code without any I/O. (As following code)</p> <p>Howerver, it can reduce the execution time from 6.3s to 3.7s.</p> <p>Is the result correct ?</p> <p>or...
<python><multithreading><python-multithreading>
2023-01-05 14:45:13
3
545
Xiang
75,020,141
353,337
Add data to class with `__slots__`, wrap it?
<p>I have a Python object <code>a</code> of class <code>A</code> which is out of my control. I don't know anyhing about <code>A</code>, inclusing its <code>__init__</code>. I would like to add some data to <code>a</code>, but <code>__slots__</code> in <code>A</code> prevents me from doing so. I'd like to work around i...
<python><class><subclass><wrapper>
2023-01-05 14:41:55
1
59,565
Nico Schlömer
75,019,942
12,883,297
Add time delta for 2 columns based on the condition on 1 column in pandas
<p>I have a dataframe</p> <pre><code>df = pd.DataFrame([[&quot;A&quot;,&quot;9:00 AM&quot;,&quot;10:20 AM&quot;],[&quot;A&quot;,&quot;11:12 AM&quot;,&quot;12:32 PM&quot;],[&quot;A&quot;,&quot;1:03 PM&quot;,&quot;1:33 PM&quot;],[&quot;A&quot;,&quot;1:34 PM&quot;,&quot;2:44 PM&quot;],[&quot;B&quot;,&quot;9:00 AM&quot;,&q...
<python><pandas><dataframe><datetime><time-series>
2023-01-05 14:26:24
1
611
Chethan
75,019,865
10,891,675
Python unit tests - mocking imported class methods
<p>I would like to mock some imported class methods and module functions for my unit tests. I tried several ways to define the mocked values but I don't understand why they are not taken into account.</p> <p>I wrote some tests following the advices in <a href="https://stackoverflow.com/questions/16134281/python-mocking...
<python><unit-testing><mocking>
2023-01-05 14:19:51
1
696
Christophe
75,019,800
1,195,909
SQLAlchemy inheritance relations issue
<p>My SQLAlchemy model has a base class <code>Alpha</code> and two derived classes <code>Beta</code> and <code>Gamma</code>. <code>Beta</code> is also a field of <code>Beta</code>. My implementation results in the message error below. How do I fix this join condition issue?</p> <blockquote> <p>AmbiguousForeignKeysError...
<python><inheritance><sqlalchemy>
2023-01-05 14:15:47
1
3,463
msampaio
75,019,532
13,488,334
Local imports work in bundled PyInstaller app but in Python source
<p>This issue has plagued me for the last few months, I need a more experienced opinion. We have a CLI Python application that uses a gRPC server to communicate with other backend services. Its structured something like this:</p> <pre><code>app - gRPC_service - __init__.py - service_related_files.py...
<python><python-3.x><pyinstaller><python-import><python-internals>
2023-01-05 13:55:43
1
394
wisenickel
75,019,496
19,674,402
Enable "Try it out" in OpenAPI so that no need to click
<p>I'm using FastAPI and OpenAPI/Swagger UI to see and test my endpoints.</p> <p>Each time I use an endpoint for the first time, in order to test it, I have to first click the <kbd>Try it out</kbd> button, which is getting tedious.</p> <p>Is there a way to make it disappear and be able to test the endpoint instantly?</...
<python><swagger><fastapi><swagger-ui><openapi>
2023-01-05 13:53:54
1
496
PythonForEver
75,019,472
8,868,699
Apply pandas groupby, sum and mean based on another column
<p>Im working on a data frame. Trying to group, sum, and mean on based on the other column. As all the 3 operations are in one. Im unable to find any solution. Please help</p> <p><a href="https://i.sstatic.net/nRxJH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nRxJH.png" alt="enter image description h...
<python><pandas><group-by>
2023-01-05 13:51:40
2
1,649
Hayat
75,019,357
5,084,566
How to write videos with half of duration using OpenCV?
<p>I have a mp4/avi videos with duration 10 minutes and FPS 30. I want to reduce duration to 5 mins but FPS still 30. It means that the new videos will drop a half of frame (for example, <code>f0 f2 f4</code> compare with original video <code>f0 f1 f2 f3 f4</code>). How can I do it on opencv? This is current code to ge...
<python><python-3.x><opencv>
2023-01-05 13:42:58
2
395
Moon Lee
75,019,347
8,844,500
Style not compatible with Jupyter-Book when using python-sphinx autodoc to generate API documentation
<p>I'd love to use the so elegant Jupyter-Book to construct documentation for my packages. I've tried quite a lot, and here is an example I'm finalizing those days :</p> <ul> <li>the package is available on a gitlab repository <a href="https://framagit.org/nlp/iamtokenizing" rel="nofollow noreferrer">https://framagit.o...
<python><jupyter-notebook><python-sphinx><documentation-generation><jupyterbook>
2023-01-05 13:42:29
0
329
FraSchelle
75,019,302
4,114,325
Python sum over map over list
<p>From Mathematica I am used to summing over a map over a list with a very short and concise syntax. E.g. to sum a map over a polynomial function:</p> <pre><code>myList = {1,2,3}; output = Sum[ x^3+x^2+x , { x, myList } ] </code></pre> <p>To do the same thing in Python, I came up with the following syntax:</p> <pre><c...
<python>
2023-01-05 13:39:04
2
1,023
Kagaratsch
75,019,188
4,847,250
How do I compute the barycenter of an histogram represented as polar coordinate
<p>I display a histogram as a polar plot and I want to display the barycenter to see if there is a dominant orientation of the histogram. My issue is when the histogram have a lot of 0 and 2pi value, the barycenter is not working (because 0 and 2pi is the same angle in the polar plot)</p> <p>So I get something like thi...
<python><polar-coordinates>
2023-01-05 13:29:58
1
5,207
ymmx
75,019,075
5,353,753
Comparing two dataframes columns
<p>I have two dataframes that are structure wise equal.</p> <p>Both has to following format:</p> <pre><code>file_name | country_name | country_code | ..... </code></pre> <p>I want to compare the two, and get a percentage of equality for each column.</p> <p>The second data frame is the test dataframe, that holds the tru...
<python><pandas><dataframe>
2023-01-05 13:20:41
2
40,569
sagi
75,018,977
1,325,133
Splitting nested lists into DataFrame
<p>I have the following data:</p> <pre><code>{ &quot;load_avg_1min&quot;: &quot;0.40&quot;, &quot;load_avg_5min&quot;: &quot;0.25&quot;, &quot;load_avg_15min&quot;: &quot;0.28&quot;, &quot;processes_total&quot;: &quot;719&quot;, &quot;processes_running&quot;: &quot;3&quot;, &quot;cpu_state_user&...
<python><pandas><dataframe>
2023-01-05 13:13:45
1
16,889
felix001
75,018,833
3,444,107
Flink Postgres query to jsonb column gives jdbc failure
<p>I am using PyFlink 1.16 and flink-connector-jdbc-1.16.0.jar to query Postgres table with a jsonb column</p> <pre><code>sql = &quot;SELECT entity_id FROM event_files&quot; table2 = table_env.sql_query(sql) table2.execute().print() </code></pre> <p>It failed with this error:</p> <pre><code>Caused by: java.lang.Unsuppo...
<python><java><postgresql><apache-flink><pyflink>
2023-01-05 13:02:12
0
1,032
Sami Badawi
75,018,635
1,397,946
Detect equidistant lines on an image
<p>I am trying to detect horizontal distance markers on a measurement plate like on the picture below. The marked area shows which lines I need to detect. You will notice there is a problem in the image, an extra line (marked with an arrow) that should not be there - it's just an artifact and it's messing with my initi...
<python><opencv><computer-vision>
2023-01-05 12:47:57
0
11,517
Lukasz Tracewski
75,018,630
1,058,671
Why pyright doesn't allow str.join of a non-literal set?
<p>The following code produces the error message:</p> <blockquote> <ol> <li>Operator &quot;|&quot; not supported for types &quot;set[str]&quot; and &quot;set[str]&quot;</li> </ol> <p>......   Operator &quot;|&quot; not supported for types &quot;set[str]&quot; and &quot;set[str]&quot; when expected type is &quot;Iterab...
<python><python-3.x><python-typing><python-3.10><pyright>
2023-01-05 12:47:20
0
6,651
Yam Mesicka
75,018,374
20,078,696
Why is the turtle offset?
<p>I am trying to create a program to move the turtle to where the mouse is. Right now I am doing:</p> <pre><code>import turtle t = turtle.Turtle() canvas = turtle.getcanvas() width = canvas.winfo_width() height = canvas.winfo_height() midpointX = width / 2 midpointY = height / 2 t.speed(0) while True: mouseX,...
<python><turtle-graphics><python-turtle>
2023-01-05 12:26:00
1
789
sbottingota
75,018,324
1,240,487
What is the difference between pydantic Field and Annotated?
<p>Those two concepts <strong>Field</strong> and <strong>Annotated</strong> seem very similar in functionality. For example, I can define the same variable in any way as:</p> <pre><code>temperature: float = Field(0.0, ge=0, le=1) temperature: Annotated[confloat(ge=0, le=1),...] = 0.0 </code></pre> <p>Is there any drawb...
<python><pydantic>
2023-01-05 12:22:10
2
1,373
gench
75,018,307
12,210,908
Undefined Reference to major, minor and makedev in libpython*.so file during Python-2.7.13 and Python-3.5.7 build
<p>I am cross-compiling <code>python-2.7.13</code> and <code>python-3.5.7</code> from scratch using the following configuration command line options to the <code>./configure</code> binary:</p> <pre><code>CONFIG_SITE=config.site ./configure \ --host=arm-linux-gnueabi \ --build=x86_64-pc-linux-gnu \ CC=/toolc...
<python><python-3.x><python-2.7><cross-compiling>
2023-01-05 12:20:53
1
368
strikersps
75,018,094
10,896,385
Map dataframe function without lambda
<p>I have the following function:</p> <pre><code>def summarize(text, percentage=.6): import numpy as np sentences = nltk.sent_tokenize(text) sentences = sentences[:int(percentage*len(sentences))] summary = ''.join([str(sentence) for sentence in sentences]) return summary </code></pre> <p>And I want ...
<python><pandas>
2023-01-05 12:03:28
1
303
Mus
75,017,751
13,839,945
Using multiple CPU in PyTorch
<p>I dont have access to any GPU's, but I want to speed-up the training of my model created with PyTorch, which would be using more than 1 CPU. I will use the most basic model for example here.</p> <p>All I want is this code to run on multiple CPU instead of just 1 (Dataset and Network class in <em>Appendix</em>).</p> ...
<python><pytorch>
2023-01-05 11:30:27
1
341
JD.
75,017,723
10,866,873
Python get/set port and identify it without communication
<p>I am selecting a random port that all my applications can use to communicate on that changes each time.</p> <pre class="lang-py prettyprint-override"><code>s = socket(AF_INET, SOCK_STREAM) s.bind(('', 0)) addr = s.getsockname() port = addr[1] s.close() </code></pre> <p>Now I'm looking for a good way for other script...
<python><python-sockets>
2023-01-05 11:27:23
0
426
Scott Paterson
75,017,628
19,003,861
Generate QR Code to URL with variable (page/pk_ID)
<p>I am trying to generate a QR code that is unique to the <code>page_id</code>.</p> <p>The aim is to send a user that <strong>is not</strong> <code>request.user</code> to a specific page (<code>loyalty_card/UserProfile_ID</code>).</p> <p>As an example:</p> <ol> <li>site/loyaltycard/UserProfile_1 - would have qr code l...
<python><django><django-models><django-views>
2023-01-05 11:18:47
1
415
PhilM
75,017,489
3,484,477
Install older version of pytorch with GPU support using conda
<p>I would like to install <code>pytorch</code> <code>1.11</code> using <code>conda</code> with <code>gpu support</code> for a specific cuda version, e.g. <code>11.6</code>.</p> <p>One can do the following to install latest version:</p> <pre><code>conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorc...
<python><pytorch><anaconda><conda>
2023-01-05 11:07:11
1
1,643
Meysam Sadeghi
75,017,331
3,608,005
RangeX in geoviews, trying to understand x axis range
<p>Can someone please explain to me the meaning of the x axis range retrieved using RangeX for geospatial data?</p> <pre><code>import geoviews as gv import holoviews as hv background = gv.tile_sources.Wikipedia rng = hv.streams.RangeX(source=background) background </code></pre> <p><a href="https://i.sstatic.net/Zk0P6....
<python><holoviews><geoviews>
2023-01-05 10:54:02
1
5,448
Moritz
75,017,330
14,534,957
A constructor for dataclasses with randomized attribute values
<p>Hi could someone explain whats happening here: i want to instantiate objects with random values.</p> <pre><code>@dataclass class Particle: pos = (random.randint(0, 800), random.randint(0, 800)) for _ in range(3): p = Particle() print(p.pos) </code></pre> <p>prints:</p> <ul> <li>(123, 586)</li> <li>(123...
<python><python-dataclasses>
2023-01-05 10:53:51
1
418
user14534957
75,017,277
2,397,072
Dealing with multiple subprocesses writing to stdout in python
<p>I have multiple subprocesses (opened with <code>subprocess.Popen</code>) continuously writing lots of short lines to stdout (several MB/s).<br /> Sometimes, I guess when two subprocesses write at the exact same time to stdout, the output in stdout is an unreadable line.</p> <p>For example, subprocess 1 writes AAAA, ...
<python><subprocess><stdout><multiprocess>
2023-01-05 10:48:39
1
301
Guillaume Adam
75,017,224
2,802,576
Pythonnet cannot convert object to target type
<p>Using <a href="https://github.com/pythonnet/pythonnet" rel="nofollow noreferrer">pythonnet</a> I am calling a Python function, which returns an object, from my C# script. Once I get the result from Python function I want to be able to cast/convert this Python object into C# user defined class. I tried using <code>As...
<python><c#><python.net>
2023-01-05 10:44:50
0
801
arpymastro
75,017,208
4,534,466
Dask using too much memory when reading parquet
<p>I have a rather large parquet file (~1.35Gb) that I'm trying to read. I'm using Google Colab Pro which gives me 25 Gb of RAM. I ran the following code:</p> <pre><code>import dask.dataframe as dd data = dd.read_parquet(DATA_DIR / 'train.parquet', chunksize=100) data.head() </code></pre> <p>And ran out of memory, is t...
<python><dataframe><dask><parquet><dask-dataframe>
2023-01-05 10:43:42
1
1,530
João Areias
75,017,187
17,124,619
Sudo apt-get install commands with Jenkins
<p>I have a jenkins server open and I'm attempting to sudo install:</p> <pre><code>sudo apt-get install libsqlite3-dev </code></pre> <p>Because I am using a pipeline that runs a python script, whereby this script would return the following error:</p> <blockquote> <p>builtins.ModuleNotFoundError: No module named '_sqlit...
<python><jenkins>
2023-01-05 10:42:02
0
309
Emil11
75,017,086
10,729,292
Extracting the largest rectangle like object from an image with any possible orientation using openCV?
<p>I have pictures of cheques which were scanned and are on A4 sheets now. I need to extract those cheques, which can be a bit tilted or rotated. Now using an AI model would be my last preference. I tried the following script and it gave away every little and tiny rectangle from the image</p> <pre><code>import cv2 impo...
<python><opencv><computer-vision>
2023-01-05 10:33:59
0
1,558
Sadaf Shafi
75,017,033
2,418,162
Run Selenium directly on Pydroid3 on Android
<p>my goal is to run a python script that uses Selenium to manipulate the chrome browser, directly with Pydroid 3 app on my android smartphone (without a pc connection).</p> <p>I followed the instructions at the link <a href="https://chromedriver.chromium.org/getting-started/getting-started---android" rel="nofollow nor...
<python><selenium><selenium-webdriver><selenium-chromedriver><pydroid>
2023-01-05 10:30:07
0
445
Fobi
75,016,854
11,945,144
How can I resolve write errors that I have in my data?
<p>I have a dataframe (more than 1 million rows) that has an open text columns for customer can write whatever they want. Misspelled words appear frequently and I'm trying to group comments that are grammatically the same.</p> <p>For example:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>...
<python><dataframe><nlp><misspelling><write-error>
2023-01-05 10:14:30
2
343
Maite89
75,016,612
4,317,058
How to draw 2 readily available Figure objects alongside
<p>Let's see a contrived example of 2 <code>matplotlib.pyplot</code> functions returning a plot, which then may be accessed through <code>plt.gcf()</code> or <code>plt.gca()</code> methods:</p> <pre><code>x = np.linspace(-5, 5, 11) y = x y_2 = x * x plt.plot(x,y) fig_1 = plt.gcf() ax_1 = plt.gca() #plt.close() plt.pl...
<python><matplotlib>
2023-01-05 09:56:02
1
25,529
Sergey Bushmanov
75,016,581
11,653,949
Which catalog is Airflow viewing during initialization of SensorOperator?
<p>I try open fil during performing <strong>init</strong> method in SensorOperator and get error in Airflow:</p> <blockquote> <p>Broken DAG: [/opt/airflow/dags/get_stars_and_print.py] Traceback (most recent call last): File &quot;/opt/airflow/dags/get_stars_and_print.py&quot;, line 69, in <strong>init</strong> self.sta...
<python><airflow>
2023-01-05 09:53:42
1
602
Alexander Lopatin
75,016,478
14,868,949
Split and merge 2 columns pandas
<p>Is it possible to have this kind of disposition in pd.DataFrame : <a href="https://i.sstatic.net/n73Pz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n73Pz.png" alt="enter image description here" /></a></p>
<python><pandas>
2023-01-05 09:44:35
2
648
ArrowRise
75,016,292
5,349,291
Modifing the return value of reduce() expression modifies the input
<p>I wrote a function to collect all values into a single list from a dictionary where each value is a list. However, when I later modified that list, I found that my original dictionary was modified too!</p> <pre><code>from functools import reduce d = {'foo': [1,2,3]} all_vals = reduce(lambda x, y: x + y, d.values()...
<python>
2023-01-05 09:29:55
3
2,074
mchristos
75,016,212
2,392,965
PaddleOCR Error flag 'flagfile' was defined more than once
<p>Am encountering an issue running PaddleOCR on M1 Macbook</p> <p>ERROR: flag 'flagfile' was defined more than once (in files '/Users/paddle/xly/workspace/f2bafd01-b80e-4ac8-972c-1652775b2e51/Paddle/build/third_party/gflags/src/extern_gflags/src/gflags.cc' and '/tmp/gflags-20211021-3963-1mi18ai/gflags-2.2.2/src/gflags...
<python><paddle-paddle><paddleocr>
2023-01-05 09:21:40
2
443
user2392965
75,016,155
8,622,404
converting onnx model to tensorflow fails
<p>I am trying to convert <a href="https://github.com/facebookresearch/detr" rel="nofollow noreferrer">detr model</a> to tensor flow using onnx. I converted the model using <code>torch.onnx.export</code> with opset_version=12.(which produces a <code>detr.onnx</code> file)</p> <p>Then I tried to convert the onnx file to...
<python><tensorflow2.0><onnx>
2023-01-05 09:16:59
2
356
kingGarfield
75,016,142
16,591,917
Did the Panel class move to another library in bokeh for new version of Bokeh
<p>I have a bokeh application using Tabs and Panel widgets. I used to do: <code>from bokeh.models import Tabs,Panel</code></p> <p>I recently did a new installation of python 3.8 and subsequently bokeh (3.0.2) and now <code>Panel</code> cannot be imported from <code>bokeh.models</code>. Online examples cite importin...
<python><tabs><bokeh><panel>
2023-01-05 09:15:46
1
319
JacquesStrydom
75,016,130
6,007,601
Multi clients modbus to single modbus server
<p>I have two python scripts which need to get data from the same modbus server.</p> <p>However they cannot be simultaneously connected to the same modbus server, so I am looking for a &quot;proxy&quot; software.</p> <p>This proxy will then sequentially transfer the modbus queries to the modbus server. Solution should ...
<python><network-programming><modbus>
2023-01-05 09:14:58
2
585
clouvis
75,016,050
11,264,031
How to perform async commit when using kafka-python
<p>I'm using <code>kafka-python</code> library for my fastapi consumer app and I'm consuming messages in batch with maximum of 100 records. Since the topic has huge traffic and have only one partition, consuming, processing and committing should be as quick as possible hence I want to use <code>commit_async()</code>, i...
<python><apache-kafka><kafka-consumer-api><kafka-python>
2023-01-05 09:08:34
1
426
Swastik
75,015,571
12,436,050
Error: Time out while performing API call in Python
<p>I have a list (lst) which is a list of list. There are 19 elements in this list and each element has ~2500 strings.</p> <pre><code>lst [['A', 'B', 'C',...]['E', 'F', 'G',....][.....]] </code></pre> <p>I am using these strings (A,B....) to call an API endpoint ('q':element). However after ~1800 strings, I am gettin...
<python><python-requests>
2023-01-05 08:21:32
1
1,495
rshar
75,015,557
516,268
How to set xaxis ticks order?
<p>df:</p> <pre><code> USER_ID EventNum 0 1390 17 1 4452 15 2 995 14 3 532 14 4 3281 14 ... ... ... 5897 4971 1 5898 2637 1 5899 792 1 5900 5622 1 5901 1 1 [5902 row...
<python><pandas><matplotlib>
2023-01-05 08:19:48
1
1,327
l4rmbr
75,015,435
9,257,578
How to flatten the dataset properly
<p>I have a dataset like this <a href="https://i.sstatic.net/eHpu8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eHpu8.png" alt="enter image description here" /></a></p> <p>The problem here is i want to have <code>General_officers_0_Name</code> , <code>General_officers_0_Title</code>, <code>General_off...
<python><json><pandas><dataframe>
2023-01-05 08:07:13
0
533
Neetesshhr
75,015,390
7,125,235
The boto3 `list_discovered_resources` method is returning deleted resources even when flag `includeDeletedResources` is set to False
<p>I am using a python script to fetch active resources from my AWS account. I am using the following method:</p> <pre class="lang-py prettyprint-override"><code>member_session = boto3.session.Session( aws_access_key_id=credentials[&quot;Credentials&quot;][&quot;AccessKeyId&quot;], aws_secret_access_key=cre...
<python><amazon-web-services><boto3><aws-config>
2023-01-05 08:03:03
1
613
sparkstar
75,015,228
3,103,957
Python import module approaches
<p>I have created a package named mod and placed a python file inside it (a.k.a: module). The name of the python file is printme.py.</p> <p>I import the module in the below couple of ways.</p> <pre><code>import mod.printme ['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spe...
<python><import><module><namespaces>
2023-01-05 07:45:54
1
878
user3103957
75,014,987
72,911
How do I add a chain of trust with x509.CertificateBuilder?
<p>I'm building a certificate with <a href="https://cryptography.io/en/latest/x509/reference/#x-509-certificate-builder" rel="nofollow noreferrer">cryptography.x509.CertificateBuilder</a>:</p> <pre><code>from pathlib import Path from cryptography import x509 from cryptography.hazmat.primitives.asymmetric import rsa fro...
<python><cryptography><x509><python-cryptography>
2023-01-05 07:18:59
0
9,642
Gary van der Merwe
75,014,976
3,082,759
How to fit long time period data into Regression models in scikit-learn?
<p>I'm working on the regresion model with population and demand values my data is for period from 1980 to 2021 by country, below example where under year is the number of population and under year_dem is the demand for item.</p> <p><a href="https://i.sstatic.net/Kd80V.png" rel="nofollow noreferrer"><img src="https://i...
<python><scikit-learn><forecasting>
2023-01-05 07:18:00
0
387
PiotrK
75,014,968
5,753,454
What is the best way to handle boolean bounds with scipy's minimize function?
<p>I am trying to find the minimum value of a function that takes <code>float</code> and <code>bool</code> values as input.</p> <pre class="lang-py prettyprint-override"><code>def function_to_optimize(a : float, b : float, c : bool) -&gt; float: # do some calculation... </code></pre> <p>How do I define the <code>bo...
<python><scipy-optimize><scipy-optimize-minimize>
2023-01-05 07:17:12
0
2,104
FTM
75,014,768
4,414,359
Why is json.loads throwing JSONDecodeError: Expecting value
<p>I have a string like:</p> <pre><code>j = '{&quot;type&quot;:&quot;x&quot;,&quot;key&quot;:&quot;A&quot;,&quot;attributes&quot;:{&quot;label&quot;:&quot;test&quot;,&quot;visible&quot;:True,&quot;advancedOptions&quot;:True},&quot;fees&quot;:[{&quot;type&quot;:&quot;set&quot;,&quot;key&quot;:&quot;fee&quot;,&quot;attri...
<python><json>
2023-01-05 06:52:38
1
1,727
Raksha
75,014,747
10,576,494
How to initialize locations of numpy array using dictionary keys and values?
<p>I have the following numpy array which is basically a 3 channel image:</p> <pre><code>arr = np.zeros((6, 4, 3), dtype=np.float32) # dictionary of values, key is array location values_of_channel_0 = { (0, 2) : 1, (1, 0) : 1, (1, 3) : 5, (2, 1) : 2, (2, 2) : 3, ...
<python><python-3.x><numpy>
2023-01-05 06:48:52
1
4,781
Elad Maimoni
75,014,563
4,133,188
Pytorch find the matching 2x2 tensor in a batch of 2x2 tensors
<p>I have a <code>2x2</code> reference tensor and a batch of candidate <code>2x2</code> tensors. I would like to find the closest candidate tensor to the reference tensor by summed euclidean distance over the identically indexed (except for the batch index) elements.</p> <p>For example:</p> <pre><code>ref = torch.as_te...
<python><pytorch>
2023-01-05 06:27:17
1
771
BeginnersMindTruly
75,014,470
10,450,242
Django Many to Many field dependent on another many to many field
<p>I'm creating two many-to-many fields based on same model in a single model. I would like to show only those instances in second many-to-many field which are selected in first many to many field to further apply selection. Through which approach should i handle this behaviour.</p> <pre><code>class Params(models.Model...
<python><django><django-models>
2023-01-05 06:15:21
1
346
Kashan
75,014,452
18,059,131
Cannot connect to chrome at 127.0.0.1 python undetected-chromedriver
<p>Running the following on a machine running Ubuntu 22.094 LTS:</p> <pre><code>chrome_options = Options() chrome_options.add_argument(&quot;--headless&quot;) chrome_options.add_argument(&quot;--no-sandbox&quot;) driver = uc.Chrome(executable_path='/home/samuel04/chromedriver', chrome_options=chrome_options) </code></p...
<python><ubuntu><selenium-webdriver><selenium-chromedriver><undetected-chromedriver>
2023-01-05 06:12:49
0
318
prodohsamuel
75,014,245
1,625,487
Python Gunicorn with Gevent workers very slow than pure flask for time.localtime
<p>I have a controller that's very slow when running in Gunicorn/Gevent (21sec) over pure Flask (5s)</p> <p>Upon profiling there are 300K calls to Python's built-in method <code>time.localtime</code>. Here's a simplified controller that also shows this behavior</p> <pre><code>import time def my_time(): time.localti...
<python><performance><gunicorn><gevent>
2023-01-05 05:36:48
0
2,432
Abs
75,014,117
5,640,258
What's the difference between Bazel's py_library and py_binary rules
<p>Bazel's <a href="https://bazel.build/reference/be/python#py_library" rel="nofollow noreferrer">documentation</a> explains how to use each, but I don't understand the difference in their nature. Aren't all python files executables anyway? What difference does it make to specify it is a binary?</p>
<python><bazel><bazel-rules>
2023-01-05 05:16:56
2
494
A. Fenzry
75,013,812
2,148,718
Access Google Cloud Storage object in a project that I don't belong to
<p>There is a GCP project that contains a bucket that I have read and write permissions to, but I don't know the name of the project nor am I part of the project. None of the contents of this bucket are public.</p> <p>I have successfully authenticated my user locally using <code>gcloud auth application-default login</c...
<python><google-cloud-platform><google-cloud-storage><google-api-python-client>
2023-01-05 04:18:04
1
20,337
Migwell
75,013,720
12,883,297
Select the dataframe based on the certain time value in pandas
<p>I have a dataframe</p> <pre><code>df = pd.DataFrame([[&quot;A&quot;,&quot;11:40 AM&quot;],[&quot;B&quot;,&quot;12:51 PM&quot;],[&quot;C&quot;,&quot;6:33 PM&quot;],[&quot;D&quot;,&quot;11:13 AM&quot;],[&quot;E&quot;,&quot;7:13 PM&quot;]],columns=[&quot;id&quot;,&quot;time&quot;]) </code></pre> <pre><code>id time A...
<python><pandas><dataframe><time-series><timestamp>
2023-01-05 04:00:33
1
611
Chethan
75,013,708
10,483,893
Finding local minima and maxima
<p>The implementation from Geeksforgeeks <a href="https://www.geeksforgeeks.org/find-indices-of-all-local-maxima-and-local-minima-in-an-array/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/find-indices-of-all-local-maxima-and-local-minima-in-an-array/</a> is wrong. If you have consecutive-duplicates, things ...
<python><algorithm>
2023-01-05 03:57:02
2
1,404
user3761555
75,013,651
9,359,102
Django makemigrations : IndexError: list index out of range
<p>When I attempt to run python3.8 makemigrations, I get the following :</p> <pre><code>File &quot;/usr/lib/python3.8/gettext.py&quot;, line 436, in _parse plural = v[1].split('plural=')[1] IndexError: list index out of range </code></pre> <p>Upon detailed inspection by running python3.8 manage.py runserver , I observe...
<python><django><django-i18n>
2023-01-05 03:46:25
1
489
Earthling
75,013,555
2,101,043
string conversion with exponential notation
<p>I have a value that has exponential notation in it which I wanted to covert to string in python, tried the below ways, but it gets converted e+100,</p> <pre><code>value=5066e97 str(value) results in '5.066e+100' f'{value}' results in '5.066e+100' value.__str__() results in '5.066e+100' '{}'.format(tag) results in '5...
<python><python-3.x><string><scientific-notation>
2023-01-05 03:23:45
1
2,062
Sai
75,013,480
5,621,387
error while adding multiple triggers to same glue workflow via boto3
<p>Task that I wanted to achieve is: I wanted to create workflow, add jobs and triggers to workflow and run the workflow</p> <p>I am using below code to create the workflow</p> <pre><code>import boto3 def create_workflow(wf_name): response = client.create_workflow( Name=wf_name, Description='string' ) return response['...
<python><amazon-web-services><boto3><aws-glue>
2023-01-05 03:09:29
1
789
Naveen Srikanth
75,013,374
18,308,621
How to send a Polars `Expr`/`PyExpr`/`LogicalPlan` from Python to Rust?
<p>In a single process, I could write an Polars <code>Expr</code> and then use it on <code>DataFrame</code> by <code>with_column</code> or <code>select</code>.</p> <p>But in another scenario of realtime financial data, I have a rust process which has a lot of history and realtime data(<code>DataFrame</code>) as a serve...
<python><rust><python-polars><rust-polars>
2023-01-05 02:41:51
1
331
Hakase
75,013,274
14,584,978
How to re-group parquet files using polars (in file storage)
<p>I am using a dataset of multiple data frames as a makeshift data warehouse accessible to Power BI and python use cases. How can I regroup the data using polars into data frames of a particular size?</p> <pre><code>from pathlib import Path import uuid import polars as pl def repartition(directory_to_repartition, ta...
<python><dataframe><parquet><partitioning><python-polars>
2023-01-05 02:22:02
1
374
Isaacnfairplay
75,013,126
3,624,549
python - Convert Panda Dataframe string-column into bigquery.SchemaField "TIMESTAMP"
<p>I am trying to load a <code>BigQuery Table</code> from a python panda <code>Dataframe</code>.</p> <p>the csv file has the content:</p> <pre><code>t_time 2023-01-01 07:20:54.272000 UTC 2023-01-02 04:22:26.914000 UTC 2023-01-03 04:32:38.663000 UTC </code></pre> <p>the BigQuery table has one column <code>t_time</code> ...
<python><pandas><dataframe><google-bigquery>
2023-01-05 01:53:41
1
2,420
Alg_D