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,366,550
2,011,284
SQLAlchemy: Difference between session.commit() and session.execute('COMMIT')
<p>I'm trying to understand the difference between <code>session.commit()</code> and <code>session.execute('COMMIT')</code> but I can't find anything in the documentation.</p> <p>They seem to do different things, for example, this:</p> <pre><code>db.session.commit() db.session.execute(&quot;VACUUM ANALYZE my_table;&quo...
<python><sqlalchemy>
2023-05-30 15:48:28
0
4,927
CIRCLE
76,366,462
11,065,874
fastapi body not working properly with Body and Depends for singular values in Body
<p>I have this small fastapi application</p> <pre><code>import uvicorn from fastapi import FastAPI, Body, Query from fastapi import Path app = FastAPI() @app.get(&quot;/test/{test_id}&quot;) def test( id: str = Path(...), q: str = Query(...), b: str = Body(...) ): return &quot;Hello world...
<python><fastapi>
2023-05-30 15:36:50
1
2,555
Amin Ba
76,366,458
223,992
Python parse POST in Lambda
<p>I am trying to write a simple HTTP POST handler in Python (running on Lambda) dealing with data sent from a simple html form (i.e. application/x-www-form-urlencoded). I am not very familiar with Python. My code appears to be parsing the data but the output is not a form which Python can process?</p> <p>I was using t...
<python><aws-lambda>
2023-05-30 15:36:11
1
48,387
symcbean
76,366,371
12,493,545
How to fix module 'fluidsynth' has no attribute 'Synth'
<h1>What I have tried</h1> <ol> <li>I've installed <code>pip install pyfluidsynth</code> (installed 1.23.5) and <code>pip install fluidsynth</code> (0.2)</li> <li>I followed the solution here, but it didn't work for me. I also think that this wouldn't have been a real solution since it links an older version: <a href="...
<python><ubuntu><fluidsynth>
2023-05-30 15:25:04
1
1,133
Natan
76,366,301
18,018,869
detach rectangle from scaling and give it "absolute" coordinates, or autoscale the rectangle
<p>This is the layout I am trying to achieve: <a href="https://i.sstatic.net/b5Hxf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/b5Hxf.png" alt="My Plot" /></a><br> I actually manage to do this with this code:</p> <pre class="lang-py prettyprint-override"><code>def create_bcs_plot(x_data: tuple = tuple...
<python><matplotlib><python-imaging-library>
2023-05-30 15:17:49
0
1,976
Tarquinius
76,366,229
10,266,106
Multiprocess Sharing Static Data Between Process Jobs
<p>Consider the following Python function to be parallelized, which utilizes an georeferenced ndarray (assembled from rioxarray) and a shapefile. This function uses both these datasets to generate map plots with Matplotlib/CartoPy, the dependent variable being changes in map domain extent. Note that code to govern cosm...
<python><matplotlib><multiprocessing><python-multiprocessing><shared-memory>
2023-05-30 15:08:07
1
431
TornadoEric
76,366,195
3,080,056
Python logger code stopping code from executing
<p>The below code stops my class from running, could someone please tell me why. From what I can tell it is the logger.FileHandler section but I don't understand why, I use the same code in a different script without issue. I have checked the file location and it exists and the IIS server user has write access.</p> <...
<python><logging>
2023-05-30 15:03:59
0
1,564
Blinkydamo
76,366,153
3,614,254
Python Selenium-Beautifulsoup not loading dynamic text
<h2>Problem</h2> <p>I'm scraping a dynamic page - one that appears to be loading results from a database for display - but, it appears, I'm only getting the placeholder for the text elements rather than the text itself. The page I'm loading is: <code>https://www.bricklink.com/v2/search.page?q=8084#T=S</code></p> <h2>E...
<python><selenium-webdriver><beautifulsoup>
2023-05-30 14:58:21
1
557
James B
76,366,080
9,002,568
Get the selected date from python/nicegui
<p>I have two functions for getting date from user, which are:</p> <pre class="lang-py prettyprint-override"><code>def date_selector(): with ui.input('Date') as date: with date.add_slot('append'): ui.icon('edit_calendar').on('click', lambda: menu.open()).classes('cursor-pointer') with ui.men...
<python><nicegui>
2023-05-30 14:50:32
1
593
kur ag
76,366,003
9,692,180
Not possible to access selected file name in Panel FileInput widget
<p>I am using python Panel FileInput widget (panel==0.13.0) to upload a file. Upload works, but I can’n find a way to access uploaded file name. However, after selecting file the widget displays filename next to it, but filename is not included in objects, nor filename,…</p> <p>Using file_input.get_param_values(), I wi...
<python><widget><bokeh><panel>
2023-05-30 14:41:23
0
787
Léo SOHEILY KHAH
76,365,676
11,649,050
Huggingface datasets.DatasetDict gives only labels to transform preprocessing method
<p>I'm trying to use Huggingface's datasets and transformers libraries to train a model on the CIFAR10 dataset. For the specific model I'm using however, there needs to be preprocessing on the images, which I do using the <code>.with_transform()</code> method. When picking individual datapoints for visualizing or testi...
<python><pytorch><huggingface-transformers><huggingface-datasets>
2023-05-30 14:05:24
0
331
Thibaut B.
76,365,674
5,704,159
dataframe bar plot not looks good
<p>I'm trying to plot data with ~2000 values as bar kind, but the plot looks bad. probably because the amount of values.</p> <p>In case I have 500 values, the plot looks ok.</p> <p>Here is my simple code:</p> <pre><code>data = { 'du': duList, 'sum_of_avg': sum_of_avg, 'sum_of_max': s...
<python><tkinter><plot>
2023-05-30 14:05:18
0
429
gogo
76,365,636
5,371,505
Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`
<ul> <li>I am trying to run my poetry based python project inside docker using docker compose</li> <li>When I run the application, it works but it gives me this warning</li> </ul> <pre><code>ch_news_dev_python | Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. Yo...
<python><python-packaging><python-poetry>
2023-05-30 14:01:01
5
6,352
PirateApp
76,365,600
1,838,076
Python-MySQL connector demo works on WSL but fails when run from Windows
<p>I have a simple demo program trying to demonstrate the connection to MySQL from Python, that works fine on WSL for fails on Windows.</p> <p>Here is the sample code</p> <pre class="lang-py prettyprint-override"><code>import mysql.connector con = mysql.connector.connect( host='mysql-host', user='mysql-user', ...
<python><mysql><windows>
2023-05-30 13:57:07
1
1,622
Krishna
76,365,578
1,736,407
TypeError: Parameter to MergeFrom() must be instance of same class: expected google.cloud.dataproc.v1.WorkflowTemplate got str
<p>I am trying to write a Google cloud function that imports a Dataproc Workflow template from storage, and invokes the workflow. I am getting the above <code>TypeError</code> when trying to instantiate the template. Here is the offending piece of code:</p> <pre class="lang-py prettyprint-override"><code> # crea...
<python><google-cloud-platform><google-cloud-functions><google-cloud-dataproc>
2023-05-30 13:54:21
1
2,220
Cam
76,365,558
353,337
Match at whitespace with at most one newline in regex
<p>I would like to match <code>a b</code> if between <code>a</code> and <code>b</code> is only whitespace with at most one newline.</p> <p>Python example:</p> <pre class="lang-py prettyprint-override"><code>import re r = &quot;a\s*b&quot; # ? # should match: print(re.match(r, &quot;ab&quot;)) print(re.match(r, &qu...
<python><regex>
2023-05-30 13:51:39
2
59,565
Nico Schlömer
76,365,515
5,875,041
Django model constraint at least one field from two is not null or empty
<p>I added a constraint to the model but seems that it has no impact because I'm still able to create a model instance without supplying any of the fields. Please help me to enforce the constraint to check is at least one field from two is not null or empty.</p> <p>Fields:</p> <pre><code>class Fruit(models.Model): n...
<python><django><postgresql><django-orm>
2023-05-30 13:46:21
0
445
Artem Dumanov
76,365,100
11,684,473
Argmax of numpy array returning non-flat indices, but on conditioned array
<p>I want to extend following <a href="https://stackoverflow.com/questions/9482550/argmax-of-numpy-array-returning-non-flat-indices">question</a> with particular concern:</p> <p><strong>How to obtain the argmax of <code>a[...]</code> in proper <code>a</code> indices</strong></p> <pre class="lang-py prettyprint-override...
<python><numpy>
2023-05-30 12:56:34
2
1,565
majkrzak
76,365,084
1,200,914
Rollback a SQS message
<p>I would like to know if one can remove a message from SQS FIFO queue only with the response of <code>sqs_client.send_message</code>. I have tried MessageId from the response, but it's not a valid <code>ReceiptHandle</code>.</p> <p>I want to do this because I need to send several messages (like 10), but if one fails,...
<python><amazon-sqs><aws-sqs-fifo>
2023-05-30 12:54:22
0
3,052
Learning from masters
76,365,022
17,596,179
Duplicate callback outputs
<p>So I created this dash project but I keep encountering this <code>Duplicate callback outputs</code> error. This is my <code>index.py</code> file.</p> <pre><code>from dash import html, dcc from dash.dependencies import Input, Output from app import app from pages import portfolio, prices from components import navbar...
<python><flask><plotly-dash>
2023-05-30 12:47:39
0
437
david backx
76,364,921
9,779,999
Seaborn pairplot() error, OptionError: "No such keys(s): 'mode.use_inf_as_null'", any idea?
<p>I am thrown an error when I am trying to apply searbor pairplot. My full script is easy, and is copied as follows:</p> <pre><code>import seaborn as sns import pandas as pd import numpy as np # Creating a sample DataFrame data = { 'A': np.random.randn(100), 'B': np.random.randn(100), 'C': np.random.randn...
<python><seaborn><inf><pairplot>
2023-05-30 12:38:17
5
1,669
yts61
76,364,851
3,008,221
How to create a row number that infer the group it belongs to from another column? Want to do it in both pandas and postgresql/sql
<p>UPDATE: SQL solution provided below, but pandas solution not yet. Appreciate if anyone has a pandas solution.</p> <p>I have a table/pandas dataframe that looks like this:</p> <p><a href="https://i.sstatic.net/73WFh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/73WFh.png" alt="enter image description...
<python><sql><pandas><postgresql>
2023-05-30 12:30:16
1
433
Aly
76,364,741
8,419,962
QT Waiting Spinner not showing
<p>I am trying to use qwaitingspinner.py (<a href="https://github.com/snowwlex/QtWaitingSpinner" rel="nofollow noreferrer">QtWaitingSpinner on GitHub</a>) module in my project. The spinner's parent is an existing, visible QTabWidget page. When I add a page (a process whose initialization takes 5 to 10 seconds during wh...
<python><pyqt6>
2023-05-30 12:16:57
1
418
Pierre Lepage
76,364,689
4,451,521
Tox can not find python interpreter
<p>I just installed pyenv. After that I installed python 3.8.0 in the system</p> <p>So I have</p> <pre><code>pyenv versions system * 3.8.0 (set by /home/me/.pyenv/version) </code></pre> <p>I have the tox.ini</p> <pre><code>[tox] envlist = py36,py38 skipsdist = True [testenv] # instsall pytest in the virtualenv where...
<python><pyenv><tox>
2023-05-30 12:10:21
1
10,576
KansaiRobot
76,364,685
264,136
Not able to update MongoDB database
<p>I have the below doc in DB:</p> <pre><code>{ &quot;_id&quot;: { &quot;$oid&quot;: &quot;6475dd3485054c30333cf52c&quot; }, &quot;job_queue_name&quot;: &quot;CURIE_BLR&quot;, &quot;job_job_id&quot;: 1059, &quot;job_jenkins_job_id&quot;: 0, &quot;job_status&quot;: &quot;ENQUEUED&quot;, &quot;job_platf...
<python><mongodb><pymongo>
2023-05-30 12:10:08
1
5,538
Akshay J
76,364,600
16,371,459
running code in two gpus consume more time, when run independently, as compared to running in a single one
<p>I am trying to inference model with the best possible speed. While testing, I found that one inference take 34 milliseconds ( on average), when run on one GPU. And one inference ( on average) take 40 milliseconds, when requested to two GPUs, independently. And one inference ( on average) take 50 milliseconds, when r...
<python><performance><gpu><nvidia><onnxruntime>
2023-05-30 12:01:47
0
318
Basir Mahmood
76,364,144
13,086,128
TypeError: histogram() got an unexpected keyword argument 'normed'
<p>I am using <code>numpy.histogram</code> and I am getting this error:</p> <pre><code>import numpy as np np.histogram(np.arange(4), bins=np.arange(5), normed=True) TypeError: histogram() got an unexpected keyword argument 'normed' </code></pre> <p>I was expecting:</p> <pre><code>(array([0.2,0.25,0.25]),array([0,1,2,3...
<python><python-3.x><numpy><math><histogram>
2023-05-30 11:03:03
2
30,560
Talha Tayyab
76,363,921
7,483,211
How to fix pandas v2 "ValueError: Cannot convert from timedelta64[ns] to timedelta64[D]."
<p>When upgrading from pandas version 1 to 2.0.0, I suddenly get a <code>ValueError</code> in a script that worked fine before upgrading pandas to version 2:</p> <pre><code>ValueError: Cannot convert from timedelta64[ns] to timedelta64[D]. Supported resolutions are 's', 'ms', 'us', 'ns' </code></pre> <p>This is a minim...
<python><pandas><type-conversion><timedelta>
2023-05-30 10:34:29
3
10,272
Cornelius Roemer
76,363,837
11,197,301
Count the number of specific objects in a OrderedDict structure
<p>I create the following OrderedDict:</p> <pre><code>import collections class obj1(): def __init__(self): self.aa = 22 self.bb = 23 class obj2(): def __init__(self): self.dd = 22 self.ee = 23 my_test = collections.OrderedDict() my_test['1'] = obj1 my_test['2'] = obj1...
<python><counting>
2023-05-30 10:23:07
3
623
diedro
76,363,766
10,866,873
Tkinter get child widget on creation
<p>I am trying to get the widget that has just been created in a frame.</p> <p>Using either the or bindings will trigger <strong>only</strong> if I am binding <code>root (r)</code>, if I bind the <code>Frame (a)</code> then no event is triggered when creating new widgets inside.</p> <pre class="lang-py prettyprint-ov...
<python><tkinter>
2023-05-30 10:12:59
0
426
Scott Paterson
76,363,743
17,487,457
Retrieving data from two separate files and writing to a third csv file
<p>I have been thinking all day how to approach this task. I have these two files:</p> <ol> <li><code>user.plt:</code> contains timestamped GPS trajectory of user.</li> <li><code>label.txt:</code> contains information about mode of travel used to cover user trips.</li> </ol> <p>The first file (<code>user.plt</code>) i...
<python><python-3.x><csv><file><file-io>
2023-05-30 10:09:59
2
305
Amina Umar
76,363,493
7,089,108
Plotly. Animated 3D surface plots
<p>I want to make a 3D animation using Surface of Plotly.</p> <p>However, I run into two issues: (1) When I press play, the figure is only updated at the second frame. (2) I see all the previous frames as well. I just want to see one frame.</p> <p>What do I need to change? Below is a minimal example, which highlights m...
<python><animation><plotly>
2023-05-30 09:37:11
1
433
cerv21
76,363,452
9,620,095
Display automatic row height adjustment. XLSXWRITER (python)
<p>How to display automatic row height adjustment? I tried with using 'text_wrap': True , but doesn't work for me. Also , I doen't want to set_row() statically beacuse the data is dynamic.</p> <p>This is the option in Excel which I want .</p> <p><a href="https://i.sstatic.net/s3wbL.png" rel="nofollow noreferrer"><img s...
<python><xlsxwriter>
2023-05-30 09:31:14
0
631
Ing
76,363,436
610,569
cannot import name 'PartialState' from 'accelerate' when using Huggingface pipeline on Kaggle notebook?
<p>When import pipeline from Huggingface on Kaggle notebook,</p> <pre><code>from transformers import pipeline </code></pre> <p>it throws this error:</p> <pre><code>/opt/conda/lib/python3.10/site-packages/tensorflow_io/python/ops/__init__.py:98: UserWarning: unable to load libtensorflow_io_plugins.so: unable to open fil...
<python><pipeline><huggingface-transformers><kaggle>
2023-05-30 09:29:24
3
123,325
alvas
76,363,394
7,657,180
Import packages in Pyscript framework
<p>I have this html that uses Pyscript framework</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF8&quot;&gt; &lt;title&gt;PyScript Hello, World!&lt;/title&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;https://pyscript.net/alpha/pyscript.css...
<python><pyscript>
2023-05-30 09:25:31
1
9,608
YasserKhalil
76,363,375
661,716
numba jitclass with dictionary key tuple
<p>Below code works with @jit, but does not work with jitclass on Dict.empty. Is it that jitclass does not support the dictionary with tuple key while @jit supports it?</p> <pre><code>from numba import types, njit from numba.experimental import jitclass from numba.typed import Dict from numba import int64, float64 spe...
<python><numba><jit>
2023-05-30 09:23:03
0
1,226
tompal18
76,363,333
10,215,160
How to preserve multiindex order on join in pandas?
<p>Consider The following Example Code:</p> <pre><code>import pandas as pd df1 = pd.DataFrame({'data1':[1,2,3,4]}, index=pd.MultiIndex.from_product([['a','b'],[1,2],], names=['index1','Index2'])) df2 = pd.DataFrame({'data2':[5,6]}, index=pd.MultiIndex.from_product([[1,2]], names=['Index2'])) df3 = df1.join(df2, ho...
<python><python-3.x><pandas>
2023-05-30 09:17:20
2
1,486
Sandwichnick
76,363,301
12,764,964
What is the logic behind AWS Sagemaker error responses using boto3 python?
<p>I am working with AWS Sagemaker API using boto3, python 3.10. One of my goals is to implement proper error handling for several cases to make method call idempotent.</p> <p>However, while exploring the errors, I found that they are inconsistent.</p> <p>So my question is that what logic is behind implementing such er...
<python><python-3.x><amazon-web-services><boto3><amazon-sagemaker>
2023-05-30 09:13:34
1
553
Kyrylo Kravets
76,362,880
8,248,194
Pandas assign with comprehension giving unexpected results
<p>I want to use assign in pandas passing a dictionary comprehension.</p> <p>Reproducible example:</p> <pre class="lang-py prettyprint-override"><code> import pandas as pd df = pd.DataFrame({ &quot;a&quot;: [1, 2, 3], &quot;b&quot;: [4, 5, 6], &quot;weight&quot;: [0.1, 0.2, 0.3] }) metrics = [&quot;a&quot...
<python><pandas><dataframe>
2023-05-30 08:18:09
3
2,581
David Masip
76,362,792
277,176
How to intern objects with weakref/gc support?
<p>I'm trying to implement interning of non-string objects in python. For strings we have the <code>sys.intern</code> function. However it doesn't support other immutable objects. To put it out of the way, I'm aware of the problems that may arise when the interned objects are modified.</p> <p>A commonly cited way of in...
<python><garbage-collection><weak-references>
2023-05-30 08:06:24
1
72,849
Yakov Galka
76,362,768
2,646,881
"in" clause, best (fastest) target type for checking
<p>I was doing a project that is doing some stuff, and wanted to print &quot;summary&quot; of the warnings that occurred during processing at the end.</p> <p>What I did was to store Enums in a list, than for each list member, there is <code>if</code> in the last <code>print_warnings()</code> method. Something like this...
<python>
2023-05-30 08:02:59
1
418
rRr
76,362,664
1,342,516
Exclude overlapping intervals with numpy
<p>I have two lists of intervals. I would like to remove all ranges from list1 that already exist in list2. Example: List1:</p> <blockquote> <p>[(0,10),(15,20)]</p> </blockquote> <p>List2:</p> <blockquote> <p>[(2,3),(5,6)]</p> </blockquote> <p>Output:</p> <blockquote> <p>[(0,2),(3,5),(6,10),(15,20)]</p> </blockquote> <...
<python><numpy>
2023-05-30 07:51:01
2
539
user1342516
76,362,600
525,865
getting data out of clutch.co: with BS4 and requests failed:
<p>trying to gather the data form the page <code>https://clutch.co/il/it-services</code> and that said i - think that there are probably several options to do that</p> <p>using <code>bs4</code> and requests b. using pandas</p> <p>this first approach uses a.</p> <pre><code>import requests from bs4 import BeautifulSoup i...
<python><pandas><beautifulsoup><python-requests>
2023-05-30 07:44:58
1
1,223
zero
76,362,579
7,257,731
Wrapper over Flask endpoint is very slow
<p>I have a Flask service made with <a href="https://editor-next.swagger.io/" rel="nofollow noreferrer">Swagger Editor</a> and Swagger Codegen (python flask). The code generated uses Connexion and Flask to serve the application.</p> <p>This service has an endpoint that, on its own, answers the request in just 300ms (wh...
<python><flask><wsgi><swagger-codegen><connexion>
2023-05-30 07:42:01
1
392
Samuel O.D.
76,362,522
13,396,497
Read XML parent and child tag value from log file if child tag value condition match in Python
<p>I have a log file in which XML and text data is there. I want to read the XML with below conditions and read some values in data frame format.</p> <ul> <li>Want to read only the set in which <code>&lt;NEW_DATA&gt;</code> tag is there inside <code>&lt;DATA&gt;</code> tag, ignore all other.</li> <li>Then filter only t...
<python><xml><dataframe>
2023-05-30 07:33:44
2
347
RKIDEV
76,362,447
10,939,080
Python dataclasses: Allow mutation of existing field but disallow new fields
<p>I would like to write a dataclass that allows change of value for fields that already exist, but prevent addition of new fields.</p> <p>I am on Python &gt;= 3.10</p> <pre><code>from dataclasses import dataclass @dataclass class Foo: bar: int baz: int foo = Foo(bar=1, baz=0) foo.baz = 2 # this should be oka...
<python><python-dataclasses>
2023-05-30 07:23:22
1
734
tyson.wu
76,362,377
5,080,612
Retrieving float and binary data sqlite3
<p>I have a database in sqlite</p> <p><a href="https://i.sstatic.net/OWE0j.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OWE0j.png" alt="enter image description here" /></a></p> <p>This database contains strings, floats and column with BLOB values. These BLOB values contain binary data that it has to ...
<python><sqlite><blob>
2023-05-30 07:11:21
0
1,104
gis20
76,362,291
4,495,790
How could skforecast.ForecasterAutoreg predict without lag?
<p>I'm using now <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiM7fOku5z_AhVLNuwKHcxjCLsQFnoECB0QAQ&amp;url=https%3A%2F%2Fskforecast.org%2F&amp;usg=AOvVaw0PPIBTqFLD6ym2Q7ouyMmj" rel="nofollow noreferrer">skforecast</a> to forecast kind ...
<python><time-series><forecasting>
2023-05-30 06:59:18
1
459
Fredrik
76,362,026
3,793,935
QR code detecting in python with OpenCV raises UnicodeDecodeError: 'utf-8' codec can't decode byte
<p>I have written a class to retrieve creditor data like the Iban from an invoice pdf with an qr code on it. It worked fine, until we've gotten an pdf that throws this error:</p> <pre><code>UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 157: invalid start byte </code></pre> <p>If I try to process ...
<python><opencv><qr-code>
2023-05-30 06:15:51
2
499
user3793935
76,361,997
13,078,067
Is passing Exceptions instances as values considered pythonic
<p>I want to pass caught <em>instance</em> of an <code>Exception</code> (or deriving class) as and argument to some function, and I wonder if it is an idiomatic (pythonic) thing to do. In summary I have a system that runs different callbacks depending on success of some other method call. In reduced form it looks like ...
<python><exception>
2023-05-30 06:09:43
0
6,455
Aleksander Krauze
76,361,868
10,097,229
Cannot import module from partially initialized module
<p>I am writing an Azure Function where I have two files. First file <code>helperfunc_postapi</code> contains some functions which return a value and the second one is calling the functions in first file. I am cythonizing (encrypting using cython package) the first file so that its contents are not visible to others.</...
<python><python-3.x><function><azure-functions>
2023-05-30 05:39:44
1
1,137
PeakyBlinder
76,361,820
8,278,075
How to add a fixed value to the Y axis in Altair?
<p>I'm new to Altair and I'd like to add a two rule lines on the Y axis of a stock progression in my line chart.</p> <p>The DataFrame <code>symbol_data</code> has Date, Symbol, Name, Close, and I added another column &quot;StdDev&quot; which is the standard deviation for the entire data set.</p> <pre class="lang-py pre...
<python><data-science><altair>
2023-05-30 05:27:49
1
3,365
engineer-x
76,361,397
1,743,837
mock.patch-ing the .append method of the Python list
<p>I am unit testing a single line of code within an if statement where I append an item onto a list if a variable has a specific value.</p> <pre><code>foo = [] if bar == 'a': foo.append(bar) </code></pre> <p>I would like to assert that such an append has been called. I have patched methods from a variety of source...
<python><mocking><pytest><python-unittest><magicmock>
2023-05-30 03:13:29
1
1,295
nerdenator
76,361,324
473,923
Install Python 3.10 or 3.11 with OpenSSL on MAC Apple Silicon
<p>I have tried multiple times to get Python working on my Mac M2 and always have trouble <code>openssl</code>.</p> <p>I have used both Stack overflow questions (which are out of date) and ChatGPT to guide me on installation and still cannot get a working environment.</p> <p>I have tried with <code>pyenv</code>, <code>...
<python><python-3.x><macos><openssl><pyenv>
2023-05-30 02:48:57
1
6,962
David Cruwys
76,360,982
2,571,019
Combine two videos in python and get frame-precision duration of the end of the first clip within the new combined clip
<p>I am trying to combine two videos (mov files) in Python and get the frame-precision duration of the end of the first clip within the new, combined clip so that I can skip to the end of the first clip/start of the second clip within the newly combined clip.</p> <p>Here is how I combine the two videos.</p> <pre><code>...
<python><ffmpeg><video-processing>
2023-05-30 00:39:55
0
1,998
johnklawlor
76,360,381
7,920,004
Python if creates false positive result
<p>I'm trying to investigate my AWS resources by listing all and checking whether they have special <code>troux</code> tag.</p> <p>When iterating through my results I'm getting duplicate rows for some resources, both stating that <code>troux</code> tag does and doesn't exist at the same time.</p> <pre><code>import boto...
<python>
2023-05-29 21:21:14
1
1,509
marcin2x4
76,360,370
11,692,124
Get init arguments of child class from parent class
<p><code>getInitInpArgs</code> on <code>ann</code> gets the input arguments in <code>init</code> of <code>ann</code> to a dictionary. Now I want to define a function like <code>getInitInpArgs</code> on <code>ann</code> (parent class) and not on the child classes, which makes a dictionary of input arguments of init of <...
<python><introspection><python-class>
2023-05-29 21:20:16
1
1,011
Farhang Amaji
76,359,906
11,505,680
Figures suppressed with plt.ioff show up later
<p>I have a module that loads data and makes plots. I have a bunch of test cases that run whenever I import my module. Some of them generate figures just so that I can inspect their properties. I suppress these figures using <code>plt.ioff</code> as a context manager. But when, in an interactive session (Spyder), I imp...
<python><matplotlib>
2023-05-29 19:26:28
1
645
Ilya
76,359,743
3,848,573
Cannot run SendGrid Python
<p>I'm using the SendGrid sample code to make sure my Token is ready, but every time I try to run it I get an error with RFC822 My Sample Code:</p> <pre><code>import os import sendgrid from sendgrid.helpers.mail import Mail message = Mail( from_email='someone@gmail.com', to_emails='someone@gmail.com', subj...
<python><python-3.x><pip><sendgrid><rfc822>
2023-05-29 18:57:36
1
715
Joseph Khella
76,359,670
2,699,929
3D connected components with periodic boundary conditions
<p>I am trying to identify connected features on the globe (i.e., in space-time on a sphere). The <a href="https://pypi.org/project/connected-components-3d/" rel="nofollow noreferrer">cc3d</a> package has gotten me 90% of the way but I am struggling to deal with the date border (i.e., the periodic boundary conditions i...
<python><python-3.x><numpy><python-xarray>
2023-05-29 18:40:28
1
457
Lukas
76,359,550
4,231,821
Converting SVG TO PNG are doing abnormal Behavior in other languages than English
<p>I want to export image by converting svg to png for the following purpose I am using <a href="https://cairosvg.org/" rel="nofollow noreferrer">CairoSvg</a></p> <p>It is working fine when I am svg that exists in English.</p> <p>For Example :</p> <p><a href="https://i.sstatic.net/jw0EJ.png" rel="nofollow noreferrer"><...
<python><charts><arabic-support><svgtopng>
2023-05-29 18:16:43
0
527
Faizan Naeem
76,359,494
11,922,765
Missing markers in the plot legends of scikit-learn examples
<p>I have been looking at the Scikit library documentation and example codes. Many of the plots does not have markers in the legends, leaving us to guess everything.</p> <p><a href="https://scikit-learn.org/stable/auto_examples/svm/plot_separating_hyperplane_unbalanced.html#sphx-glr-auto-examples-svm-plot-separating-hy...
<python><matplotlib><scikit-learn><legend>
2023-05-29 18:08:17
1
4,702
Mainland
76,359,445
3,044
Simple Union type fails to type check in MyPy
<p>The following simple type check fails in MyPy.</p> <pre class="lang-py prettyprint-override"><code>from typing import Dict, Union A = Dict[str, Union[str, Dict[str, str]]] B = Union[A, Dict[str, str]] example: B = {&quot;x&quot;: {&quot;y&quot;: &quot;z&quot;}} </code></pre> <p>This results in an error message whe...
<python><mypy>
2023-05-29 17:58:39
0
8,520
levand
76,359,431
16,243,418
TypeError in Django: "float () argument must be a string or a number, not 'tuple.'"
<p><strong>Description:</strong></p> <p>When attempting to access a specific page that relate to a cryptocurrency, in this case Dogecoin, I receive a TypeError in my Django application. &quot;Field 'bought_price' expected a number but got (0.07314770668745041,)&quot; reads the error notice. The traceback also states th...
<python><python-3.x><django><django-models>
2023-05-29 17:56:17
1
352
Akshay Saambram
76,359,395
12,297,666
How determine the y coordinate of center of mass from timeseries
<p>Consider the following pandas dataframe, with shape <code>NxT</code>, where <code>N = 10</code> is the number of samples and <code>T = 6</code> are the timesteps.</p> <pre><code>import pandas as pd import numpy as np from scipy import ndimage data = pd.DataFrame(np.random.random_sample((10, 6))) </code></pre> <p>I n...
<python><scipy>
2023-05-29 17:49:58
1
679
Murilo
76,359,359
10,530,575
Add a fixed value to get cumulative sum
<p>I have a dataframe , I want to add a fixed number 5 to the first element of the dataframe, to get cumulative sum</p> <pre><code>import pandas as pd data = {'Values': [10, 5000, 6000, 7000, 8000, 9000, 8000]} df = pd.DataFrame(data) </code></pre> <p><a href="https://i.sstatic.net/8SmSO.png" rel="nofollow noreferrer"...
<python><python-3.x><pandas><dataframe>
2023-05-29 17:44:17
3
631
PyBoss
76,359,347
11,692,124
Run a method of base class automatically after constructor of a child instance
<p>I want a way to run <code>func_z</code> after <code>ChildClass constructor</code> automatically.</p> <pre><code>class BaseClass: def __init__(self): print(&quot;BaseClass constructor&quot;) self.func_z() def func_z(self): print(&quot;BaseClass func_z&quot;) class ChildClass(BaseClas...
<python>
2023-05-29 17:42:30
0
1,011
Farhang Amaji
76,359,178
21,420,742
How to get first name and last name when last name is multiple names in pandas
<p>I have a data frame and need to separate first and last name. So far this is where I got to.</p> <pre><code>df = [['Victor De La Cruz', 'Ashley Smith', 'Angel Miguel Hernandez', 'Hank Hill']] df['first_name'] = df.str.split().str[0] df['last_name'] = df.str.split().str[1:] </code></pre> <p>OutPut</p> <pre><code>fi...
<python><python-3.x><pandas><dataframe>
2023-05-29 17:10:15
2
473
Coding_Nubie
76,359,112
489,088
Python Pandas giving me SettingWithCopyWarning when I attempt to map a particular DataFrame column - how to fix?
<p>I have some code that needs to replace two columns of a pandas DataFrame with the index of each value as they appear in a unique list of those values. For example:</p> <pre><code>col1, col2, col3, col4 A, 1, 2, 3 A, 1, 2, 3 B, 1, 2, 3 </code></pre> <p>Should end up in the data frame as:</p> <pre><code>col1, col2, co...
<python><pandas><dataframe><apply>
2023-05-29 16:58:18
0
6,306
Edy Bourne
76,359,085
2,411,048
How to allow None type as a parameter in a fastAPI endpoint?
<p>I define the class I am assuming for the parameters. I want the parameters (eg param1 to potentially have a value of None):</p> <pre><code> class A(BaseModel): param1: Union[int, None] = None #Optional[int] = None param2: Optional[int] @app.post(&quot;/A_endpoint/&quot;, response_...
<python><fastapi>
2023-05-29 16:52:24
1
406
edgarbc
76,358,976
6,199,181
Is it possible to read and parse csv in streaming mode with Python?
<p>I want to download huge CSV and parse it line by line in streaming mode. My code is:</p> <pre><code>with httpx.stream(&quot;GET&quot;, url) as r: for line in r.iter_lines(): for row in csv.reader([line]): ... </code></pre> <p>but if there are &quot;multi-lines&quot; in input file this code do...
<python><python-3.x><csv>
2023-05-29 16:35:47
1
1,517
Serge
76,358,689
21,404,794
Uncrop 3d plots in jupyter notebook
<p>I'm doing some 3d scatter plots with jupyter notebooks in VSCode, and they aren't showing properly.</p> <p><a href="https://i.sstatic.net/LU6zN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LU6zN.png" alt="3d scatter plot from docs" /></a></p> <p>I went to the documentation in matlab and downloaded ...
<python><visual-studio-code><jupyter><matplotlib-3d><z-axis>
2023-05-29 15:45:48
1
530
David Siret Marqués
76,358,590
12,352,239
OpenCV polyLines() throws error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'polylines'
<p>I am trying to draw a segmentation mask from a YOLO segmentation mask dataset. The annotation line I am reading looks like this:</p> <p><code>36 0.6158357764423077 0.814453125 0.6158357764423077 0.8095703125 0.6070381225961539 0.8095703125 0.6041055721153846 0.8115234375 0.5894428149038462 0.8154296875 0.57478005769...
<python><numpy><opencv><yolov8>
2023-05-29 15:33:41
1
480
219CID
76,358,564
12,394,134
Bootstrapping multiple random samples with polars in python
<p>I have generated a large simulated population polars dataframe using numpy arrays. I want to randomly sample from this population dataframe multiple times. However, when I do that, the samples are exactly the same from sample to sample. I know there must be an easy fix for this, any recommendations? It must be the r...
<python><numpy><python-polars><bootstrapping>
2023-05-29 15:30:14
1
326
Damon C. Roberts
76,358,367
1,946,418
Figure out return of a method that returns empty hash on some condition
<p>I'm trying to understand how to make this work:</p> <pre class="lang-py prettyprint-override"><code>def someMethod() -&gt; dict[any, any]: if not os.path.exists('some path'): return {} config = {'a': 1, 'b': 2} return config </code></pre> <p>I don't think that's correct. Seeing this error - <cod...
<python>
2023-05-29 14:57:54
1
1,120
scorpion35
76,358,355
5,869,121
FastAPI Depends w/ get_db failing for PUT endpoint
<p>I'm working on a FastAPI Project w/ some basic user endpoints. I recently shifted my project around to use routers to separate all of the endpoints out into individual files, but this has caused my only PUT endpoint to start failing while all of the GET ones still function just fine.</p> <p>When I hit the POST endp...
<python><fastapi>
2023-05-29 14:56:30
1
1,019
jyablonski
76,358,179
2,504,762
GCP DataCatalog Linage API - Create Custom Linage
<p>We are using some custom spark process for certain ingestion and transformation. and So I wanted to utilize the Datacatalog Linage API to create our custom linage.</p> <p>I am trying to follow mentioned documentation. However, not exactly able to figure out how to provide custom linage.</p> <p><a href="https://cloud...
<python><google-cloud-platform>
2023-05-29 14:29:21
0
13,075
Gaurang Shah
76,358,170
16,383,578
How to implement Sieve of Eratosthenes with Wheel factorization in NumPy?
<p>I have already implemented <a href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow noreferrer">Sieve of Eratosthenes</a> and another version with <a href="https://en.wikipedia.org/wiki/Wheel_factorization" rel="nofollow noreferrer">Wheel factorization</a>, both in NumPy. But I don't think I have ...
<python><python-3.x><numpy><math><sieve-of-eratosthenes>
2023-05-29 14:27:36
0
3,930
Ξένη Γήινος
76,358,068
5,802,882
Performance and Data Integrity Issues with Hudi for Long-Term Data Retention
<p>Our project requires that we perform full loads daily, retaining these versions for future queries. Upon implementing Hudi to maintain 6 years of data with the following setup:</p> <pre class="lang-py prettyprint-override"><code>&quot;hoodie.cleaner.policy&quot;: &quot;KEEP_LATEST_BY_HOURS&quot;, &quot;hoodie.cleane...
<python><amazon-web-services><apache-spark><amazon-emr><apache-hudi>
2023-05-29 14:11:42
1
1,325
Luiz
76,357,984
3,247,006
The class name with or without quotes in a Django model field to have foreign key relationship
<p>I can set <code>Category</code> with or without quotes to <a href="https://docs.djangoproject.com/en/4.2/ref/models/fields/#foreignkey" rel="nofollow noreferrer">ForeignKey()</a> as shown below:</p> <pre class="lang-py prettyprint-override"><code>class Category(models.Model): name = models.CharField(max_length=5...
<python><django><django-models><foreign-keys><python-class>
2023-05-29 14:00:04
1
42,516
Super Kai - Kazuya Ito
76,357,948
17,071,718
Installation of Python
<p>Want to use <code>python</code> and typed the command <code>py</code> which gave me the following list.</p> <p>I certainly want to use the most recent version. Should one clean up such setup so that I only have <code>python3.6 </code> ?</p> <pre><code>hagbard@fuckup:~$ py py3clean pydoc pygettext2.7 p...
<python>
2023-05-29 13:53:05
1
465
Dilna
76,357,872
16,053,370
How to insert comment in iceberg table?
<p>I'm trying to put a comment on the ICEBRG table in glue catalog, and I used it as follows:</p> <pre><code>spark.sql(f&quot;&quot;&quot;CREATE EXTERNAL TABLE IF NOT EXISTS {schema_name}.{table_name}({columns}) USING iceberg COMMENT 'table description' PARTITIONED BY ({partition_by_create}) LOCATION '{bucket_name}'&qu...
<python><pyspark><aws-glue><apache-iceberg>
2023-05-29 13:39:26
0
373
Carlos Eduardo Bilar Rodrigues
76,357,757
131,874
No module named 'flask' in virtualenv
<p>I was running <code>pgAdmin4</code> in Centos 8 with no problems. I upgraded to <code>pgAdmin4 7.11</code> and now it no longer works. This is the error:</p> <pre><code>ModuleNotFoundError: No module named 'flask' </code></pre> <p>Flask is installed in the virtualenv:</p> <pre><code># pwd /usr/pgadmin4/venv/lib/pyth...
<python><flask><centos><virtualenv><pgadmin-4>
2023-05-29 13:21:46
1
126,654
Clodoaldo Neto
76,357,536
395,857
How can I run some inference on the MPT-7B language model?
<p>I wonder how I can run some inference on the <a href="https://huggingface.co/mosaicml/mpt-7b" rel="nofollow noreferrer">MPT-7B language model</a>. The <a href="https://huggingface.co/mosaicml/mpt-7b" rel="nofollow noreferrer">documentation page on MPT-7B language model </a> on huggingface doesn't mention how to run ...
<python><nlp><huggingface-transformers><large-language-model>
2023-05-29 12:50:17
1
84,585
Franck Dernoncourt
76,357,364
641,565
pytest.postgresql external template database
<p>I am trying to write database integration tests against a dockerized postgresql database, the schema of which I would rather not replicate in my own test setups. In pytest-postgresql documentation there is a mention of the following option:</p> <blockquote> <p>You can also define your own database name by passing sa...
<python><postgresql><docker><pytest>
2023-05-29 12:25:13
0
325
CptPicard
76,357,201
10,620,788
Pyspark optimization with loops
<p>I have a table with the columns items, date, and sales. I have the total sales by date and item. I need to find the combination of 3 items which minimizes the standard deviation. The table looks like this: e.g.</p> <pre><code># df: # +------------+----------+------------+ # |item | date|sales | # +...
<python><optimization><pyspark>
2023-05-29 12:03:45
0
363
mblume
76,357,177
7,657,219
pip can't find flit-core dependency when offline installing other packages
<p>So i'm trying to install idna and trio, and both need flit_core, the problem is that I'm installing it in an offline machine downloading from this PyPi resource &quot;https://pypi.org/project/flit-core/&quot;, it install it perfectly, but when I try to install the other two, it says:</p> <blockquote> <p>ERROR: Could...
<python><linux><pip><package>
2023-05-29 12:00:42
2
353
Varox
76,356,969
54,557
How to add an outline to a mask with no internal lines in matplotlib
<p>For a given 2D mask, I would like to draw its outline with no internal lines between adjacent grid cells. Highlighting one cell is straightforward: <a href="https://stackoverflow.com/questions/56654952/how-to-mark-cells-in-matplotlib-pyplot-imshow-drawing-cell-borders">How to mark cells in matplotlib.pyplot.imshow (...
<python><numpy><matplotlib><mask><cartopy>
2023-05-29 11:33:10
1
9,654
markmuetz
76,356,950
3,361,462
Log record is not propagated to the root handler
<p>I noticed very strange behaviour with logging and logger:</p> <pre><code>import logging logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler()) logger.warning(&quot;A&quot;) # Print one message logging.warning(&quot;A&quot;) # Pirnts another message logger.warning(&quot;A&quot;) # Prints two...
<python><logging>
2023-05-29 11:29:51
1
7,278
kosciej16
76,356,924
5,539,782
scrape website through it's api using request
<p>I want to scrape live matches data from this website: <a href="https://egamersworld.com/matches" rel="nofollow noreferrer">https://egamersworld.com/matches</a></p> <p>I tried using the api: <a href="https://api.egamersworld.com/matches?lang=en" rel="nofollow noreferrer">https://api.egamersworld.com/matches?lang=en</...
<python><web-scraping><python-requests>
2023-05-29 11:26:12
1
547
Khaled Koubaa
76,356,789
3,247,006
The default value with or without "()" in a Django model field and "ValueError: Cannot serialize function" error
<h2>&lt;The 1st case&gt;:</h2> <p>I can use <a href="https://docs.djangoproject.com/en/4.2/ref/utils/#django.utils.timezone.now" rel="nofollow noreferrer">timezone.now()</a> with or without <code>()</code> as a default value in <a href="https://docs.djangoproject.com/en/4.2/ref/models/fields/#datetimefield" rel="nofoll...
<python><django><datetime><django-models><default>
2023-05-29 11:04:38
2
42,516
Super Kai - Kazuya Ito
76,356,601
7,657,219
How can I offline install tkinter for python3.11?
<p>In this case I'm having problems with Tkinter, although it is in the installed libraries/packages from python 3.11 installation, It seems I can't use it.</p> <p>Whenever I try import tkinter it gives me the following error:</p> <blockquote> <p>No module named '_tkinter'</p> </blockquote> <p>My problem is that I'm us...
<python><python-3.x><linux><tkinter><rhel>
2023-05-29 10:35:22
0
353
Varox
76,356,591
10,396,469
How to skip weights init when loading pretrained transformers model?
<p>I need to find out how to load a pretrained transformer model without initializing weights in the beginning (to save time and memory)?</p> <ol> <li>I saw this code example, but this is not elegant: <pre><code>saved_inits = torch.nn.init.kaiming_uniform_, torch.nn.init.uniform_, torch.nn.init.normal_ # pre...
<python><pytorch><initialization><huggingface-transformers><transformer-model>
2023-05-29 10:33:20
1
4,852
Poe Dator
76,356,513
18,949,720
NeoVim ugly text next to variable assignment
<p>Using NeoVim, I created a Python file for a new project, and noticed that now when I declare a new variable, and go back to normal mode, a text appears looking like this:</p> <pre><code>a = 1 : Literal[1] b = 'hello' : Literal['hello'] c = ['a', 'random', 'list'] : list[str] </code></pre> <p>I am not sure it comes f...
<python><neovim><neovim-plugin>
2023-05-29 10:23:18
1
358
Droidux
76,356,365
7,340,304
Django ORM get object based on many-to-many field
<p>I have model with m2m field <code>users</code>:</p> <pre class="lang-py prettyprint-override"><code>class SomeModel(models.Model): objects = SomeModelManager() users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True) </code></pre> <p>My goal is to get instance of this model where set of ins...
<python><django><many-to-many><django-orm>
2023-05-29 09:59:37
1
591
Bohdan
76,356,156
19,451,374
Aynchronous Google Datastore Calls in a Python FastAPI Application
<p>I am developing an application using <strong>FastAPI</strong> hosted on <strong>Google Cloud Run</strong>. A vital part of this application involves a series of read/write operations using <strong>Google Datastore</strong>. I've observed that these operations, particularly the ones executed in a loop, are becoming a...
<python><asynchronous><async-await><google-cloud-datastore>
2023-05-29 09:27:26
0
443
Mohamed Haydar
76,355,950
5,403,987
Why won't dynaconf read my settings.toml file?
<p>I&quot;m writing this Q&amp;A to document a painful investigation and resolution in the hopes of saving others the hassle.</p> <p>I'm using the Python Dynaconf (3.1.11) to manage settings for a package I've written. The settings are stored in a settings.toml file within the package. When I first started using Dynaco...
<python><dynaconf>
2023-05-29 08:59:27
1
2,224
Tom Johnson
76,355,874
12,196,370
Selenium python script can't run after an update to chrome browser
<p>The problem occurs in my python script run on an ubuntu server (no GUI). A chrome browser version 112 was installed on this server, and other requirements (chromedriver, python, etc.) were all met and a python3 script worked fine. Its function is calling webdriver, manipulating chrome to do some automated work.</p> ...
<python><google-chrome><selenium-webdriver>
2023-05-29 08:47:51
1
305
VKX
76,355,873
10,474,176
Unable to get complete participant list: get_participants in Telethon
<p>get_participants is only giving a few participants but not the complete group of participants. It was working fine a few weeks back but not working as of now. Am I missing anything here?</p> <pre><code> target_group=self.groups[int(g_index)] print('Fetching Members...') all_participants = [] all_par...
<python><telegram><telethon>
2023-05-29 08:47:46
1
534
mondyfy
76,355,825
7,657,219
Offline install setuptools - Python3
<p>I'm trying to install setuptools offline in order to install cx_Oracle, as this one asks for the first in my offline machine and I keep getting this error after running this command:</p> <p>python3.11 -m pip install setuptools-67.8.0.tar.gz</p> <p><em>ERROR: Could not find a version that satisfies the requirement wh...
<python><linux><pip><package><offline>
2023-05-29 08:38:31
0
353
Varox