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
79,069,823
2,072,312
How do I insert timestamp data into an AWS Glue managed Iceberg table using AWS Firehose?
<p>Using AWS Firehose to ingest data into an Iceberg table managed by AWS Glue, I'm unable to insert timestamp data.</p> <p><strong>Firehose</strong></p> <p>I'm trying to insert data using the following script:</p> <pre class="lang-py prettyprint-override"><code>json_data = json.dumps( { &quot;ADF_Record&qu...
<python><amazon-web-services><aws-glue><amazon-kinesis-firehose><apache-iceberg>
2024-10-09 10:43:22
2
832
Crolle
79,069,771
7,483,211
Mypy throws syntax error for multi-line f-strings, despite code running without error
<p>I'm working with Python 3.12 and recently added <code>mypy</code> type-checking to my project. I've encountered an odd issue where <code>mypy</code> throws a syntax error for certain f-strings in my code, specifically those with newline characters in the middle of the f-string. The curious thing is that the Python i...
<python><syntax-error><mypy><f-string><python-3.12>
2024-10-09 10:28:36
2
10,272
Cornelius Roemer
79,069,684
4,993,513
Twilio playing only white noise while trying to stream audio
<p>I am trying to stream audio generated by ElevenLabs (via their websocket) back to Twilio. However, I was only able to hear white noise.</p> <p>However, when I used their API to get the audio, opened it, and streamed it to twilio, it was played on the phone properly.</p> <p>Below is my code where I'm trying to genera...
<python><audio><websocket><twilio><elevenlabs>
2024-10-09 10:08:36
1
11,141
Dawny33
79,069,603
2,613,150
Unable to configure Celery logging using a YAML configuration file with FastAPI server
<p>I am using Celery as the background task processor with a FastAPI web server. Logging for FastAPI is configured using a <code>logging.yaml</code> file via Uvicorn like this:</p> <pre><code>uvicorn syncapp.main:app --workers 4 --host 0.0.0.0 --port 8084 --log-config logging.yaml </code></pre> <p>I have configured mul...
<python><logging><celery><fastapi>
2024-10-09 09:48:17
2
2,357
Zobayer Hasan
79,069,570
3,169,872
Raising python exception from native thread
<p>I have a C++ class <code>Runner</code> that encapsulates running a native thread. This class is exposed to Python via <code>pybind11</code>, so <code>start_thread</code> is called from Python.</p> <pre class="lang-cpp prettyprint-override"><code>class Runner { public: void start_thread() { thread_ = std:...
<python><c++><exception><pybind11>
2024-10-09 09:40:58
1
1,653
DoctorMoisha
79,069,554
10,557,442
PySpark: New column with uppercase name is dropped unexpectedly
<p>I am trying to add a new column <code>CHANNEL_ID</code> in my PySpark DataFrame based on conditional logic using <code>pyspark.sql.functions.when</code> and after that, removing the old column <code>channel_id</code>, which is no longer needed. However, the new column doesn't appear in the resulting DataFrame when I...
<python><dataframe><apache-spark><pyspark>
2024-10-09 09:38:31
1
544
Dani
79,069,392
11,277,108
How to tell if CloseSpider was raised at the level of CrawlerProcess
<p>I need to run my scrapers in a loop but if certain errors occur in a spider I'd like to be able to raise <code>CloseSpider</code>and for this to filter up to the looping function and stop the loop.</p> <p>Here's my code so far which works fine with a fully functioning spider but I've created a little MRE to test the...
<python><scrapy><python-multiprocessing>
2024-10-09 08:56:17
1
1,121
Jossy
79,069,112
17,277,677
chromaDB collection.query WHERE
<p>this is how i pass values to my where parameter:</p> <pre><code>results = collection.query( query_texts=user_info, n_results=10, where={&quot;date&quot;:&quot;20-04-2023&quot;} ) print(results['metadatas'], results['distances']) </code></pre> <p>what if i want my start day to be &quot;20-04-2023&quot; t...
<python><chromadb>
2024-10-09 07:43:09
1
313
Kas
79,069,042
16,545,894
is it possible to use the azure blob storage as a postgresql database server in a django project?
<p>I want to apply the <strong>PostgreSQL</strong> database in a <strong>azure blob storage</strong> In my <strong>Django</strong> Project. Because <strong>azure blob storage</strong> is cheaper than the <strong>SQL</strong> database on <strong>azure</strong>.</p> <p>Is technically possible ?</p>
<python><django><postgresql><azure><azure-blob-storage>
2024-10-09 07:21:07
1
1,118
Nayem Jaman Tusher
79,068,751
4,935,114
Convert a pure Python list of lists to a numpy array of pure python lists (of 1 dimension)
<p>I have a list of a certain Python object (let's call it <code>MyClass</code>) that can be interpreted as a multi-dimensional Numpy array. However, I'd like to convert that list to a numpy array of <code>MyClass</code>, and not try to convert <code>MyClass</code> to an inner Numpy array. Just for the sake of the ques...
<python><arrays><numpy>
2024-10-09 06:02:28
2
2,916
Doron Behar
79,068,558
748,175
Stripping prefix in python module name
<p>I have the following tree structure:</p> <pre><code>volleybot/ - vbt/ +- BUILD +- api.py - tests/ +- BUILD +- api_test.py </code></pre> <p>From <code>tests/api_test.py</code>, I would like to be able to write: <code>from vbt import api</code>, instead of <code>from volleybot.vbt import api</code>. How can I do that?...
<python><bazel>
2024-10-09 04:49:50
1
13,030
qdii
79,068,519
13,086,128
ERROR: Failed building wheel for pyarrow (Failed to build pyarrow)
<p>I am installing <code>pyarrow</code> on python 3.13:</p> <pre><code>pip install pyarrow </code></pre> <p>this is what I am getting:</p> <pre><code>C:\Users\dev\AppData\Local\Programs\Python\Python313&gt;py -3.13 -m pip install pyarrow Collecting pyarrow Downloading pyarrow-17.0.0.tar.gz (1.1 MB) -------------...
<python><pip><python-3.13>
2024-10-09 04:24:59
2
30,560
Talha Tayyab
79,068,298
6,471,140
valueError: Supplied state dict for layers does not contain `bitsandbytes__*` and possibly other `quantized_stats`(when load saved quantized model)
<p>We are trying to deploy a quantized Llama 3.1 70B model(from Huggingface, using bitsandbytes), quantizing part works fine as we check the model memory which is correct and also test getting predictions for the model, which is also correct, the problem is: after saving the quantized model and then loading it we get</...
<python><artificial-intelligence><huggingface-transformers><large-language-model><quantization>
2024-10-09 02:25:28
1
3,554
Luis Leal
79,068,176
2,955,827
Why we need sync_to_async in Django?
<p>The <a href="https://docs.djangoproject.com/en/5.1/topics/async/#asgiref.sync.sync_to_async" rel="nofollow noreferrer">document</a> said:</p> <blockquote> <p>The reason this is needed in Django is that many libraries, specifically database adapters, require that they are accessed in the same thread that they were cr...
<python><django><multithreading><python-asyncio>
2024-10-09 00:59:27
1
3,295
PaleNeutron
79,068,166
10,150,736
Jupyter notebook module not found python3
<p>I am receiving this module error while using <code>jupyter notebook</code>:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import sisl %matplotlib inline plt.rcParams['font.size'] = 16 Emin, Emax = -15, 15 --------------------------------------------------------------------------- ModuleNotFoun...
<python><python-3.x><jupyter-notebook><modulenotfounderror>
2024-10-09 00:50:29
0
2,474
Emanuele
79,067,938
4,963,334
Peewe upgrade causing weired autocommit behaviour
<p>We currently use peewe 2.x and this is the code we use custom mysql connection:</p> <pre><code>from peewee import MySQLDatabase class SQLDb(MySQLDatabase): def connect(self, *args, **kwargs): attempts = 5 while attempts &gt; 0: # Logic to retry db connection def begin(self): self.e...
<python><mysql><peewee><flask-peewee>
2024-10-08 22:15:12
2
1,525
immrsteel
79,067,913
6,780,025
Is it possible to load configs from a file for a "dynamic config group" in Hydra?
<p>Imagine a complex config that specifies many ML models, each with some number of layers. Something like</p> <pre><code>@dataclass class Layer: width: int activation: str ... @dataclass class Model: layers: List[Layer] @dataclass class Forest: models: Dict[str, Model] </code></pre> <p>Then, I have a ...
<python><fb-hydra>
2024-10-08 22:05:39
1
3,643
iga
79,067,793
2,016,632
When I register blueprints within init then they fail to register, why is that?
<p>There are dozens of questions about disappearing blueprints on StackExchange, but this may be the tersest example yet. Assume app.py is in upper folder and __init__.py, etc are in a subfolder &quot;test&quot;. The following fails:</p> <p><strong>app.py</strong></p> <pre><code>from test_bad import create_app # Start...
<python><flask>
2024-10-08 21:11:06
1
619
Tunneller
79,067,766
2,437,514
Render LATEX math in Excel using Python in Excel
<p>I'd like to use <strong>Python in Excel</strong> to display some LATEX math formulas in cells.</p> <p>Creating these images is easy when just using the <code>sympy</code> library, but one has to have <code>latex</code> installed. <strong>Python in Excel</strong> runs on Anaconda distribution and it does not include ...
<python><excel><latex><sympy>
2024-10-08 20:59:07
2
45,611
Rick
79,067,648
14,179,793
Docker exec with python subprocess.Popen failes
<p><strong>Objective</strong> Use <code>docker exec</code> on an EC2 instance to run a command in another container that is on the instance.</p> <p><strong>Code</strong>:</p> <pre><code>from base64 import decode import json import subprocess with open('temp.json', 'r') as file: event = json.load(file) encoded = j...
<python><docker><amazon-ecs>
2024-10-08 20:09:06
0
898
Cogito Ergo Sum
79,067,505
2,056,452
Mapping between GeoPandas coordinates and MatPlotLib coordinates
<p>I'd like to draw a map with <code>geopandas</code> which I then want to overlay with standard <code>matplotlib</code> plots as subplots.</p> <pre><code>map = gpd.read_file(&quot;my_shapefile.shp&quot;) map[&quot;values&quot;] = np.random.rand(len(map)) fig, ax = plt.subplots(1, 1, figsize=(15, 15)) map.plot(column=&...
<python><matplotlib><geopandas>
2024-10-08 19:23:09
1
13,801
derM
79,067,419
8,521,346
Django Prefetch Related Still Queries
<p>I have the function</p> <pre><code>def selected_location_equipment(self): qs = (Equipment.objects .prefetch_related('service_logs') .all()) return qs </code></pre> <p>That returns a queryset with a few related fields grabbed.</p> <p>The problem is that when i access the prefetched da...
<python><django>
2024-10-08 18:53:09
2
2,198
Bigbob556677
79,067,351
2,056,452
Move labels close to "axis" on pyplot "radar_chart"
<p>I use matplotlib and geopandas to plot a map. Now I'd like to plot additional information on top of this map, e.g. using radar charts or pie charts.</p> <p>I got this sweet function, which creates radar charts for me</p> <pre><code>def radar_chart(ax, data, categories, color, label_fontsize=8): N = len(categorie...
<python><matplotlib>
2024-10-08 18:29:25
1
13,801
derM
79,067,242
8,963,682
Bot Framework: 'access_token' Error When Sending Messages in Teams Bot Using Python
<p>I'm building a Teams bot using the Bot Framework SDK for Python, integrated with FastAPI. The bot is supposed to send periodic updates to users every 60 seconds after they send an initial message. However, I'm facing issues with sending messages due to an <code>access_token</code> error.</p> <p>When I use <code>turn...
<python><botframework><fastapi><microsoft-teams>
2024-10-08 17:58:57
0
617
NoNam4
79,067,153
8,232,165
KITTI IMU data gaps interpolation
<p>I am using some IMU data from KITTI raw dataset. There are gaps in OxTs IMU data. I want to interpolate the gaps. The data looks periodically. Is there any way to interpolate them realistically? Below is the visualization of accelerations at XYZ axis.</p> <p><a href="https://i.sstatic.net/K2QkBJGy.png" rel="nofollow...
<python><math><time-series><interpolation><kitti>
2024-10-08 17:29:52
1
453
Bai Yang
79,067,125
20,591,261
Efficiently Handling Large Combinations in Polars Without Overloading RAM
<p>I have a list of n values (in my case, n=19), and I want to generate all possible combinations of these values. My goal is to use each combination as a filter for a Polars DataFrame, iterate over the combinations, do some functions, and save the results into a new DataFrame.</p> <p>However, since n=19, this results ...
<python><python-itertools><python-polars>
2024-10-08 17:21:34
0
1,195
Simon
79,067,000
7,326,981
Unable to install azureml-dataset-runtime
<p>I am using a M1 mac running on MacOS Sonoma 14.7. I have project dependencies that I need to install to execute the project. I am using Python version 3.8. When I install the same dependencies on Windows machine it works fine.</p> <p>Below are the dependencies.</p> <pre><code>azureml azureml-core azureml-dataset-run...
<python><pip><apple-m1><azure-machine-learning-service><pyarrow>
2024-10-08 16:42:47
0
1,298
Furqan Hashim
79,066,931
2,840,125
Query a pandas DataFrame for a Windows path
<p>I need to inventory a network server. I want to save a list of file names, paths, file sizes, and created and accessed dates into a CSV file. Here is my code:</p> <pre><code>df = pd.read_csv(r&quot;C:\Users\ME\Documents\INVENTORY.csv&quot;) for root, dirs, files in os.walk(r&quot;S:\XXXXXXXXXXX&quot;): for file ...
<python><python-3.x><pandas>
2024-10-08 16:26:06
1
477
Kes Perron
79,066,683
11,561,121
Unable to replace python function definition with mock and unitest
<p>I am trying to write integration test for the following python code:</p> <pre><code>import xx.settings.config as stg from xx.infrastructure.utils import csvReader, dataframeWriter from pyspark.sql import SparkSession from typing import List from awsglue.utils import getResolvedOptions import sys def main(argv: Lis...
<python><mocking>
2024-10-08 15:20:46
2
1,019
Haha
79,066,674
22,371,917
Flask and CSRF tokens
<p>I'm trying to use <code>csrf</code> tokens with my Flask app, but I noticed after a little bit of the site being open(1 hour), it wouldn't work unless I reloaded, so I did a little testing and found out its because of the <code>csrf</code> tokens expiring, so I tried generating a new one every request(which is what ...
<python><flask><csrf><csrf-token>
2024-10-08 15:17:41
1
347
Caiden
79,066,654
2,897,115
snowflake: python connector: execute many: not able to insert
<h1>I have created a table</h1> <pre><code>CREATE TABLE &quot;VALIDATION_RULES_RESULTS&quot; ( id INT AUTOINCREMENT, created_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP, mongo_data_ingestion_id STRING, table_name STRING, col_name STRING, rule_name STRING, success STRING, element_count INT, ...
<python><snowflake-cloud-data-platform>
2024-10-08 15:15:07
1
12,066
Santhosh
79,066,590
13,634,560
plotly dash, css file not connecting
<p>I am attempting to move from plotly to dash, and would like to connect a css file to style my dashboard. The app renders fine with my file structure; app.py and index.py in the main folder, and an additional style.css file in the /assets folder.</p> <p>however, when I add some styling to the css, the main dash app d...
<python><css><plotly-dash>
2024-10-08 14:59:30
1
341
plotmaster473
79,066,491
8,188,120
'Flask' object is not iterable | AWS lambda using zappa
<p>I am trying to deploy a Flask app on AWS lambda using zappa. (I am very new to this so if I need to provide more relevant information, please ask!)</p> <p>The Flask app has this directory structure:</p> <pre><code>backend ├── __init__.py ├── __pycache__ ├── app.py ├── databases ├── home.py ├── static ├── templates └...
<python><amazon-web-services><flask><aws-lambda><zappa>
2024-10-08 14:33:05
1
925
user8188120
79,066,483
1,922,959
Seaborn plot labeling
<p>Very new to Seaborn...using it in a class and using VSCode to edit notebooks for assignments.</p> <p>Without uploading a bunch of data here, I have the following code:</p> <pre><code>myPlot = sns.barplot(dfFrequencies, x=&quot;Topic&quot;, y=&quot;Relative Frequency&quot;) myPlot.set_xticklabels(myPlot.get_xticklabe...
<python><seaborn>
2024-10-08 14:31:14
1
1,299
jerH
79,066,478
999,162
Django reusable Many-to-one definition in reverse
<p>I'm struggling to make a Many-to-one relationship reusable.</p> <p>Simplified, let's say I have:</p> <pre><code>class Car(models.Model): ... class Wheel(models.Model): car = models.ForeignKey(Car) ... </code></pre> <p>Pretty straight forward. What, however, if I'd like to use my <code>Wheel</code> model...
<python><django><orm><many-to-one>
2024-10-08 14:29:02
2
5,274
kontur
79,066,324
2,915,050
Get every key in JSON whose value is an array and its path
<p>I have a JSON file, and for some keys their value is an array. The JSON can go up to an unspecified depth. I would like to know how to extract all the keys whose value is an array, and also the JSON path to that array.</p> <p>Example schema:</p> <pre><code>[ { &quot;field1&quot;: &quot;x&quot;, &...
<python><json>
2024-10-08 13:49:45
1
1,583
RoyalSwish
79,066,076
133,374
Distinguish native type from user type
<p>I want to be able to distinguish some native class like <code>_functools.partial</code> (<a href="https://github.com/python/cpython/blob/43ad3b51707f51ae4b434e2b5950d2c8bf7cca6e/Modules/_functoolsmodule.c#L758" rel="nofollow noreferrer">code</a>, <a href="https://github.com/python/cpython/blob/43ad3b51707f51ae4b434e...
<python>
2024-10-08 12:55:44
1
68,916
Albert
79,066,074
6,533,161
Python CSV Reader & Writer to respect the double quotes
<p>I'm new to Python and working on below use case:</p> <p>I want my Python script to enhance a csv file.</p> <p>My <code>input.csv</code> looks like below:</p> <pre><code>test_case,test_desc,&quot;test data 1&quot;,&quot;test data 2&quot; ,0,&quot;&quot;, </code></pre> <p>I want to enhance this to add two more columns...
<python><csv>
2024-10-08 12:55:22
1
808
Roshan007
79,065,764
448,357
Django max_length validation for BinaryField causes KeyError in translation __init__.py
<p>I have a simple model, something like</p> <pre class="lang-py prettyprint-override"><code>class Notenbild(models.Model): bild_data = models.BinaryField(max_length=500000, editable=True) </code></pre> <p>In <code>admin.py</code></p> <pre class="lang-py prettyprint-override"><code>class BinaryFieldWithUpload(forms...
<python><django><validation><django-admin><binary-data>
2024-10-08 11:35:34
0
9,860
Alexander Pacha
79,065,461
335,247
Typing polars dataframe with pandera and mypy validation
<p>I am considering <code>pandera</code> to implement strong typing of my project uses <code>polars</code> dataframes.</p> <p>I am puzzled on how I can type my functions correctly.</p> <p>As an example let's have:</p> <pre class="lang-py prettyprint-override"><code> import polars as pl import pandera.polars as pa from ...
<python><python-typing><mypy><python-polars><pandera>
2024-10-08 10:12:35
1
3,713
ohe
79,065,271
10,451,021
Trying to pass prompt value into the code in Azure DevOps (python)
<p>I am trying to get userStory value from user while running build pipeline in Azure DevOps. I want to use that value as a variable into the python script that I am building. I tried below code with yaml, Also attached is the error.</p> <pre><code>trigger: - main pool: vmImage: 'ubuntu-latest' parameters: - name...
<python><azure-devops><azure-pipelines><azure-pipelines-yaml>
2024-10-08 09:30:42
2
1,999
Salman
79,065,268
6,105,404
Horizontal bar chart with matplotlib and an x-offset
<p>I'd like to make a horizontal bar chart with the length of the space mission (in years) on the x-axis plotted against cost of mission given on the y-axis.</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt data = pd.read_csv('mission_lifetime.dat') length_of_mission = data['Mission_End_Year']-data...
<python><matplotlib><plot><histogram>
2024-10-08 09:30:20
1
1,918
npross
79,065,238
11,403,193
Python 3.13 distutils.msvccompiler Not Found Error
<p>During the installation of <code>gymnasium-2048</code> I came across this rather persistent error message: <code>ModuleNotFoundError: No module named ‘distutils.msvccompiler</code></p> <p>A quick google search suggests installing MSVC compiler by Visual Studio Installer, etc. But this alone did not solve the problem...
<python><visual-c++><pip>
2024-10-08 09:22:30
1
401
SiminSimin
79,065,191
801,924
Why hexa decode need two digit
<p>The <code>hex</code> Python function produce <code>0x0</code> for the <code>0</code> number:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; hex(0) '0x0' </code></pre> <p>But <code>bytes.fromhexa</code> only accept hexa with minimum of two digits:</p> <pre class="lang-py prettyprint-override"><code>...
<python>
2024-10-08 09:14:04
2
7,711
bux
79,065,189
1,481,986
Matplotlib venn3 empty subgroup layout
<p>I'm creating a venn3 diagram using <code>matplotlib_venn</code> where one of the subsets is empty. Minimal example -</p> <pre><code>from matplotlib_venn import venn3, venn3_circles group1 = set([1,2, 3]) group2 = set([1, 4, 5]) group3 = set([4, 5]) venn3(subsets = [group1, group2, group3], set_labels = ['a','b' ,'c...
<python><matplotlib><matplotlib-venn>
2024-10-08 09:13:19
1
6,241
Tom Ron
79,065,062
9,324,997
Copy a ML Model from one Azure Databricks workspace to another Databricks Workspace
<p>I ran the below code to export the ML Model in <strong>Azure Databricks</strong> based mlflow but I seem to be getting this error</p> <blockquote> <p>MLflow host or token is not configured correctly</p> </blockquote> <p>I'm unable to figure out what the issue is. The URL for the workspace is correct along with the P...
<python><machine-learning><azure-databricks><mlflow>
2024-10-08 08:39:33
1
460
Gopinath Rajee
79,064,907
3,494,271
How to ensure QWebEngineScript is executed before any other JS script in HTML document?
<p>I'm trying to add to a PyQt5 application a QtWebEngineView widget. This widget must load the following very simple SVG (which, by specs, I cannot modify):</p> <pre><code>&lt;!DOCTYPE svg PUBLIC &quot;-//W3C//DTD SVG 1.1//EN&quot; &quot;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&quot;&gt; &lt;svg version=&q...
<javascript><python><pyqt5><qwebengine>
2024-10-08 08:04:31
0
945
Silverspur
79,064,048
829,979
Issues with Using `--extra-index-url` in `uv` with Google Cloud Artifact Registry
<p>I'm trying to create a <code>uv</code> project that uses an <code>--extra-index-url</code> with Google Cloud Artifact Registry. According to the <a href="https://docs.astral.sh/uv/guides/integration/alternative-indexes/" rel="nofollow noreferrer">uv documentation</a>, this should be possible. I am using <code>uv 0.4...
<python><google-cloud-platform><uv>
2024-10-08 01:22:17
2
685
Jonatas Eduardo
79,063,940
688,563
Cannot figure out why previously working FastAI learner inference now fails with CUDA 12 and Jetpack 6.0
<p>I have a Jetson Orin and the internal drive failed. I had to flash from scratch.</p> <p>I had some working Fastai 2.0 based code with a PyTorch version ~1 year ago and also a previous version of CUDA, I believe some version of 11.x. The Jetpack version was 5.x.</p> <p>I now flashed the latest version of Jetpack on t...
<python><pytorch><fast-ai>
2024-10-07 23:59:44
0
368
PhilBot
79,063,876
5,153,500
VSCode shows duplicate tests in Python
<p>I don't know if this due to a recent update, but I am seeing my Python tests appear twice and when I am in test debug mode it runs twice as well. How can I fix this? I just created an empty project and I am running into the same issue.</p> <p>Steps to reproduce:</p> <ol> <li><p><code>python -m venv .venv</code> (cre...
<python><visual-studio-code><pytest><vscode-debugger>
2024-10-07 23:13:14
1
560
Semih Sezer
79,063,772
2,778,405
AWS Lambda timing out on return statement
<p>I'm trying to write a simple lambda function to use as a view for an application that has parquet data living in an S3 bucket. I'm just trying to test out a simple function here:</p> <pre><code>import json import time t = time.time() print('This ') import os import urllib.parse import boto3 import pandas as pd imp...
<python><amazon-web-services><aws-lambda>
2024-10-07 22:10:27
0
2,386
Jamie Marshall
79,063,686
898,042
how to catch throw and other exceptions in coroutine with 1 yield?
<p>I have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:</p> <pre><code>DICTIONARY = { 'a': 'apple', 'b': 'banana', 'c': 'cat', 'd': 'dog', } </code></pre> <p>M...
<python><coroutine><yield>
2024-10-07 21:26:36
3
24,573
ERJAN
79,063,645
3,849,662
Gaps and inconsistent ordering in plotly express bar chart
<p>I have a dataframe that consists of 3 columns, Date, Name, Number. With 5 dates (may change depending on time data extract is run) and 10 names per date. The same name can appear in multiple dates, or may only appear in one date. Numbers can be positive or negative. The data is ordered by Date (<code>ascending=True<...
<python><pandas><plotly>
2024-10-07 21:09:29
1
773
Joe Smart
79,063,592
8,869,570
Quickest way to compute the sum of squared elements of the result of a matrix multiplication?
<p>I want to do something like this in Python</p> <pre><code>sum(square(matmul(A, B))) </code></pre> <p>There are various ways you can achieve this behavior, e.g.,</p> <pre><code>sum(np.square(np.matmul(A, B))) </code></pre> <p>or</p> <pre><code>np.lingalg.norm(np.matmul(A, B)) ** 2 </code></pre> <p>I haven't profiled ...
<python><numpy><matmul>
2024-10-07 20:47:01
1
2,328
24n8
79,063,569
11,515,528
Error encountered scrapping data using Selenium due to NoneType
<p>I am extracting data from the website <code>https://octopus.energy/dashboard/new/accounts</code> that requires a login. I have been successfully accessing it using Selenium with this code.</p> <pre><code>driver = webdriver.Chrome() wait = WebDriverWait(driver, 30) page = driver.get(electric_meter) user_name =&quot;x...
<python><selenium-webdriver><web-scraping>
2024-10-07 20:34:00
1
1,865
Cam
79,063,494
7,347,925
How to accelerate getting points within distance using two DataFrames?
<p>I have two DataFrames (df and locations_df), and both have longitude and latitude values. I'm trying to find the df's points within 2 km of each row of locations_df.</p> <p>I tried to vectorize the function, but the speed is still slow when <code>locations_df</code> is a big DataFrame (nrows&gt;1000). Any idea how t...
<python><pandas><dataframe><dask><geopandas>
2024-10-07 20:02:28
1
1,039
zxdawn
79,063,476
2,512,377
Adding a policy to my custom chain in nftables via python libnftables is failing, can you tell me why?
<p>I'm trying to create a table, chain and ruleset for nft in python to act as a whitelist.</p> <p>So I need a chain with policy of &quot;drop&quot; to drop all outbound packets that do not match approved destinations set out in the rules of that chain.</p> <p>I want to use a custom table to keep maintenance easier and...
<python><json><netfilter><nftables>
2024-10-07 19:53:31
1
549
user2512377
79,063,329
5,536,016
Django custom function taking a long time to run for the view
<p>I have a function below that generates a navigation so it can be using in the view. It is pulling in the articles, article category, and article subcategory. The main issue is that with about 15 category and 46 subcategory and 33 articles it is taking like 7-10 seconds to finish loading this function. What is the be...
<python><django>
2024-10-07 18:59:30
1
1,765
Nello
79,063,204
6,068,462
Matplotlib's plt.show() throwing "ValueError: object __array__ method not producing an array"
<p>I'm trying to run the following simple lines of Python code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt x = np.array([1, 2, 3]) y = np.array([4, 5, 6]) plt.plot(x, y) plt.show() </code></pre> <p>But 'm getting the following error for the plt.show() line:</p> <pre><code>Traceback (most recent...
<python><numpy><matplotlib><valueerror>
2024-10-07 18:29:37
1
541
TheTomer
79,063,140
6,068,462
ModuleNotFoundError: No module named 'distutils.msvccompiler' when trying to install numpy 1.16
<p>I'm working inside a conda environment and I'm trying to downgrade numpy to version 1.16, but when running <code>pip install numpy==1.16</code> I keep getting the following error:</p> <pre><code>$ pip install numpy==1.16 Collecting numpy==1.16 Downloading numpy-1.16.0.zip (5.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━...
<python><numpy><anaconda><conda><distutils>
2024-10-07 18:13:22
1
541
TheTomer
79,063,135
1,178,841
Python Filtering
<p>In my application I have a list of films that I want to filter by year or other criterias. My filters work fine except the year (= variable annee)</p> <p>In the following code the variable annee becomes {'9', '1'} for video['année'] = 1999 all the other variables have no such problem</p> <pre><code>def populate_com...
<python>
2024-10-07 18:11:14
1
571
G. Trennert
79,063,091
13,142,245
FastAPI stateful dependencies
<p>I've been reviewing the <a href="https://fastapi.tiangolo.com/tutorial/dependencies/#first-steps" rel="nofollow noreferrer">Depends docs</a>, official example</p> <pre class="lang-py prettyprint-override"><code>from typing import Annotated from fastapi import Depends, FastAPI app = FastAPI() async def common_par...
<python><fastapi>
2024-10-07 17:58:50
1
1,238
jbuddy_13
79,062,904
2,071,807
How to create a subclass with a different type parameter to its parent
<p><a href="https://peps.python.org/pep-0695/" rel="nofollow noreferrer">PEP 695</a> introduced a nice way to specify type parameters in a generic class.</p> <p>But I find the rules around inheritance confusing. I would like to inherit from a class which specifies a type parameter, but replace the parent's type paramet...
<python>
2024-10-07 16:57:54
0
79,775
LondonRob
79,062,895
9,983,652
Error of Could not reach host. Are you offline when converting html file into PDF
<p>I am attempting to change an html file into PDF document. I tried multiple methods but none of them proved effective. The html documentwas saved stored on the U drive of my company's network.</p> <p>For instance, when I am use pyhtml2pdf, I consistently encounter the error displayed below.</p> <p><a href="https://p...
<python>
2024-10-07 16:56:08
1
4,338
roudan
79,062,864
1,839,674
VS Code Pytest won't run individual tests
<p>My VS Code instance (1.94.0) can discover the tests (after modifying the settings.json) and it does run all the tests if I press the &quot;Rerun Tests&quot; button on top of the VSCode Testing Pane (beaker icon).</p> <p>However, using the VSCode Testing Pane (beaker icon), when I drill down to the individual tests, ...
<python><visual-studio-code><pytest>
2024-10-07 16:48:09
0
620
lr100
79,062,809
1,966,790
Find out whether filesystem supports extended attributes
<p>I have python program that calls another (external) program:</p> <pre><code>cmd = [ &quot;unsquashfs&quot;, &quot;-n&quot;, &quot;-d&quot;, dirname, filename ] subprocess.check_call( cmd ) </code></pre> <p>It worked so far. But now I started running this program in /tmp with tmpfs filesystem, which doesn't support x...
<python><linux><filesystems><xattr>
2024-10-07 16:31:46
1
3,033
MateuszL
79,062,615
536,262
python logger init to `level=20` (INFO) do not show debug if I later change to `level=10` (DEBUG)
<p>I changed my logging default level to <code>logging.INFO</code> (20) from <code>Logging.DEBUG</code> (10), but then it wont show debug messages if I change logLevel to 'DEBUG' later on in the code:</p> <p>Old config works fine:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import mylog &gt;&gt;&gt...
<python><logging>
2024-10-07 15:36:25
2
3,731
MortenB
79,062,605
898,042
how to generate correct output using 2 yield statements in coroutine?
<p>i have var DICTIONARY, which is a dictionary where the keys are English letters and the values are words that start with the corresponding letter. The initial filling of DICTIONARY looks like this:</p> <pre><code>DICTIONARY = { 'a': 'apple', 'b': 'banana', 'c': 'cat', 'd': 'dog', ... } </code></p...
<python><coroutine><yield>
2024-10-07 15:34:13
1
24,573
ERJAN
79,062,545
1,295,422
Compute FFT after reading accelerometer data
<p>I'd like to detect abnormal vibrations on a motor I have. I'm using the following devices:</p> <ul> <li>Raspberry PI 5</li> <li>Adafruit accelerometer ISM330DHCX</li> </ul> <p>I've successfully managed to read the sensor at a specific rate (2000Hz) and I'm using it's absolute value (although it's not changing that m...
<python><linux><numpy><fft><raspberry-pi5>
2024-10-07 15:23:28
1
8,732
Manitoba
79,062,434
11,062,613
Conda downgrading NumPy during package update
<p>I have a virtual Conda environment named dev that was created using the following YAML file:</p> <pre><code># *** dev.yml *** name: dev channels: - defaults # Check this channel first - conda-forge # Fallback to conda-forge if packages are not available in defaults dependencies: - python==3.12 - nu...
<python><numpy><conda>
2024-10-07 14:52:56
1
423
Olibarer
79,062,292
7,500,268
TypeError: expected np.ndarray (got numpy.ndarray)
<p>I use the below code and it report error, This is a very simple example and should not report error as expected.</p> <pre><code>import numpy as np import torch as th # Assuming tt is some data (example as list) tt = [1, 2, 3, 4, 5] # Example data # Check if tt is a NumPy array, and convert if necessary if not isi...
<python><python-3.x><numpy><pytorch>
2024-10-07 14:09:24
2
797
Z. Zhang
79,062,223
19,155,645
RAG with Haystack: compiles but returns empty responses
<p>My RAG pipeline (using Haystack) compiles and runs, but is returning empty responses.<br> From my checks, I thought it might be due to the embedding and llm models not being compatible, so I changed to an embedding model that is based on same as my llm model (both based on mistral).</p> <pre><code>mymodel = &quot;oc...
<python><huggingface-transformers><embedding><rag><haystack>
2024-10-07 13:49:25
0
512
ArieAI
79,061,819
4,461,051
Check if any value in a Polars DataFrame is True
<p>This is quite a simple ask but I can't seem to find any clear simplistic solution to this, feels like I'm missing something.</p> <p>Let's say I have a DataFrame of type</p> <pre><code>df = pl.from_repr(&quot;&quot;&quot; ┌───────┬───────┬───────┐ │ a ┆ b ┆ c │ │ --- ┆ --- ┆ --- │ │ bool ┆ bool ┆ ...
<python><dataframe><data-science><python-polars>
2024-10-07 11:49:38
3
746
Jerry
79,061,810
11,703,652
Sync pl.StringCache / Categorical encoding across machines in polars
<p>I need polars <code>Categorical</code> data type to have the same physical representation across different machines. On one machine, I can use <code>pl.StringCache</code> to get the same physical representation:</p> <pre class="lang-py prettyprint-override"><code>with pl.StringCache(): s1 = pl.Series(&quot;color...
<python><python-polars><categorical>
2024-10-07 11:46:21
1
361
McToel
79,061,645
9,773,920
Box-api get_items() folders fetch limits to 15 folders
<p>I am trying to fetch a specific folder under the<code>target_folder_name</code> variable from my box account using get_items in box SDK. However, my code below fetches only first 15 folder names and stops rightafter. Pagination is not working as expected.</p> <pre><code>def lambda_handler(event, context): bo...
<python><sdk><box-api><box>
2024-10-07 10:49:36
0
1,619
Rick
79,061,618
10,566,155
Fuzzy Join on Venue Names Based on City
<p>I am working with PySpark and need to join two datasets based on the city and a fuzzy matching condition on the venue names. The first dataset contains information about stadiums including a unique venue_id, while the second dataset, which I receive periodically, only includes venue names and cities without the venu...
<python><sql><pyspark><apache-spark-sql>
2024-10-07 10:39:48
1
329
Harshit Mahajan
79,061,520
12,350,600
How get PDF/A compliance with fpdf2
<p>I am able to generate a pdf with fpdf2 but I want it to show up with the PDF/A compliance tag in Adobe Acrobat Reader. Basically i want the below text to appear when the PDF is opened.</p> <p><a href="https://i.sstatic.net/65PEgleB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/65PEgleB.png" alt="PDF...
<python><python-3.x><pdf><fpdf2>
2024-10-07 10:09:18
1
394
Kruti Deepan Panda
79,061,506
525,229
How can you verify two tar.gz files are identical
<p>I am making a sharing protocol, and when you share a folder it gets tar.gz-ipped and inserted in a folder.</p> <p>It's created like this:</p> <pre><code>with tarfile.open(full_data_name, &quot;w:gz&quot;, format=GNU_FORMAT) as tar_handle: ... tar_handle.add(file_path) </code></pre> <p>When you do that again, I...
<python><python-3.x><gzip><tar>
2024-10-07 10:04:38
1
2,969
Valmond
79,061,437
151,829
Verifying Amazon SNS signatures in Python
<p>I am struggling to get a successful signature validation when I send a test message through <code>complaint@simulator.amazonses.com</code>. Below is my current relevant Python code after some trial and error. But I always get an InvalidSignature error on <code>signing_cert.public_key().verify</code>. Any ideas on wh...
<python><amazon-web-services><cryptography><amazon-sns>
2024-10-07 09:44:24
0
16,763
Botond Béres
79,061,128
6,111,772
python: class with global variables
<p>Of course there should be no global variables - vars should be passed with function calls. My actual implementation needs lots of variables which are used in different &quot;xxx.py&quot; modules. So I tried to make an own class including these variables and put it in an own module named e.g. &quot;vars.py&quot;:</p>...
<python><module><global-variables>
2024-10-07 08:08:52
1
441
peets
79,061,095
5,378,816
Using Annotated[...] in a type statement
<p>The <code>type</code> statement is relatively new (3.12+) and its support in <code>mypy</code> is experimental:</p> <blockquote> <p>PEP 695 type aliases are not yet supported. Use --enable-incomplete-feature=NewGenericSyntax for experimental support</p> </blockquote> <p>Here is a short program were mypy (with the fe...
<python><python-typing>
2024-10-07 08:00:50
0
17,998
VPfB
79,060,768
13,560,598
stacking rugplots in seaborn
<p>Is there a way to stack rugplots in Seaborn as in <a href="https://d2mvzyuse3lwjc.cloudfront.net/images/WikiWeb/Rug_Plot/Distribution_Curve_with_Rug.png?v=10549" rel="nofollow noreferrer">here</a> but below the x-axis?. I have not found anything on the rugplots <a href="https://seaborn.pydata.org/generated/seaborn.r...
<python><matplotlib><seaborn>
2024-10-07 06:06:28
1
593
NNN
79,060,606
15,002,748
DeprecationWarning: The `ipykernel.comm.Comm` class has been deprecated. Please use the `comm` module instead
<p>I'm trying to build recommendation engine using Azure Databricks notebook by using the algorithm from mlxtend library. I'm able to train the model successfully. However, there is a warning during training process as shown in the screenshot below:</p> <p><a href="https://i.sstatic.net/IxLkGpVW.png" rel="nofollow nore...
<python><jupyter-notebook><azure-databricks><ipywidgets><deprecation-warning>
2024-10-07 04:41:44
1
1,127
weizer
79,060,390
1,641,112
Where is the documentation for how ptyest implements conftest.py files?
<p>I'm new to Python. Been playing with pytest and I'm ready to tear my hair out. As best I can tell, an older version of pytest, 7.2.2 searches up the directory tree and merges in conftest file. In 8.3.3, it only seems to find conftest.py if it's in the same directory I run the tests in.</p> <p>I can't find any offici...
<python><pytest>
2024-10-07 01:43:18
0
7,553
StevieD
79,060,340
19,090,490
Elegant way to add a list view test case in drf
<p>I have one concern in writing the test code for list view.</p> <p>For DRF's list view, it responds to multiple data.</p> <p>What should I do if I assume that the response.data object is a model with many fields?</p> <pre><code>response.data --&gt; [{&quot;id&quot;: 1, &quot;field1&quot;: &quot;xxx&quot;, &quot;field...
<python><django><django-rest-framework><django-tests>
2024-10-07 00:55:36
1
571
Antoliny Lee
79,060,140
13,279,557
Does Python allow defining a C function that a shared library can call directly?
<p>I figured out how to let Python call a function from my shared library:</p> <pre class="lang-py prettyprint-override"><code>import ctypes def bar(): return 1337 dll = ctypes.PyDLL(&quot;./mod.so&quot;) assert dll.foo(ctypes.c_float(42)) == 42 + 1337 </code></pre> <p>where <code>mod.so</code> can call that <co...
<python><c><shared-libraries>
2024-10-06 21:48:36
1
672
MyNameIsTrez
79,060,070
12,011,020
What to return in a preprocessing function for optimal performance
<p>My starting point is a large polars LazyFrame.</p> <p>I have written a function (<code>def preprocessing(df:pl.Lazyframe</code>) that has to take in a <code>pl.LazyFrame</code> (it can unfortunately not be a <code>pl.Expr</code>).<br /> The function which does a long chain of operations on different columns of the l...
<python><performance><python-polars>
2024-10-06 20:52:40
0
491
SysRIP
79,060,062
1,332,263
Tkinter Notebook: Activate Button on Tab1 from Tab2
<p>On Tab1 I have a Test button that can be &quot;turned on&quot; by pressing the Test button directly or by pressing the &quot;activate button&quot;. From Tab2 I want to press &quot;activate button on Tab 1&quot; and have the Test button on Tab 1 &quot;turn on&quot; and show the green ON state. If I remove &quot;Noteb...
<python><tkinter>
2024-10-06 20:48:41
1
417
bob_the_bob
79,060,045
219,153
How to declare multiple similar member variables of a dataclass in a single line?
<p>Can this <code>dataclass</code> declaration:</p> <pre><code>@dataclass class Point: x: float y: float z: float </code></pre> <p>be rewritten in order to reduce boilerplate and resemble something like this:</p> <pre><code>@dataclass class Point: x, y, z: float </code></pre>
<python><python-dataclasses>
2024-10-06 20:34:13
1
8,585
Paul Jurczak
79,060,002
1,936,046
Model Loader errors in Text Gen Web UI`
<p>I have tried loading multiple models from HuggingFace using Text Gen Web UI, but no matter the model or the loader, I get the same &quot;ModuleNotFoundError&quot; for the loaders.</p> <p>Importantly, I am using an Intel i7 and not a GPU, but I have been able to run smaller models using different UI tools in the past...
<python><large-language-model><huggingface>
2024-10-06 20:11:37
1
764
Duanne
79,059,906
558,639
GoogleAuth getting "invalid grant: Bad Request" in call to LocalWebserverAuth()
<p>Here's a Python script in its entirety:</p> <pre><code>from pydrive.auth import GoogleAuth gauth = GoogleAuth() gauth.LoadClientConfigFile(&quot;client_secrets.json&quot;) print(f'==== called LoadClientConfigFile', flush=True) gauth.LocalWebserverAuth() # Prompt for authentication via web browser </code></pre> <p>...
<python><windows><google-oauth>
2024-10-06 19:12:33
1
35,607
fearless_fool
79,059,839
6,618,225
Delete content from PDF using Python
<p>I need to cleanse a large number of PDFs from PDF content and leave only an image inside (the structure of the PDFs is always the same).</p> <p>Here is a screenshot of the PDF content:</p> <p><a href="https://i.sstatic.net/rUI78Wxk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rUI78Wxk.png" alt="ent...
<python><pdf>
2024-10-06 18:42:46
1
357
Kai
79,059,699
4,505,998
How to make `__getitems__` return a dict?
<p>In torch's <code>Dataset</code>, on top of the obligatory <code>__getitem__</code> method, you can implement the <code>__getitems__</code> method.</p> <p>In my case <code>__getitem__</code> returns a dict, but I can't figure out how to do the same with <code>__getitems__</code>.</p> <pre class="lang-py prettyprint-o...
<python><pytorch><pytorch-dataloader>
2024-10-06 17:25:24
1
813
David Davó
79,059,576
18,769,241
top lip to nose ratio aspect to detect chewing activity not working as expected
<p>I want to know whether a person is chewing in front of a camera or not using dlib's facemarks. For this end I compute the distance from nose to top lip and derive the mean, then if the that value is bigger than a threshold then we could say that the person is chewing.</p> <p>To compute the nose to top lip distance I...
<python><face-recognition><dlib><face-landmark>
2024-10-06 16:30:51
0
571
Sam
79,059,555
233,928
python running in cursor can't see an installed package. What makes packages visible in python?
<p>I wrote code using pygame, and so installed it:</p> <pre><code>pip install pygame </code></pre> <p>From the command line, the code works.</p> <p>In cursor (an AI-enabled editor that appears to be based on vscode) though, it shows up as missing, and when I try to run the program,</p> <pre><code>ModuleNotFoundError: n...
<python><vscode-debugger>
2024-10-06 16:21:05
1
8,644
Dov
79,059,505
15,178,267
Handling Errors in Django Test Cases
<p>I am currently writing test cases using Django and would like to improve the way we handle errors, particularly distinguishing between errors that arise from the test cases themselves and those caused by the user's code.</p> <h3>Context:</h3> <p>Let’s say a user writes a function to fetch and increment the likes cou...
<python><django>
2024-10-06 15:53:45
1
851
Destiny Franks
79,059,331
13,634,560
best way to fill nans, getting the mean from multiple columns
<p>I have a dataframe with reviews of restaurants. a columns &quot;description sentiment&quot; has been assigned a score ranging from -1.00 - +1.00. Some of the rows are 0 (due to some other factors in the dataframe), and so I'd like to interpolate some of the rows based on other info, like the Award score.</p> <pre><c...
<python><pandas><nan>
2024-10-06 14:30:16
0
341
plotmaster473
79,059,252
561,243
Indexing overlapping areas of a numpy array
<p>I have a 2D array of zeros (called labels) and a list of its coordinates (called centers). For each of the centers I would like to put a progressive number in a 5x5 cluster around it inside the label array.</p> <p>Should two centers be so close that the corresponding clusters are overlapping, then I would like the l...
<python><arrays><numpy><indexing><numpy-ndarray>
2024-10-06 13:54:24
3
367
toto
79,059,219
18,949,720
CLI game flickering
<p>I am trying to develop a small/lightweight implementation of Tetris running in the CLI, using Python. Currently, I am using a <code>print()</code> for each frame update, just after <code>os.system('cls')</code> to clear the terminal.</p> <p>The problem with this approach is heavy flickering which makes the game very...
<python><command-line-interface><game-development><tetris>
2024-10-06 13:38:38
1
358
Droidux
79,059,078
5,852,692
Applying reinforced-learning on combination of continuous and discrete action space environment
<p>I have a custom gym environment, where it has 3 continuous and 1 discrete action space. I would like to apply a reinforcement-learning algorithm, however I am not sure what to use.</p> <p>Below you can find the environment code, action space is basically setting some parameters within the gas network which is called...
<python><reinforcement-learning><openai-gym><dqn><gymnasium>
2024-10-06 12:30:55
0
1,588
oakca