QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
⌀
77,301,404
181,783
SimpleXMLRPCServer.shutdown() failure post request
<p>I recently added a RPC backend to an existing single-threaded application as shown below</p> <pre class="lang-py prettyprint-override"><code>lock = Lock() def update_state(address, value): with lock: state[address] = value class ExistingClass: def __init__(self, *args, **kwargs): thread = T...
<python><xml-rpc><simplexmlrpcserver>
2023-10-16 10:59:57
2
5,905
Olumide
77,301,377
12,468,438
Pandas apply casts None dtype to object or float depending on other outputs
<p>I would like to control the output dtypes for <em>apply</em> on a row. <em>foo</em> and <em>bar</em> below have multiple outputs.</p> <pre><code>import pandas as pd def foo(x): return x['a'] * x['b'], None, x['a'] &gt; x['b'] def bar(x): return x['a'] * x['b'], None df = pd.DataFrame([{'a': 10, 'b': 2}, {...
<python><pandas><dataframe><apply><dtype>
2023-10-16 10:55:38
1
314
Frank_Coumans
77,301,376
9,021,547
XML parsing: how to return None is element was not found
<p>I need to parse an XML file, where the same tag might have a different number of children present, such the one shown below:</p> <pre><code>xml_file = ''' &lt;clients&gt; &lt;client&gt; &lt;name&gt;John&lt;/name&gt; &lt;/client&gt; &lt;client&gt; &lt;name&gt;Mike&lt;/name&gt; &lt;...
<python><xml><parsing>
2023-10-16 10:55:36
3
421
Serge Kashlik
77,301,148
10,133,797
Python colormap in MATLAB
<p>I wish to use matplotlib's <code>cmap='bwr'</code> for in MATLAB (for e.g. <code>imagesc</code>), but that's not supported. Can it be &quot;exported&quot; from matplotlib into MATLAB?</p>
<python><matlab><matplotlib>
2023-10-16 10:20:34
1
19,954
OverLordGoldDragon
77,301,054
10,721,627
How to load CSV file from an Azure blob storage using DuckDB?
<p>I have CSV files stored in an Azure Blob Storage container. I want to use DuckDB to load this data for analysis.</p> <p>Can someone guide me through the process of loading a CSV file from an Azure Blob Storage container into DuckDB? I am looking for a Python-based solution or any relevant code examples.</p>
<python><azure-blob-storage><duckdb>
2023-10-16 10:06:22
1
2,482
Péter Szilvási
77,301,031
7,968,764
Compressing image with python-opencv actually results more size
<p>I want to compress image in-memory using python.</p> <p>Using this code from answer <a href="https://stackoverflow.com/a/40768705">https://stackoverflow.com/a/40768705</a> I expect that changing &quot;quality param&quot; (90) I will get less size of result image.</p> <pre><code>encode_param = [int(cv2.IMWRITE_JPEG_Q...
<python><opencv><python-imaging-library><compression><image-compression>
2023-10-16 10:01:30
1
527
PATAPOsha
77,300,935
17,082,611
SSIM is high, MSE is low but the two images are not similar
<p>I want to calculate the similarity between these two images:</p> <p><a href="https://i.sstatic.net/TXevJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TXevJ.png" alt="original" /></a></p> <p>and</p> <p><a href="https://i.sstatic.net/cmKmK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.ne...
<python><machine-learning><scikit-image><mse><ssim>
2023-10-16 09:46:25
0
481
tail
77,300,643
3,297,613
vscode complains about python's classmethod typing
<p>My vscode editor always complains about the classmethod typing irrespective of the class.</p> <pre><code>from __future__ import annotations class A: @classmethod def foo(cls: type[A]) -&gt; str: return &quot;bar&quot; </code></pre> <p>Error/warning about the <code>classmethod</code> (raised by Pylan...
<python><vscode-debugger><python-3.10>
2023-10-16 08:59:31
1
175,204
Avinash Raj
77,300,536
21,404,794
Iterating through dict of dicts
<p>I have a dictionary of dictionaries, in this fashion:</p> <pre class="lang-py prettyprint-override"><code>scores = {'default': {'MSE': [[1.0,2.0], [3.0,4.0]], 'R2': [[2.0,3.0],[4.0,5.0]]}, 'RBF': {'MSE': [[3.0,4.0],[5.0,6.0]], 'R2': [[4.0,5.0],[6.0,7.0]]} } </code></pre> <p>And I need the list of num...
<python><arrays><list><dictionary>
2023-10-16 08:41:38
2
530
David Siret Marqués
77,300,475
9,488,023
How can I replace NaN values with empty cells in Pandas in Python?
<p>I have a large Pandas dataset in Python with several columns of different data types that all contain some cells that are NaN. My problem is that I want these cells to be empty rather than say 'nan', but I'm not sure how to do it. I can replace the nan-value with an empty string, but then I can't keep the columns th...
<python><pandas><string><replace><nan>
2023-10-16 08:32:36
0
423
Marcus K.
77,300,444
988,279
Replace if/else with something else (e.g. pattern matching)
<p>I compare two sources (a csv file, and the database). I want to get rid of this if/else construct. How can that be achieved with the &quot;python 3.10 pattern matching&quot;</p> <pre><code>for row in csv_file: entry = find_entry_in_database(row.get('id')) # check for email changes if entry[0].email != r...
<python>
2023-10-16 08:27:32
1
522
saromba
77,300,395
16,399,497
SqlAlchemy: hybrid attribute as sum of columns with null values
<p>I've got a simple problem I can't figure out.</p> <p>I've got a simple data model with three integer columns (which can be null). I want to create an hybrid attribute to get the sum of three columns. My wish is to finally get the maximal total or to filter according to this total.</p> <p>I've made a minimal example....
<python><database><sqlalchemy>
2023-10-16 08:19:30
1
723
emonier
77,300,252
15,093,600
Type allowed keys of TypedDict
<p>I wonder how we should type a key, that corresponds to <code>TypedDict</code> instance.</p> <p>Consider that there is a class, that accepts a dictionary as an input. The dictionary is typed via <code>TypedDict</code>. Let us say there is a method that accesses the values of the dictionary by the key. In this case th...
<python><typeddict>
2023-10-16 07:54:29
1
460
Maxim Ivanov
77,300,153
3,420,197
IPython.display doesn't show long wav files
<p>I use IPython.display for listening audio file in Jupyter notebook. I have a long file(30 min).</p> <pre><code> import IPython.display as dis import numpy y = numpy.zeros(30*60*48000) </code></pre> <p>This code work as fluidly for 5 seconds</p> <p><code>dis.display(dis.Audio(y[:5*48000], rate=48000))</code></p> <p>...
<python><audio><jupyter-notebook>
2023-10-16 07:42:02
1
1,712
Anna Andreeva Rogotulka
77,300,113
726,730
get cpu temperature without elevated privileges
<p>In windows 7 or in windows 11 i want to display the cpu temperature using a python script.</p> <p>The code i run successfully is:</p> <pre class="lang-py prettyprint-override"><code>import wmi import pyuac def main(): w = wmi.WMI(namespace='root\\wmi') temperature = w.MSAcpi_ThermalZoneTemperature()[0] ...
<python><windows><cpu><temperature>
2023-10-16 07:35:14
0
2,427
Chris P
77,300,078
22,466,650
How .transform handle the splitted groups?
<p>I have this dataframe :</p> <pre><code>import pandas as pd df = pd.DataFrame({'subject': ['a', 'a', 'b', 'b', 'c', 'd'], 'level': ['hard', None, None, 'easy', None, 'medium']}) print(df) subject level 0 a hard 1 a None 2 b None 3 b easy 4 c None 5 d medium <...
<python><pandas>
2023-10-16 07:28:56
1
1,085
VERBOSE
77,300,059
2,006,844
AppStore Limitation to publish iOS app embedded with Python script
<p>Will there be any restrictions/Limitations on publishing iOS applications that internally run Python scripts on the App Store during the Apple Review process?</p>
<python><ios><xcode><app-store>
2023-10-16 07:25:28
1
479
lreddy
77,300,038
13,605,694
pip error: ModuleNotFoundError: No module named 'distutils'
<p>I updated to python 3.12 on windows and trying to <code>pip install -r requirements.txt</code>, but it terminates with error when trying to build <code>numpy</code>, <code>ModuleNotFoundError: No module named 'distutils'</code></p> <p>requirements.txt</p> <pre><code>altgraph==0.17.4 blinker==1.6.2 certifi==2023.7.22...
<python><python-3.x><numpy><pip>
2023-10-16 07:21:08
0
392
ayitinya
77,299,863
5,667,265
MATLAB Interp2 equivalent in SciPy python not working
<p>Original MATLAB Statement is -</p> <pre><code>Output = (interp2(X,Y,Tbl',Z,ThrtlPrcnt,'linear')); </code></pre> <p>Where parameter values (in Python) are</p> <pre><code>X = array([0, 550, 600, 700, 800, 874, 900, 950, 1000, 1100, 1200, 1300, 1400,       1500, 1600, 1700, 1730, 2000, 2100, 2200, 2500, 3000], dtype=o...
<python><matlab><linear-interpolation>
2023-10-16 06:51:20
1
1,259
Dipak
77,299,819
65,889
Can I use VS Code's launch config to just run a specific python file and not to debug it?
<p>In my Python project I have a module <code>my_stuff.py</code> which is active in my editor, but I want to execute the file <code>main.py</code> to run my project. -- Can I use <code>launch.json</code> for this?</p> <p>I tried a simple config like this:</p> <pre class="lang-json prettyprint-override"><code>{ // U...
<python><visual-studio-code>
2023-10-16 06:41:27
1
10,804
halloleo
77,299,359
5,624,602
Confluence REST API content-type issue for attachment with python
<p>I am trying to upload an attachment to Confluence using REST API from python. I get 415 error: unsupported media type.</p> <p>I understand the content-type is not correct, but I tried some content types and got the same error:</p> <pre><code>import requests print(&quot;start....................&quot;) url = 'https:/...
<python><python-requests><confluence-rest-api><http-status-code-415>
2023-10-16 04:09:08
1
1,513
STF
77,299,088
489,088
How to replace a value by another value only in certain columns of a 3d Numpy array?
<p>I have a 3d numpy array and a list of columns (axis = 1) in which I would like to replace all zeroes by a constant value:</p> <p>My sample data is like so:</p> <pre><code>data = np.array([ [[10, 10, 10], [0, 10, 10], [0, 10, 0]], [[20, 0, 20], [20, 20, 0], [0, 20, 20]], [[0, 30, 30], [30, 0, 30], [0, 30,...
<python><arrays><numpy><array-broadcasting>
2023-10-16 02:14:25
1
6,306
Edy Bourne
77,299,004
6,115,999
Nested schema for an association table
<p>I'm having trouble serializing my <code>Joke</code> data with a schema when I've added an association table.</p> <p>Here is my model it allows users to enter a joke and also a tag for categorizing the joke:</p> <pre><code>class Joke(db.Model): id = db.Column(db.Integer, primary_key=True) joke_name = db.Colum...
<python><flask><sqlalchemy><flask-sqlalchemy><marshmallow>
2023-10-16 01:37:33
1
877
filifunk
77,298,993
13,916,049
Match index of first dataframe to column of a second dataframe and replace the index with corresponding values in the second dataframe
<p>'ref' is an AnnData object and one of its components is a <code>ref.var</code> Pandas dataframe. <code>gene_list</code> is a separate Pandas dataframe with two columns: <code>ensembl_gene_id</code> and <code>hgnc_symbol</code>. If <code>ref.var.index</code> matches <code>gene_list[hgnc_symbol]</code>, replace <code>...
<python><pandas>
2023-10-16 01:29:51
1
1,545
Anon
77,298,753
6,591,677
Django - Heroku postgres connection opens with each page refresh and does not close ever
<p>I am using Django, heroku, websocket, AJAX, celery, postgres, consumer, asgi (uvicorn; tried Daphne also). <strong>My problem is that after just a page refresh, new postgres connection would be created, and it doesn't go away even after long inactivity.</strong> Soon with just refreshes my connections go over the to...
<python><django><postgresql><heroku>
2023-10-15 23:05:44
1
479
superbot
77,298,704
9,072,753
How to .format expressions like f string?
<p>Consider the following program:</p> <pre><code>$ python -c 'import sys; print(sys.argv[1].format(**dict(val = 1)))' &quot;val={val}&quot; val=1 </code></pre> <p>However, the f-string functionality is not available in .format:</p> <pre><code>$ python -c 'import sys; print(sys.argv[1].format(**dict(val = 1)))' &quot;v...
<python><python-3.x><f-string>
2023-10-15 22:38:34
0
145,478
KamilCuk
77,298,543
8,507,034
Why is seaborn superimposing plots?
<p>The following function is called from a fastapi post request:</p> <pre><code>import seaborn as sns import os from random import randint def make_histogram(data, filepath, destructive = True): sns.set() sns.set_style(&quot;whitegrid&quot;) sns.set_palette(&quot;husl&quot;) sns.set_context(&quot;paper&...
<python><seaborn><fastapi>
2023-10-15 21:30:56
0
315
Jred
77,298,383
284,932
Stack size errors on fine tunning t5 with xsum using pytorch
<p>I am trying to fine fine tunning t5-small with xsum dataset on pytorch Windows 10 (CUDA 12.1).</p> <p>Unfortunately <strong>Trainer</strong> (or Seq2SeqTrainer) class from bitsandbytes is not avaliable for Windows, so it was necessary to create a epoch loop:</p> <pre><code>from datasets import load_dataset from tran...
<python><pytorch><huggingface-transformers><summarization>
2023-10-15 20:27:10
0
474
celsowm
77,298,313
219,153
How to select the native GUI backend for standard Tkinter input dialogs on Python
<p>This Python 3.11 script on Ubuntu 22.04:</p> <pre><code>from tkinter import filedialog fileName = filedialog.askopenfilename(title='Open file', filetypes=((&quot;BMP files&quot;, &quot;*.bmp&quot;), (&quot;All files&quot;, &quot;*&quot;))) </code></pre> <p>opens this dialog box:</p> <p><a href="https://i.sstatic.ne...
<python><tkinter><dialog><backend>
2023-10-15 20:06:14
0
8,585
Paul Jurczak
77,298,182
7,724,007
Snapcraft python builds - how to get it to pack - path doesn’t exist error?
<p>So I am newer to Snapcraft, however I have been having this issue, despite following examples and tutorials so I figured I would ask here.</p> <p><strong>Machine setup</strong>: So I am on a windows machine, running ubuntu in a VM to compile the snap. Sadly work has not given me a ubuntu dev machine. Our deployments...
<python><ubuntu-22.04><snapcraft>
2023-10-15 19:23:52
1
334
meh93
77,297,981
145,682
matplotlib plotting incorrectly when csv files are concatted
<p>There are two csv files mentioned in the following gist:</p> <p><a href="https://gist.github.com/deostroll/7d1e95391855245fed8a4c746be4a901" rel="nofollow noreferrer">https://gist.github.com/deostroll/7d1e95391855245fed8a4c746be4a901</a></p> <p>They are simple historical NAV charts of a fund. It has only two fields....
<python><matplotlib>
2023-10-15 18:27:36
0
11,985
deostroll
77,297,946
3,050,730
Type Hinting Error with Union Types and Type Variables in Python 3.11
<p>I've encountered a type hinting issue in Python 3.11 using Pylance in Visual Studio Code, and I'm looking for insights into why this error is occurring and how to resolve it. Here's my code:</p> <pre class="lang-py prettyprint-override"><code>from typing import TypeAlias, TypeVar Data: TypeAlias = int | str DataVar...
<python><python-typing><pyright>
2023-10-15 18:19:25
1
523
nicrie
77,297,681
12,214,867
trying to run resnet on 128 by 128 imagenet but got 'the input dimensions must be equal' error, how do i fix it?
<p>i'm trying to build an image classifier following a <a href="https://www.mindspore.cn/tutorials/application/en/r2.1/cv/resnet50.html" rel="nofollow noreferrer">tutorial</a></p> <p>i managed to go through the tutorial and got good accuracy on the CIFAR-10 dataset.</p> <p>i'm trying to run the classifier on the imagen...
<python><deep-learning>
2023-10-15 17:03:27
1
1,097
JJJohn
77,297,662
19,130,803
Display dash html.Div inside dash ag-grid
<p>I am working on <code>dash</code> app. I am using <code>dash Ag-grid</code> component, to load custom data. For this I am using <code>cellRenderer</code> property which is define in <code>assets/dashAgGridComponentFunctions.js</code></p> <pre><code>import dash from dash import html # sample content data data = pd.D...
<python><reactjs><plotly-dash>
2023-10-15 16:56:40
0
962
winter
77,297,624
5,284,829
writing gzip csv file introduces random chars in the first row
<p>I am writing some csv data to a csv gzip file in python as follows</p> <pre><code>import csv import gzip import io csv_rows=[[&quot;cara&quot;,&quot;vera&quot;,&quot;tara&quot;],[&quot;rar&quot;,&quot;mar&quot;,&quot;bar&quot;],[&quot;jump&quot;,&quot;lump&quot;,&quot;dump&quot;]] mem_file = io.BytesIO() with gzip....
<python><csv><gzip>
2023-10-15 16:46:11
2
658
JennyToy
77,297,445
11,108,930
Pandas: Non overlapping datetimes algorithm
<p>I have a pandas dataframe (see input below) with multiple columns the important columns are start_datetime and end_datetime. The algorithm that I want to apply is the following. I compare every line to its next line. If the end_datetime (current line) is exceeding the start_datetime (next line) I want to move the ro...
<python><pandas><algorithm>
2023-10-15 16:02:25
2
977
MachineLearner
77,297,356
14,468,588
how to provide constraint for convex problem in python
<p>I want to solve a convex problem in python. But when I want to define constraints for my problem, it produces an error. here is my code:</p> <pre><code>delta = 10; A = pandas.read_excel(r&quot;C:\Users\mohammad\Desktop\feko1\feko\A.xlsx&quot;) Y = pandas.read_excel(r&quot;C:\Users\mohammad\Desktop\feko1\feko\Y.xlsx&...
<python><dimensions><convex-optimization><convex>
2023-10-15 15:39:02
1
352
mohammad rezza
77,297,284
10,786,288
Plotly Express: How can I adjust the size of marginal distribution plots?
<p>I have several datasets I am plotting with plotly express's scatterplot. I am using the option of the marginal distribution plots to show a histogram of the datasets but the problem is that the histograms on the margins tend to be way too big, eclipsing the actual data. An example:<a href="https://i.sstatic.net/vU9e...
<python><plotly>
2023-10-15 15:22:55
1
471
lpnorm
77,297,217
4,126,843
"Package does not exist" error because Conda cannot find recent package versions
<p>I have an existing Conda 23.1.0 environment managed using Mamba 1.5.1, which was created with the <code>channels: conda-forge</code> option. I want to install the latest version of the <code>holidays</code> package, <a href="https://anaconda.org/conda-forge/holidays" rel="nofollow noreferrer">which is 0.34</a>.</p> ...
<python><conda><mamba>
2023-10-15 15:04:59
1
7,661
PHPirate
77,297,092
20,000,775
"Inconsistent Audio Classification Results between Flutter App and Postman - Flask API"
<p>I've developed a Flutter app that records audio and sends it to a Python Flask API for classification. The API uses Librosa for feature extraction and a pre-trained ML model for audio classification. However, I'm experiencing inconsistencies in the predictions.</p> <h3>Problem:</h3> <ul> <li>When I send audio files ...
<python><flutter><flask><librosa>
2023-10-15 14:32:18
1
642
Dasun Dola
77,297,031
2,612,235
Format currency with babel without Unicode?
<p>Using Babel I get this:</p> <pre><code>&gt;&gt;&gt; babel.numbers.format_currency(1099.98, 'CHF', locale='fr_CH') '1\u202f099,98\xa0CHF' </code></pre> <p>I would like this format:</p> <pre><code>&quot;CHF 1'099.98&quot; </code></pre> <p>Is it possible to specify a custom format with babel?</p> <p>My current ugly wor...
<python><format><numbers><python-babel>
2023-10-15 14:14:11
2
29,646
nowox
77,296,633
4,379,151
How to combine objects in a full outer join with Django?
<p>Let's use Django's standard users and groups. I have a couple of users and groups and each user can be assigned to several groups via a M2M relation.</p> <p>Now, I want to construct a single query which cross joins users x groups. The purpose is a view that shows all groups with it's members, when users are members ...
<python><django>
2023-10-15 12:28:02
1
33,253
Erik Kalkoken
77,296,454
1,987,726
How to dedent a block in Python3 under MacOS?
<p>I am learning Python3. It is executed on MacOS/Terminal by running <code>python3</code>.<br /> I was able to execute some examples from the book &quot;Deep Learning with Python, Second Edition&quot;, but I am stuck now at a simple editor problem:<br /> If I enter the following statements</p> <pre><code>&gt;&gt;&gt; ...
<python><read-eval-print-loop>
2023-10-15 11:35:47
2
15,407
Reinhard Männer
77,296,419
195,787
Optimizing a Python Function of SmoothStep with Multiple Conditionals for Numba Vectorization
<p>I implemented a function which creates a smooth rectangle function using <a href="https://en.wikipedia.org/wiki/Smoothstep" rel="nofollow noreferrer">SmoothStep</a>:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np from numba import jit, njit import matplotlib.pyplot as plt @njit def GenSmooth...
<python><numpy><performance><vectorization><numba>
2023-10-15 11:23:32
1
5,123
Royi
77,296,360
15,844,296
Capturing key and mouse events application wide in Beeware/Toga
<p>I recently discovered <code>Beeware/Toga</code> and I'm considering switching to it: it's so much nicer than <code>Tkinter</code> and it seems to be more straighforward than <code>wxPython</code>, and faster both at dev and run time. So I tried to build a few toy apps, one of them being a look-alike of <a href="http...
<python><user-interface><beeware>
2023-10-15 11:06:54
1
3,843
gimix
77,296,183
10,902,946
Plot a semantic segmentation using plotly
<p>Given an image as a <code>uint8</code> <code>numpy.ndarray</code> of shape <code>(H, W, C)</code> and a set of binary masks (<code>uint8</code>) of shape <code>(H, W)</code>, where each mask is related to an instance of a class <code>c</code> (you could think of a dictionary having the names of the classes as keys a...
<python><plotly><image-segmentation>
2023-10-15 10:14:24
0
552
Nicola Fanelli
77,295,962
2,782,188
Prevent my flask app using html unicode for curly braces
<p>I am making an API call in my flask app:</p> <pre><code>count = len(bankid) bankid = &quot;044&quot; response = requests.get(f&quot;{base_api_url}/banks/&quot; + &quot;{bankid}/branches&quot;.format(bankid=f&quot;{{{bankid}:0{count}d}}&quot;, headers=headers)) </code></pre> <p>My target is to use this url <code>http...
<python><flask><python-requests><flutterwave>
2023-10-15 09:10:19
2
956
George Udosen
77,295,731
4,776,689
PostgreSQL Values list (table constructor) with SQLAlchemy. How to for native SQL query?
<p>I am trying to use PostgreSQL Values list <a href="https://www.postgresql.org/docs/current/queries-values.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/current/queries-values.html</a> (also known as table constructor) in Python with SQLAlchemy.</p> <p>Here the SQL working in PostgreSQL</p> <pre><co...
<python><postgresql><sqlalchemy>
2023-10-15 07:55:24
1
2,990
P_M
77,295,712
1,815,710
Cannot find module in Jupyter Notebook but other python files can
<p>I'm trying to use JupyterLab/Notebook within my API Service as a playground as I think it's a bit nicer than simply using the terminal. I've installed <code>jupyterlab</code> in my virtual environment and I believe it's activated according to the top right corner of the image uploaded. However, when I try to import ...
<python><jupyter-notebook><jupyter-lab>
2023-10-15 07:47:10
0
16,539
Liondancer
77,295,709
12,859,833
Greenlet installation fails with `OSError`
<p>I try to install the <code>optuna</code> package into a TensorFlow <code>tensorflow:2.11.1-gpu</code> image. However, it failed with</p> <pre><code>ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/usr/local/include/python3.8/greenlet' </code></pre> <p>Installing other vers...
<python><tensorflow><hyperparameters><optuna><greenlets>
2023-10-15 07:46:47
1
343
emil
77,295,658
7,818,560
Airflow DAG breaks with JSONDecodeError
<p>So my DAG starts like given below:</p> <pre><code>import airflow from datetime import timedelta, datetime from airflow import DAG from airflow.models import Variable from airflow.contrib.operators.bigquery_operator import BigQueryOperator default_args = { &quot;owner&quot;: &quot;scheduled_queries&quot;, &quot;depe...
<python><json><google-cloud-platform><airflow><directed-acyclic-graphs>
2023-10-15 07:29:25
1
509
user12345
77,295,565
14,498,998
Static and Media files are not shown in django website - nginx & gunicorn
<p>I'm trying to deploy a django website on a vps and it's now up and running(after a lot of trouble!), but now my media and static files are not shown in my website and I really tried a lot of ways but none of them worked.</p> <p>My nginx configuration:</p> <pre><code>server { listen 80; server_name domain_nam...
<python><django><nginx><gunicorn><wsgi>
2023-10-15 06:46:20
1
313
Alin
77,295,311
2,013,747
how to define an "empty" async generator in Python?
<p>I need to define an &quot;empty&quot; async generator i.e. one that does not generate any values. Since the definition of an async generator is an async function containing a yield statement, this is what I came up with:</p> <pre><code>async def _empty_async_generator() -&gt; AsyncGenerator[str, None]: if False:...
<python><python-3.x>
2023-10-15 04:37:11
1
4,240
Ross Bencina
77,295,278
10,856,988
Displaying 'FILTERED' Dataframe in HoverToolTip (Bokeh)
<p>In Bokeh(3.2.2) <strong>while trying to display a filtered pandas dataframe in a Hover tooltip via callback , the cb_data.source/cb_data.x/cb_data.y = undefined .</strong><br /> How to retrieve current x,y properties in Javascript?</p> <p><a href="https://i.sstatic.net/FuN0E.jpg" rel="nofollow noreferrer"><img src=...
<python><bokeh>
2023-10-15 04:13:54
0
1,641
srt111
77,295,253
5,161,197
Efficient Queue with batching
<p>I want to implement an internal Queue for batch processing in my service. The client of my service would be making sequential calls with 1 element at a time and I would like to process multiple of them at once internally if I have them available. This will help me scale for the bulk operation case where requests are...
<python><go><queue><channel><job-batching>
2023-10-15 03:53:02
0
363
likecs
77,295,084
1,048,171
Convert YML object/dict to paths of directories using Ansible/Jinja/Python?
<p>For an Ansible role that needs to create multiple folders I want to work with a simple representation of the list of paths to create: an human readable YAML &quot;object&quot;.</p> <p>The following pseudo Ansible code should create (if missing) the following folders:</p> <ul> <li>/home/some-user/dir1</li> <li>/home/...
<python><ansible><jinja2>
2023-10-15 01:53:55
1
2,300
CDuv
77,295,081
16,565,444
Interpolate data from dictionary given a float index position
<p>I have a json file with data tuples of torque figures for given temperatures. Say I pull the data figures from the 46 degree portion:</p> <pre><code>j = {&quot;46&quot;: [[88.0, 95.3], [86.1, 93.4], [84.2, 91.3], [82.8, 89.7], [80.8, 87.8]]} </code></pre> <p>If I am then given a floating point number as a reference ...
<python><json><dictionary><floating-point><interpolation>
2023-10-15 01:51:22
1
489
PW1990
77,295,005
1,758,023
autogluon: Detected time series with length <= 2 in data
<p>I am using autogluon, and I have created my train_data from my dataframe.</p> <pre><code>train_data = TimeSeriesDataFrame.from_data_frame( df, id_column=&quot;index&quot;, timestamp_column=&quot;timestamp&quot; ) train_data.head() value item_id timestamp 0 2021-10-13 1409083.0 1 2021-10-14 14160...
<python><autogluon>
2023-10-15 01:03:11
2
2,198
Mark
77,294,679
10,431,629
Pandas Column Split a row with Conditional and create a separate Column
<p>It seems the problem is not difficult, but somehow I am not able to make it work. My problem is as follows. I have a dataframe say as follows:</p> <pre><code> dfin A B C a 1 198q24 a 2 128q6 a 6 1456 b 7 67q22...
<python><pandas><regex><group-by><split>
2023-10-14 22:18:43
3
884
Stan
77,294,444
7,714,681
Getting lists and dictionaries from my function call in the openai api
<p>While working with the ChatGPT api, I want to make function calls. Below is one of my functions:</p> <pre><code>{ &quot;name&quot;: &quot;set_absolute_parameter_values_for_component&quot;, &quot;example&quot;: &quot;Change the margin to ‘comfortable’.&quot;, &quot;description&quot;: &quot;Set specific values for ...
<python><openai-api><chatgpt-api>
2023-10-14 20:43:26
0
1,752
Emil
77,294,405
2,600,531
handling multiprocessing.Manager() server process termination
<p>I'm writing my first multiprocessing application.</p> <p>When the OS kills the server process spawned by multiprocessing.Manager(), whether it's due to OOM or if I manually SIGKILL it, some but not all of my child processes also terminate. My application is left in a bad state and systemctl does not restart it as I ...
<python><multiprocessing><systemd><watchdog>
2023-10-14 20:30:59
1
944
davegravy
77,294,353
2,458,922
mutiple Gaussian Curves to fit scipy optimize curve_fit ,
<p>Refer, <a href="https://github.com/shuyu-wang/DSC_analysis_peak_separation/tree/main/DSC-Automatic%20multimodal%20decomposition" rel="nofollow noreferrer">https://github.com/shuyu-wang/DSC_analysis_peak_separation/tree/main/DSC-Automatic%20multimodal%20decomposition</a></p> <p>Consider X is a sum of Multiple Gaussin...
<python><curve-fitting><gaussian><scipy-optimize><gaussian-mixture-model>
2023-10-14 20:16:29
1
1,731
user2458922
77,294,331
22,466,650
How to relay the sum of each nested list to the next one?
<p>My input is this list :</p> <pre><code>my_list = [[3, 4, -1], [0, 1], [-2], [7, 5, 8]] </code></pre> <p>I need to sum the nested list <code>i</code> and pad it to the right of the list <code>i+1</code>, it's like a relay course.</p> <p>I have to mention that the original list should be untouched and I'm not allowed ...
<python><list>
2023-10-14 20:10:34
6
1,085
VERBOSE
77,294,212
4,348,534
How do I get the URL of a quoted retweet?
<p>Take this tweet (you will have to be logged into twitter to see it): <a href="https://twitter.com/JoeBiden/status/1712487592740978801" rel="nofollow noreferrer">https://twitter.com/JoeBiden/status/1712487592740978801</a></p> <p>It quotes this tweet, <a href="https://twitter.com/BidenHQ/status/1712485207121465481" re...
<python><html><selenium-webdriver>
2023-10-14 19:35:08
1
4,297
François M.
77,294,119
11,101,156
How to add combination memory to an Agent with tools?
<p>I want to create an Agent that will have 2 tools and a combined memory.</p> <ul> <li>Tools should be a <code>python_reply_tool</code> and my custom tool <code>search_documents</code>.</li> <li>I do not have problem adding the tools to the agent via <code>initialize_agent()</code> function</li> <li>But I cannot figur...
<python><langchain><large-language-model><py-langchain>
2023-10-14 18:58:30
1
2,152
Jakub Szlaur
77,293,938
391,918
No module named 'fuzzywuzzy
<p>I have created function fuzzy_match in postgres database. I have also installed fuzzywuzzy on my machine using <code>pip3 install fuzzywuzzy</code> command and I can see fuzzywuzzy installed in my <code>python3.10\site_packages\</code> folder and I also see that I am using python version 3.10 when I run command <cod...
<python><postgresql><dbeaver>
2023-10-14 17:58:20
0
4,412
Ajit Goel
77,293,884
8,152,837
Trigger st.forms when download button is clicked in streamlit, python
<p>I've created a streamlit app. I intend to use this app to gather email ids of the users. I want to create a form input whenever someone clicks on the download button for the output they created with my app. I'm not sure how to use the on_click keyword for this. Let me know if there's any other solution This is what ...
<python><streamlit>
2023-10-14 17:43:06
0
469
Sushant
77,293,877
14,309,684
How to wait for the response in Python requests?
<p>Let's say I have a code like this:</p> <pre><code>def send_request(): response = requests.get(url=&quot;https://www.google.com/&quot;) # wait for the response threading.Thread(target=send_request, daemon=False).start() </code></pre> <p>I am sending the request on the background thread. How do I wait until ...
<python><python-requests>
2023-10-14 17:40:14
3
1,695
Kumar
77,293,657
14,829,523
Sort pandas df based on balances
<p>I have the following dummy df:</p> <pre><code>import pandas as pd # Create the initial DataFrame df = pd.DataFrame({'car': ['Pickup', 'Racer', 'Lorry', 'Luxury', 'Cabrio', 'Bicycle', 'Truck'], 'old_owner': ['1', '1', '1', '2', '2', '3', '1'], 'new_owner': ['2', '3', '2', '1', '...
<python><pandas>
2023-10-14 16:31:12
1
468
Exa
77,293,646
9,811,964
How to cluster people who live close (but not too close) to each other?
<p><strong>What I have:</strong></p> <p>I have a pandas dataframe with columns <code>latitude</code> and <code>longitude</code> which represent the spatial coordinates of the home of people.</p> <p>This could be an example:</p> <pre><code>import pandas as pd data = { &quot;latitude&quot;: [49.5659508, 49.568089, 49.56...
<python><pandas><cluster-analysis><k-means><nearest-neighbor>
2023-10-14 16:29:13
1
1,519
PParker
77,293,582
19,392,385
A better way to store image with discord py?
<p>I am developing a discord bot and some commands require the user to input a file. The problem comes when fetching the files since as for now, I am using the URL. But with discord new update, any discord link older than a certain amount of minute won't display the image anymore.</p> <p>For context I simply use the im...
<python><discord.py>
2023-10-14 16:11:51
0
359
Chris Ze Third
77,293,479
2,996,578
numpy: FutureWarning: future versions will not create a writeable array from broadcast_array. Set the writable flag explicitly to avoid this warning
<p>The following snippet raises a warning in numpy v1.24:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np x = np.array(0) y = np.array([1, 2, 3]) x_, y_ = np.broadcast_arrays(x, y) x_.flags.writeable # FutureWarning: future versions will not create a writeable array from broadcast_array. Set th...
<python><numpy>
2023-10-14 15:42:19
2
1,188
ndou
77,293,194
10,963,057
Content of Page is not found in beautiful soup soup
<p>I am trying to get access to the &quot;historical quotes&quot;. I want to save the date and the close prices in a dataframe. I use bs4 to scrape the page, but I can't find the data in the page_soup.</p> <pre><code>import requests from bs4 import BeautifulSoup url = &quot;https://www.marketscreener.com/quote/index/M...
<python><beautifulsoup>
2023-10-14 14:22:59
1
1,151
Alex
77,293,193
3,099,733
NameError when using `eval` in closure
<p>Consider the following code</p> <pre class="lang-py prettyprint-override"><code>a = 1 fn = eval('lambda: a') fn() </code></pre> <p>it will work well. But if I move the above code into a closure</p> <pre class="lang-py prettyprint-override"><code>def x(): a = 1 fn = eval('lambda: a') fn() x() </code></pre> <p>T...
<python>
2023-10-14 14:22:53
0
1,959
link89
77,292,972
2,727,028
How to loop over subarrays until the end of a numpy array
<p>Suppose that we have a numpy array:</p> <pre><code>a = np.array([0,1,2,3,4,5,6,7,8,9]) </code></pre> <p>What I'm looking for is a way to loop over subranges in the array starting from a position from the end. For example like this:</p> <pre><code>[4 5] [6 7] [8 9] </code></pre> <p>The following code does not work:</...
<python><numpy-slicing>
2023-10-14 13:22:23
1
441
Sanyo Mn
77,292,760
5,119,359
Calculate overlapping track segments
<p>My goal is to achieve something similiar to the Strava Global Heatmap Feature. So basically calculating heatmaps for tracks coming from GPX sources.</p> <p>Lets say i have two GPX Files. I managed to import them via ogr2ogr as MultiLine Strings into a PostGIS database. Now i have two rows in my tracks table with the...
<python><geospatial><postgis><spatial>
2023-10-14 12:10:49
1
557
fighter-ii
77,292,752
235,671
Custom formatter properties not initialized via "." when "format" specified
<p>I have a custom <code>logging.Formatter</code> that supports some additional properties, but they don't get initialized when I also specify the <code>format</code> property. If I comment the <code>format</code> line out, the <code>.</code> property properly initializes its custom properties.</p> <pre class="lang-py ...
<python><python-logging>
2023-10-14 12:08:40
1
19,283
t3chb0t
77,292,726
494,826
Feeding my classifier one document at a time
<p>I want my <code>ModelBuilder</code> class to feed a <code>self._classifier = MultinomialNB()</code> with the content of some webpages I scraped. The documents are many and pretty big, so I can't load the whole set to memory. I'm reading them file by file. Here's the relevant portion of code:</p> <pre><code>X = [] ...
<python><machine-learning><scikit-learn><nlp><tfidfvectorizer>
2023-10-14 11:59:02
1
9,430
Fabio B.
77,292,565
1,215,175
VS Code Flask configuration seemingly causing "unable to import module"
<p>I have a Flask app that works on both macOS and Windows, but there are some &quot;module not found&quot; messages showing in VS Code terminal on Windows (even though the app still works fine in spite of the issues). Seems like something wrong with VS Code configuration?</p> <p>Note that the /Website is a subfolder o...
<python><visual-studio-code><flask>
2023-10-14 11:01:48
1
995
mr.b
77,292,564
1,084,174
Getting error "ValueError: The truth value of a Series is ambiguous" when I use lambda in Python
<p>Testing pandas <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html" rel="nofollow noreferrer">apply</a> API:</p> <pre><code>import numpy as np import pandas as pd z = np.random.randint(1, 5, size=(5, 5)) z.sort() df = pd.DataFrame(z) def mkp(s): return s.pow(s) mkpow = lambda s:...
<python><pandas>
2023-10-14 11:01:35
1
40,671
Sazzad Hissain Khan
77,292,463
13,086,128
ValueError: operands could not be broadcast together with shapes (10,) (9,)
<p>I am trying to compare 2 numpy arrays</p> <pre><code>np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) </code></pre> <p>I am getting this error:</p> <pre><code>ValueError Traceback (most recent call last) &lt;ipython-input-3-b1eabe8aba9f&gt; in &lt;cell ...
<python><python-3.x><numpy>
2023-10-14 10:22:59
1
30,560
Talha Tayyab
77,292,377
700,070
Pass a value from a function to array value in another function
<p>I have a function:</p> <pre><code>def latest_file_to_backup(): # returns latest file from a directory # called variable $latest_file </code></pre> <p>I have another function which I'm attempting to make which performs an API call to upload a file:</p> <pre><code>def auth_to_pcloud(latest_file): from pcloud ...
<python><linux><raspberry-pi>
2023-10-14 09:57:22
2
2,680
Jshee
77,292,075
2,540,336
How do I extract files embedded in docx files in Python?
<p>I am trying to extract files that are embedded in docx files in Python. I have created a simple docx that contains an embedded pdf, an embedded zip and an embedded docx to begin with.</p> <p>I have been using the code below.</p> <pre class="lang-py prettyprint-override"><code>from pathlib import Path from zipfile im...
<python><ms-word><ms-office><openxml><openxml-sdk>
2023-10-14 08:08:41
1
597
karpan
77,291,538
5,632,400
Find kth node from the end
<p>I written below function to <code>find kth node from the end.</code> However, one hidden test case is failing. Please let me know what is wrong with below code.</p> <pre><code>def find_kth_from_end(l, k): slow = l.head fast = l.head for _ in range(k): fast = fast.next if fast is None: ...
<python><python-3.x><data-structures><linked-list><singly-linked-list>
2023-10-14 03:42:26
1
15,885
meallhour
77,291,444
17,835,656
how can i send file from s3 into the user in django?
<p>i have a website , this website you can use it to upload a file.</p> <p>after that the users will be able to download what you have uploaded in that website.</p> <p>i upload a file , and this file is getting saved inside a bucket in AWS-S3.</p> <p>now how can i read that file from the bucket and send it to the user ...
<python><python-3.x><django><amazon-web-services><amazon-s3>
2023-10-14 02:50:53
1
721
Mohammed almalki
77,291,430
3,731,622
How to use GTK with cv2.namedWindow and cv2.imshow?
<p>How can I set the backend to GTK so that when I use <code>cv2.namedWindow</code> and <code>cv2.imshow</code> to display an image the GTK backend is used?</p> <pre><code>cv2.namedWindow('some_name_for_the_window', cv2.WINDOW_NORMAL) cv2.imshow('some_name_for_the_window', the_image_variable) </code></pre>
<python><opencv><backend><gtk>
2023-10-14 02:44:30
1
5,161
user3731622
77,291,235
547,198
Python: Object cannot access __bases__ attribute
<p>An class instance should have access to the classes attributes.<br /> <code>__bases__</code> as per my understand is a class attribute<br /> If I have a class called <code>C1</code>, I can call <code>C1.__bases__</code> but if I define an instance of <code>C1</code>, <code>obj1 = C1()</code>, <code>obj1.__bases__</c...
<python>
2023-10-14 00:46:20
3
7,362
TimeToCodeTheRoad
77,291,177
22,674,380
Errors in loading a Tensorflow .pb model: Exception encountered when calling layer "lambda_2" (type Lambda)
<p>I'm trying to load a pre-trained <code>saved_model.pb</code> model from <a href="https://github.com/NJU-Jet/SR_Mobile_Quantization" rel="nofollow noreferrer">this</a> repo (from the root of that repo so error is reproduceable). I want to just pass an image and visualize the resulting output image. According to some ...
<python><keras><deep-learning><neural-network><tensorflow2.0>
2023-10-14 00:09:00
0
5,687
angel_30
77,291,148
1,066,445
Running stable diffusion gives No module named 'ldm.util' error
<p>I am trying to run Stable Diffusion with the following command</p> <p><code>python3 scripts/txt2img.py --prompt &quot;red velvet cake&quot; --plms</code></p> <p>I get the following error:</p> <p><code>No module named 'ldm.util'; 'ldm' is not a package</code></p> <p>I tried multiple solutions such as running the comm...
<python><pip><stable-diffusion>
2023-10-13 23:55:16
1
4,232
Art F
77,291,084
7,212,809
MultiProcessing Signal handling: Why isn't parent task killed when child task is terminated?
<p>As per my understanding, when using &quot;fork&quot; context, a signal delivered to a subprocess triggers parent's handler.</p> <p><a href="https://github.com/python/cpython/issues/75670" rel="nofollow noreferrer">https://github.com/python/cpython/issues/75670</a></p> <p>However that doesn't seem to be the case for ...
<python><multiprocessing>
2023-10-13 23:27:01
1
7,771
nz_21
77,290,835
4,249,338
Negative list index in a format string
<p>The following string formatting involving list indexing works fine with positive indexes but fails with a type error on negative indexes. I find it surprising as negative indexing is very pythonic.<br /> I am looking for a way to make that work or at least an explanation for why that's not possible.</p> <pre class=...
<python>
2023-10-13 21:56:33
0
656
gg99
77,290,832
4,180,276
Subprocess.run timeout not killing subprocess
<p>I'm currently on <code>python-3.8.10</code> on <code>Ubuntu 20</code> with the following code. And despite every attempt the timeout does not seem to work. I'm unsure if I am inputing the text wrong?</p> <pre><code> cmd = 'ebook-convert &quot;%s&quot; &quot;%s&quot;' % (filename, outfile) process = subproces...
<python><subprocess><ubuntu-20.04>
2023-10-13 21:55:26
1
2,954
nadermx
77,290,740
901,426
SQLite3 fetchall not actually fetching all
<p>i created a simple table with 4 rows and populated it with data. when i examine the table in the interpreter, all data is present and correct. when i run <code>fetchall()</code> through the Python code, i only get 2 rows. what's going on?</p> <p>here's the table (portSettings):</p> <pre class="lang-sql prettyprin...
<python><sqlite>
2023-10-13 21:31:15
1
867
WhiteRau
77,290,667
11,748,924
python requests stream iterate header only instead of body
<p>This code I got from this <a href="https://medium.com/edureka/python-requests-tutorial-30edabfa6a1c" rel="nofollow noreferrer">site</a></p> <pre><code>import requests req = requests.get('path/to/forest.jpg', stream=True) req.raise_for_status() with open('Forest.jpg', 'wb') as fd: for chunk in req.iter_content(chun...
<python><request><stream>
2023-10-13 21:12:43
1
1,252
Muhammad Ikhwan Perwira
77,290,655
2,471,211
Trino Python SDK - Server Side Cursor
<p>I am looking for a way to use a server side cursor with the <a href="https://github.com/trinodb/trino-python-client" rel="nofollow noreferrer">Trino Python SDK</a>. I have a query that returns a large dataset and I want to keep memory usage in check.</p> <p>If I use SQLAlchemy and Pandas, I am able to process it as ...
<python><sqlalchemy><bigdata><trino>
2023-10-13 21:08:52
0
485
Flo
77,290,646
5,924,264
How to restrict instances of a class from accessing certain methods?
<p>I currently have a class that has several attributes and methods. I want to implement a pseudo alternative constructor for a special case initialization. I plan to use the method described in <a href="https://stackoverflow.com/a/682545">https://stackoverflow.com/a/682545</a>.</p> <p>Here's a skeleton of what I want ...
<python><class>
2023-10-13 21:07:06
1
2,502
roulette01
77,290,510
1,445,660
access fields by column name in SqlAlchemy raw select
<pre><code>games = session.execute(statement=text('select game.id as id, * from game')).all() for game in games: print(game['id']) </code></pre> <p>I get `tuple indices must be integers or slices, not str'. How can I access the fields by column names and not by index?</p>
<python><sqlalchemy>
2023-10-13 20:36:29
2
1,396
Rony Tesler
77,290,496
10,101,321
Pathlib joining absolute path together
<p>I'm trying to join two path together, the second starts with a leading slash.</p> <pre class="lang-py prettyprint-override"><code>from pathlib import Path path = Path('/first', '/second') # outputs WindowsPath('/second') # expecting WindowsPath('/first/second') print(path) </code></pre> <p>From the example above,...
<python><python-3.x><path><pathlib>
2023-10-13 20:33:35
1
850
Apollo-Roboto
77,290,438
7,452,343
Issue with multiple inheritance Python parent class
<p>I have a class <code>SeriesIDTestLoader</code> that inherits from both <code>CSVSeriesIDLoader, CSVTestLoader</code>.</p> <pre><code> class SeriesIDTestLoader(CSVSeriesIDLoader, CSVTestLoader): def __init__(self, series_id_col: str, main_params: dict, return_method: str, return_all=True, forecast_total=336): ...
<python><pytorch>
2023-10-13 20:19:45
1
918
igodfried
77,290,205
2,232,418
Python in-memory GZIP on existing file
<p>I have a situation where I have an existing file. I want to compress this file using gzip and get the base64 encoding of this file and use this string for latter operations including sending as part of data in an API call.</p> <p>I have the following code which works fine:</p> <pre><code>import base64 import gzip ...
<python><file><encoding><io><gzip>
2023-10-13 19:23:27
1
2,787
Ben