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,242,121
11,062,613
How to rewrite a DataFrame-based grouped rolling aggregation function to use Polars Expressions?
<p>I need to apply a custom grouped rolling aggregation function to every nth row for specific columns of a DataFrame. My current implementation works with a DataFrame as an argument and returns the modified DataFrame.</p> <p>I have a few issues with the current approach:</p> <ul> <li>The function requires specifying m...
<python><function><python-polars>
2024-12-01 17:32:02
0
423
Olibarer
79,241,786
1,224,643
Sveltekit app hosted in Flask does not render
<p>I want to run a Sveltekit app from Flask</p> <pre><code>app = Flask(__name__, static_folder='sveltekit_build') </code></pre> <p>I don't have static files so i instead of</p> <pre><code>return send_from_directory('client/public', 'index.html') </code></pre> <p>I tried this instead</p> <pre><code> return send_from_...
<python><flask><vite><sveltekit>
2024-12-01 14:33:07
0
697
petercli
79,241,735
8,939,181
unexpected transformer's dataset structure after set_transform or with_transform
<p>I am using the feature extractor from ViT like explained <a href="https://colab.research.google.com/github/nateraw/huggingface-hub-examples/blob/main/vit_image_classification_explained.ipynb" rel="nofollow noreferrer">here</a>.</p> <p>And noticed a weird behaviour I cannot fully understand.</p> <p>After loading the ...
<python><machine-learning><neural-network><huggingface-transformers><huggingface-datasets>
2024-12-01 14:07:14
1
916
hamagust
79,241,613
13,968,392
Filter series in method chain
<p>What is the preferred syntax to filter a polars Series without referencing the Series explicitly? I.e. something that works with method chaining. I thought <code>pipe</code> would be an option but it is not available for Series.</p> <p>Without method chaining, I would do the following:</p> <pre><code>import polars a...
<python><filter><series><python-polars><method-chaining>
2024-12-01 13:04:27
0
2,117
mouwsy
79,241,502
1,924,315
Python error trying to install gensim on MacOS
<p>trying to install gensim on MacBook Pro (i7, Sonoma 14.7.1) using PyCharm (Python@3.13). I've tried several suggestions from stack, github and other sources but none worked.</p> <p>Based on what little I found online, it seems that it cannot find <strong>openblas</strong>, even though it is installed. But it is inst...
<python><macos><scipy><gensim><openblas>
2024-12-01 12:01:13
3
1,123
Blejzer
79,241,455
1,804,173
How to find the exact function annotations of Python's builtin `collections.abc` Protocol types?
<p>Python's standard library comes with a bunch of <code>Protocol</code> types in <code>collections.abc</code> like <code>Sequence</code>, <code>Mapping</code>, or <code>Iterable</code>. The documentation contains a nice overview <a href="https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-...
<python><python-typing>
2024-12-01 11:30:29
1
27,316
bluenote10
79,241,319
17,721,722
Autoflake prints unused imports/variables but doesn't remove them
<p>I'm using the <code>autoflake</code> tool to remove unused imports and variables in a Python file, but while it prints that unused imports/variables are detected, it doesn't actually remove them from the file.</p> <p>Here's the command I'm running:</p> <pre class="lang-bash prettyprint-override"><code>autoflake --in...
<python><django><flake><autoflake>
2024-12-01 10:00:18
1
501
Purushottam Nawale
79,241,286
7,887,965
Apache Nifi: Unable to Merge Multiple CSVs into a Single PARQUET File using ExecuteStreamCommand Processor
<p>I am trying to merge the <code>multiple CSVs</code> which are coming from upstream as a <code>flowfiles</code> of similar kind <code>(same Schema)</code> into a one <code>PARQUET</code> file format. Below is the Flow of my <code>processor group</code>. Where in upper <code>ExecuteStreamCommand</code> i am renaming t...
<python><csv><apache-nifi><parquet><pyarrow>
2024-12-01 09:43:50
0
407
Filbadeha
79,241,135
3,130,882
Pydantic vs. Python 3.13.0: No module named 'typing_extensions'
<p>I have code that worked fine with Python 3.10.12 and Pydantic 2.7.3.</p> <p>I read that Pydantic ^2.8 supports Python 3.13.</p> <p>The same code, and indeed even just <code>import pydantic</code> under a Python 3.13.0 shell with Pydantic 2.10.2, however, gives:</p> <pre><code> File &quot;/home/user/path-to-package/...
<python><pydantic><modulenotfounderror>
2024-12-01 07:58:15
1
431
GoneAsync
79,241,088
555,129
Update installed version of python
<p>I installed python 3.9.6 few years ago on my MacBook, I do not recollect how it was installed (homebrew was not used). Here is version/path info:</p> <pre><code>$ which python3 /usr/bin/python3 $ python3 -V Python 3.9.6 </code></pre> <ul> <li>How to update this python version to the latest?</li> <li>How to tell how...
<python>
2024-12-01 07:15:33
3
1,462
Amol
79,241,077
2,155,362
How to get data from post request?
<p>I built a pyton flask app like below:</p> <pre><code>#!/usr/bin/python # -*- coding: UTF-8 -*- from flask import Flask, request, jsonify, redirect from flask_restful import Api, Resource, reqparse import database_operators import json app = Flask(__name__) app.config.update(RESTFUL_JSON=dict(ensure_ascii=False)) a...
<python><flask>
2024-12-01 07:11:28
1
1,713
user2155362
79,241,075
12,466,687
Unable to use parameters value from command line to Quarto file while rendering Quarto document in python
<p>I am trying to pass parameter value using quarto CLI and use it in Quarto file with Python code but it's not working.</p> <p>Command used:</p> <pre class="lang-bash prettyprint-override"><code>quarto render test.qmd -P foo:5 --output test_cmd_out.html </code></pre> <p>Quarto doc (<code>test.qmd</code>):</p> <pre><co...
<python><jupyter><command-line-arguments><quarto>
2024-12-01 07:10:47
1
2,357
ViSa
79,241,034
1,335,492
How to maintain synchronization between distributed python processes?
<p>I have a number of workstations that run long processes containing sequences like this:</p> <pre><code>x = wait_while_current_is_set y = read_voltage z = z + y </code></pre> <p>The workstations must maintain synchronization with a central unit that runs processes like this:</p> <pre><code>x = set_current y = wait_w...
<python><parallel-processing><distributed-computing><distributed><distributed-system>
2024-12-01 06:40:10
1
2,697
david
79,240,851
8,384,910
Plotly add_image vs add_layout_image
<p>In Plotly, both <a href="https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html#plotly.graph_objects.Figure.add_image" rel="nofollow noreferrer"><code>figure.add_image</code></a> and <a href="https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html#plotly.graph_o...
<python><plotly>
2024-12-01 03:34:35
0
9,414
Richie Bendall
79,240,243
10,452,700
Why is SARIMAX expensive to apply over high-frequency data in Python? (epochs=5mins) Any alternative models?
<p>I’ve been experimenting with <a href="https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_sarimax_stata.html" rel="nofollow noreferrer">SARIMAX</a> using <a href="/questions/tagged/statsmodels" class="s-tag post-tag" title="show questions tagged &#39;statsmodels&#39;" aria-label="show questions t...
<python><sarimax><statsforecast><statmodels>
2024-11-30 18:18:24
0
2,056
Mario
79,240,178
726,730
python set and get windows 11 volume
<p>I have this script:</p> <pre class="lang-py prettyprint-override"><code>from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume from ctypes import cast, POINTER from comtypes import CLSCTX_ALL, CoInitialize, CoUninitialize CLSCTX_ALL = 7 import time def set_windows_volume(value_max_100): devices = AudioUt...
<python><audio><comtypes>
2024-11-30 17:43:46
1
2,427
Chris P
79,240,068
4,701,426
Problem renaming index value in pandas multiindex series
<p>Please consider this dataframe:</p> <pre><code>temp = pd.DataFrame({'has_exclamation': {('automotive', 0.0): 99.1814132659203, ('automotive', np.nan): 0.8185867340796917, ('beauty_spa', 0.0): 99.8, ('beauty_spa', np.nan): 0.15384615384615385, ('beauty_spa', 1.0): 0.04615384615384615}, 'has_exclamation_end':...
<python><pandas>
2024-11-30 16:49:04
2
2,151
Saeed
79,239,802
1,371,666
Attempting to freeze a part of scroll area in tkinter using python in Windows
<p>I am using python 3.11.9 in windows.</p> <p>Here is my minimum verifiable code:</p> <pre><code>import tkinter as tk class Table(tk.Frame): def __init__(self, master, header_labels:tuple,*args, **kwargs): tk.Frame.__init__(self, master, *args, **kwargs) # configuration for all Labels # ea...
<python><tkinter>
2024-11-30 14:56:44
1
481
user1371666
79,239,801
1,355,634
seaborn countplot count wrongly nan
<p>Somehow I have trouble in getting the right result from a countplot. Let's look at the following dummy data</p> <pre><code>In [111]: import pandas as pd In [112]: import seaborn as sns In [113]: import numpy as np In [114]: data = pd.DataFrame({&quot;A&quot;: [np.nan, np.nan, 2], &quot;Cat&quot;: [0,1,0], &quot;x...
<python><seaborn>
2024-11-30 14:55:58
1
2,042
math
79,239,708
4,423,300
import local module in Python
<p>My project structure looks like:</p> <pre class="lang-none prettyprint-override"><code>my_project/ ├── common_lib/ │ ├── __init__.py │ ├── file1.py │ └── file2.py └── module1/ ├── src/ │ ├── __init__.py │ ├── script1.py │ └── script2.py ├── __init__.py └── main.py </code></pre> <p...
<python>
2024-11-30 14:04:19
0
637
SheCodes
79,239,625
1,750,975
Using QGIS in Python
<p>I'm trying to use QGIS as my map provider in an Python GUI. However, I cannot get the app to launch.</p> <p>I've created an script that launches the Python app with the correct environmental variables.</p> <pre class="lang-bash prettyprint-override"><code>Write-Output &quot;Setting up QGIS environment&quot; # Path ...
<python><qgis><pyqgis>
2024-11-30 13:20:22
1
2,276
tim687
79,239,297
11,748,924
Numpythonic way of the inverse of sliding_window_view
<p>I have original array <code>test</code>:</p> <pre><code>from numpy.lib.stride_tricks import sliding_window_view test = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14]).reshape(-1,7) # (batch_size, seq_len) -&gt; (2,7) slided = sliding_window_view(test, window_shape=(3,), axis=-1).copy() print(test, test.shape) print(sl...
<python><numpy>
2024-11-30 10:13:11
1
1,252
Muhammad Ikhwan Perwira
79,238,689
476,444
Binding a ref-qualified function with nanobind
<p>What is the appropriate <code>nanobind</code> syntax to expose the instance method below?</p> <pre><code>struct Foo { int &amp;value() &amp; { return v; }; int v; }; </code></pre> <p>With <code>pybind</code>, one could use <code>static_cast</code> with <code>Foo::*</code> syntax to cast the function pointe...
<python><c++><nanobind>
2024-11-30 01:34:20
1
1,662
dgorur
79,238,610
13,325,046
determine which columns are equal after pandas merge betwen two dataframes
<p>I performed a merge with pandas using the suffix option like below:</p> <pre><code>df3 = df1.merge(df2, how='inner',on='key',suffixes=('_first', '_second')) </code></pre> <p>I now need to:</p> <ol> <li>pairwise check i.e. (<code>x_first == x_second</code> ) for the approx 60 pairs of columns</li> <li>If the columns ...
<python><pandas>
2024-11-29 23:58:19
1
495
te time
79,238,578
3,696,153
VSCode - python unit test locations
<p>I have a large python project - it contains multiple parts, and a number of local &quot;modules&quot; that I put in modules directory.</p> <p>For each local module, I want to create a set of UNIT TESTs.</p> <p>I specifically do not want <em>ALL</em> unit tests for the entire project in one flat directory. Instead, I...
<python><unit-testing><visual-studio-code>
2024-11-29 23:35:43
0
798
user3696153
79,238,475
11,091,148
Logging Inheritance in Python
<p>I am currently developing a core utils package where I want to set some logging properties (I know that this is not best practice, but it´s for interal purposes and intended to generate logs). When I now import the package nothing gets logged:</p> <pre><code># core.__main__.py class BaseLoggerConfig(BaseModel): ...
<python><python-3.x><logging><python-logging>
2024-11-29 22:19:44
1
526
Bennimi
79,238,420
784,044
Unable to import config.py into nested subdirectory
<p>New to python. I have the following directory structure - however, I am unable to import my config.py file into bottom level files. I have tried sys.path.append in my <code>__init__.py</code>, as well as importing in my <code>__init__.py</code> files. All ears if there's an easy way to do this. Thanks!</p> <p><a h...
<python>
2024-11-29 21:40:55
1
886
Sidd Menon
79,238,278
8,792,671
Python is retrieving data from nowhere (?)
<p>Currently I've been doing some tests to prepare for an interview to find the longest palindrome, and for some reason Python is retrieving data that is not supposed to.</p> <p>A brief resume about the issue... If you read the code and the output bellow, the only part of the code that I insert anything into <code>long...
<python><python-3.x>
2024-11-29 20:17:31
1
315
SakuraFreak
79,238,229
1,112,406
How can I eliminate spaces around Panel titles in Rich?
<p>I'm using Rich's Panel feature. Is there a way to eliminate the extra spaces Panel puts around title text? Here's an example from a Wordle program, which shows a sequence of Guesses. (It is written in and runs in Colab, hence the use of Rich.)</p> <p><a href="https://i.sstatic.net/ykemDeY0.png" rel="nofollow norefer...
<python><rich>
2024-11-29 19:55:58
1
2,758
RussAbbott
79,238,188
547,231
How to handle PRNG splitting in a jax.vmap context?
<p>I have a function which simulates a stochastic differential equation. Currently, without stochastic noise, my invokation of simulating the process up to time <code>t</code> looks like this (and, yeah, I need to use jax):</p> <pre><code>def evolve(u, t): # return u + dt * b(t, u) + sigma(t, u) * sqrt_dt * noise ...
<python><random><python-3.8><jax>
2024-11-29 19:33:27
1
18,343
0xbadf00d
79,238,174
9,064,356
Pyspark date parser raises timeParserPolicy upgrade exception even when already in CORRECTED mode
<p>Spark version: <code>3.3.1</code><br/> Python version: <code>3.9</code></p> <p>By default, calling <code>pyspark.sql.functions.to_date(col(&quot;foobar&quot;), &quot;yyyy-MM-dd&quot;)</code> raises spark upgrade exception if <code>foobar</code> col can't be parsed using given format and, at the same time, this <code...
<python><apache-spark><date><pyspark><upgrade>
2024-11-29 19:27:37
0
961
hdw3
79,238,038
4,929,704
Pyflink watermarks are stuck
<p>Here's my pyflink job. No matter how much I tried I was not able to get watermarks advance.</p> <p>The output I see is:</p> <pre><code>Event: (1, 1000), Current Watermark: -9223372036854775808 Event: (2, 2000), Current Watermark: -9223372036854775808 Event: (3, 3000), Current Watermark: -9223372036854775808 Event: (...
<python><apache-flink><flink-streaming><pyflink>
2024-11-29 18:18:46
1
341
Viktor Ershov
79,237,863
8,852,013
How can I use Mypy with cookiecutter templates? Mypy throws "is not a valid Python package name" error
<p>I have the following directory containing my files:</p> <pre><code>{{cookiecutter.project_name}} </code></pre> <p>I want to run mypy on this directory and all Python files above it (such as Cookiecutter hooks).</p> <p>When I try to run mypy . I get:</p> <pre><code>{{cookiecutter.project_name}} is not a valid Python ...
<python><mypy><cookiecutter>
2024-11-29 17:05:38
0
1,145
Alexis Drakopoulos
79,237,858
620,679
Efficient access to data in a series of transient Python scripts
<p>Pandoc has a filter that accepts Python snippets and uses (for example) Matplotlib to generate charts. I want to produce documents that produce many charts from a common data source (e.g. a pandas data frame).</p> <p>As an example:</p> <pre><code>Here's the first chart: ~~~{.matplotlib} import sqlite3 import numpy ...
<python><pandas><matplotlib><pandoc>
2024-11-29 17:03:52
1
4,041
Scott Deerwester
79,237,828
2,552,713
matplotlib cm.get_cmap(name, num_steps)
<p>My python code uses</p> <p><code>plt.cm.getcmap(&quot;coolwarm&quot;, num_steps)</code></p> <p>This causes a deprecation warning.</p> <p><code>The get_cmap function was deprecated in Matplotlib 3.7 and will be removed in 3.11. Use matplotlib.colormaps[name] or matplotlib.colormaps.get_cmap() or pyplot.get_cmap() ins...
<python><matplotlib>
2024-11-29 16:53:51
1
519
juerg
79,237,585
4,614,641
Compiling Python (3.13) with custom ncurses library path
<p>I would like to compile Python 3.13 (on CentOS 7.9), and my 'ncurses' compiled libraries are in a non-standard location (<code>~/custom/gcc-14.2/lib/</code>).</p> <p>Following the configuration documentation, I define <a href="https://docs.python.org/3/using/configure.html#cmdoption-arg-CURSES_LIBS" rel="nofollow no...
<python><compilation><configure>
2024-11-29 15:22:00
0
2,314
PlasmaBinturong
79,237,283
2,956,276
Extract specific exception from ExceptionGroup tree
<p><a href="https://docs.python.org/3.12/library/exceptions.html#ExceptionGroup" rel="nofollow noreferrer">ExceptionGroup</a>s in Python contains tuple of unrelated exceptions. Some of these exceptions can be also exception groups. So the specific exception (not the group one) can be nested in several exception groups....
<python><python-3.11>
2024-11-29 13:36:44
0
1,313
eNca
79,237,081
377,303
brython in iframe nags about:srcdoc#__main__ is not a url
<p>I'm resctircted to use iframe</p> <pre><code>&lt;html style='height: 100%'&gt; &lt;head&gt; &lt;script src='https://cdn.jsdelivr.net/npm/brython@3/brython.min.js'&gt;&lt;/script&gt; &lt;script src='https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.js'&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt;...
<python><brython>
2024-11-29 12:20:08
0
1,976
nerkn
79,237,024
1,406,168
Writing to application insights from a Phyton Azure Function App
<p>I am trying to add logs with custom dimensions to the trace table in application insights. I have code below working but it writes to the dependency table. Any pointers how to write to traces and metrics?</p> <pre><code>import azure.functions as cho from azure.monitor.opentelemetry import configure_azure_monitor fro...
<python><azure><azure-functions><azure-application-insights>
2024-11-29 12:00:06
1
5,363
Thomas Segato
79,236,951
3,333,319
Persisting changes to database backend using ibis-framework
<p>I am experimenting with the Ibis framework: it seems a great tool to work on tables that already contain data that I need to join, filter, aggregate, etc. However, I do not find how to persist changes into the database.</p> <p>As far as I understand, Ibis <code>Table</code>s are immutable objects that represent the ...
<python><sql><database><ibis>
2024-11-29 11:36:02
1
973
Sirion
79,236,903
15,673,975
Can't find local python package in parallel directory when using Prefect + Docker
<p>I have setup a Prefect deployment on a Docker image. The problem is that my flow package depends on a local package which is in a parallel directory:</p> <pre><code>main_folder |_ my_flow |_ src |_ my_flow |_ source code the depends on flow_dep... |_ flow_dep |_ src |_ flow_dep |_ source code...
<python><docker><python-packaging><prefect>
2024-11-29 11:21:57
0
374
ultrapoci
79,236,884
1,613,983
Confused by keras/tensorflow error: ValueError: None values not supported
<p>I'm trying to build a neural net in <code>tensorflow</code>/<code>keras</code> but I'm stuck on this error:</p> <pre><code>ValueError: None values not supported. </code></pre> <p>I've been able to reduce the code to reproduce this to the following mock example:</p> <pre><code>from tensorflow.keras import layers, Mo...
<python><tensorflow>
2024-11-29 11:15:35
1
23,470
quant
79,236,813
3,218,338
Need help dealing with certain address scenarios in large cities and Google Places API
<p>I have an issue with the London area using Google Places API and the endpoint for autocomplete. Why are we using autocomplete? Because our input is at time ambiguous. The background story is that we ask the customer for a specific location.</p> <p>Anyway, imagine the following address &quot;13 Manor Close&quot; bein...
<python><google-maps><google-places-api>
2024-11-29 10:52:02
1
682
user3218338
79,236,793
8,129,873
How to create index pattern in AWS opensearch using API?
<p>I've configured Opensearch domain in AWS. As part of automating configurations in opensearch, I want to create a set of index patterns.</p> <p>I've tried so many APIs available online, but could not succeed. Has anyone managed to create index pattern in AWS Opensearch?</p>
<python><amazon-web-services><opensearch><amazon-opensearch>
2024-11-29 10:46:04
2
425
Prathyush Peettayil
79,236,753
2,405,663
Python get data using column name instead of column index
<p>I have the following Python code to get data from database. I need to get data from Cursor, using column name description.</p> <pre><code>try: with _db.connect() as cnn: crr = cnn.cursor() crr.execute( &quot;SELECT Frame, ROW_NUMBER() OVER(ORDER BY Frame ASC),[Left Elbow Ulnar Deviati...
<python><database>
2024-11-29 10:34:03
0
2,177
bircastri
79,236,616
13,392,257
FastAPI - listen to kafka in separate thread
<p>I have a FastAPI application. The application subscribes to kafka-topic and handles messages (everything is working)</p> <p>But when I added http endpoints, noticed that can't call the endpoints, because I am listen to kafka in infinite loop.</p> <p>How to fix my code to enable http endpoints? I guess kafka subscrip...
<python><apache-kafka><fastapi><aiokafka>
2024-11-29 09:59:34
0
1,708
mascai
79,236,498
3,400,076
Pylint flagged import_error message
<p>I have executed PyLint on my python code and got flagged that I have &quot;import-error&quot; and the message is &quot;Unable to import 'requests'&quot;, &quot;Unable to import 'openpyxl'&quot; and other python modules.</p> <p>For openpyxl, I have installed the openpyxl module on my Dockerfile with the following com...
<python><pylint>
2024-11-29 09:28:23
0
519
xxestter
79,235,967
12,466,687
pdftotext in python not working missing dll probably
<p>I was able to use <code>pdftotext</code> earlier after a alot of challenges in installation few months back and at that time if I remember correctly I did downloaded some files and placed it some folder and did sudo commands for installation and modified content in Micros. Visual Studio.</p> <p>But recently I delete...
<python><pip><anaconda><streamlit><pdftotext>
2024-11-29 05:47:37
2
2,357
ViSa
79,235,770
248,616
Python how to set dict key as 01, 02, 03 ... when using dpath?
<p>Let's say we want to create/maintain a dict with below key structure</p> <pre><code>{ &quot;a&quot;: {&quot;bb&quot;: {&quot;01&quot;: &quot;some value 01&quot;, &quot;02&quot;: &quot;some value 02&quot;, } }, } </code></pre> <p>We use <a href="https://pypi.org/project/dpath/" rel="nofo...
<python><dictionary><dpath>
2024-11-29 03:32:07
3
35,736
Nam G VU
79,235,638
65,659
How can I use type hints to declare an instance method of a class accepts another class instance as a parameter?
<p>How can I write a class in Python that has a method with an argument that should be an instance of the class?</p> <pre><code>class MyClass: def compare(self, other: MyClass): pass </code></pre> <p>This gives me an error:</p> <pre><code>NameError: name 'MyClass' is not defined </code></pre>
<python><python-typing>
2024-11-29 01:30:14
1
4,968
Chuck
79,235,606
143,189
Mocking with fakeredis+python results in HTTP 500
<p>I have the following FastAPI module in python with the corresponding test, but am never able to get an HTTP 200 response from the await redis_service.set_key call I am making. Any suggestions on what I could be doing wrong?</p> <p>THIS IS THE EXISTING CODE (I CAN REFACTOR THIS, BUT NEED WORKING TESTS BEFORE ATTEMPTI...
<python><pytest><fakeredis>
2024-11-29 01:00:53
1
550
ossandcad
79,235,514
9,500,955
Cannot write data to BigQuery when using Databricks secret
<p>I am following this <a href="https://docs.databricks.com/en/connect/external-systems/bigquery.html#read-and-write-to-a-bigquery-table" rel="nofollow noreferrer">guide</a> on writing data to the BigQuery table.</p> <p>Right now, I have an error when I try to write data using <a href="https://docs.databricks.com/en/se...
<python><pyspark><google-bigquery><databricks>
2024-11-28 23:28:13
0
1,974
huy
79,235,334
3,994,399
unstructured cannot find images
<p>I am trying to use the unstructured library to convert a word document into a json file. However, for some reason it is not seeing the images; in the list of elements that are returned there should be elements of type &quot;Image&quot;. It is not throwing an error, it's just not returning the image elements. Below m...
<python><unstructured-data>
2024-11-28 21:28:41
1
692
ThaNoob
79,235,331
9,680,491
Can child processes create shared memory and share it with parent processes?
<p>Can a child process create a SharedMemory object and share it with a parent process? Currently I am getting errors when I try. I need this because creating and copying memory is the major performance bottleneck in my application, but I need to write the shared memory in the parent process.</p> <p>Here are three mini...
<python><multiprocessing><shared-memory>
2024-11-28 21:25:23
1
403
Autodidactyle
79,235,310
1,791,279
Efficient SQL query with pandas using databricks-sql-python
<p>Databricks allows to make SQL queries via an API using the <a href="https://github.com/databricks/databricks-sql-python" rel="nofollow noreferrer">databricks-sql-python</a> package.</p> <p>There are then two ways of creating a connection object that can be put into a <code>pd.read_sql_query(sql, con=connection)</cod...
<python><pandas><databricks><databricks-sql><python-db-api>
2024-11-28 21:07:52
2
11,269
rth
79,235,198
11,850,322
Pandas Merge - Elegant way to deal with filling and dropping columns
<p>Assume we have two data frames with columns as follows:</p> <pre><code>df1[['name', 'year', 'col1', 'col2', 'col3']] df2[['name', 'year', 'col2', 'col3', 'col4']] </code></pre> <p>I want to do the merge of df1 and df2 by <code>name</code> and <code>year</code> with the condition to keep all value of <code>col2</code...
<python><pandas>
2024-11-28 20:02:04
2
1,093
PTQuoc
79,235,140
2,357,712
Converting a nested json three levels deep to dataframe
<p>I have a json that is three levels deep. I want to flatten it into a dataframe that has five columns.</p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th>id</th> <th>name</th> <th>code</th> <th>level</th> <th>parent_id</th> </tr> </thead> </table></div> <p>So: The part I struggle with is that...
<python><json><pandas><dataframe>
2024-11-28 19:29:44
2
1,617
Maxcot
79,235,043
973,956
Python evaluation of expression
<p><strong>Python yields different answers</strong></p> <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt; 0 &lt; 0 == 0 False &gt;&gt;&gt; (0 &lt; 0) == 0 True &gt;&gt;&gt; 0 &lt; (0 == 0) True </code></pre> <p>is this a bug?</p> <pre class="lang-none prettyprint-override"><code>Python 3.11.10 (main, Sep...
<python><python-3.x><operator-precedence>
2024-11-28 18:46:43
1
1,524
MrJ
79,235,040
7,663,296
Rate limiting concurrent web queries to multiple domains, stdlib only
<h1>Question</h1> <p>How to manage rate limiting concurrent web queries to multiple domains using only python stdlib? Not asking about algorithms like leaky bucket or single-domain solutions, but how to approach data and code structures for concurrent queries to multiple domains.</p> <h2>Related</h2> <p>The following ...
<python><multithreading><concurrency><cross-domain><rate-limiting>
2024-11-28 18:45:17
2
383
Ed_
79,234,891
1,711,271
How to safely check whether a Fortran file exists when reading it with Python?
<p>I need to read in Python a file written in Fortran. To do this, I'm using <code>numpy</code>'s <code>f2py</code>. Basically, I write a <code>parse.f90</code> file:</p> <pre class="lang-none prettyprint-override"><code> subroutine read_params(filename, params) implicit none ! Argument Declarations ! ...
<python><io><fortran><f2py>
2024-11-28 17:42:57
1
5,726
DeltaIV
79,234,888
919,499
python/asyncio: how to get the exception handler "context"?
<p>I set up a custom exception handler for my asyncio loop.</p> <p>I know I can call <code>loop.call_exception_handler(context)</code> to use my custom exception handler to trace/log exception I catch in my code using an <code>except:</code> statement, but is there a way to get a <code>context</code> dict as complete a...
<python><loops><python-asyncio>
2024-11-28 17:42:26
0
500
MadeR
79,234,789
2,192,488
How to use aiohttp with apscheduler?
<p>I would like to fetch several web pages periodically all within the same <code>aiohttp.ClientSession()</code>. Here is what I have got so far. The URLs need to remain within the jobs, because some other URLs will need to be calculated.</p> <p>What command is missing in the place of <code>???</code>. Or do I need to ...
<python><python-asyncio><aiohttp><apscheduler>
2024-11-28 17:06:11
2
32,046
Serge Stroobandt
79,234,684
1,802,726
Python unittest.mock patch fail with F() expressions can only be used to update, not to insert
<p>A minimal working example is available at <a href="https://github.com/rgaiacs/django-mwe-magicmock" rel="nofollow noreferrer">https://github.com/rgaiacs/django-mwe-magicmock</a>.</p> <p>When using Django, I use <code>Model.clean()</code> to validate the form submitted by the user. During the validation, some fields ...
<python><django><python-unittest.mock>
2024-11-28 16:29:08
1
2,735
Raniere Silva
79,234,681
10,425,150
Update created engine in sqlacemy
<p>I've created database using the following code:</p> <pre><code>from sqlalchemy import create_engine, text db_user = 'postgres' db_password = 'chnageme' db_host = '12.123.123.123' db_port = '5432' db_name = 'new_db' # Create a connection string to connect to the PostgreSQL server connection_string = f'postgresql://{...
<python><postgresql><sqlalchemy><psycopg2>
2024-11-28 16:28:09
0
1,051
Gооd_Mаn
79,234,492
20,343,817
flattening pandas columns in a non-trivial way
<p>I have a pandas dataframe which looks like the following:</p> <pre><code> site pay delta over under phase a a b ID D01 London 12.3 10.3 -2.0 0.0 -2.0 D02 Bristol 7.3 13.2 5.9 5.9 0.0 D03 Bristol 17.3 19.2 1.9 1.9 0.0 </code></pre> <p>I'd like to fl...
<python><pandas><dataframe>
2024-11-28 15:25:55
2
325
Penelope
79,234,349
8,000,016
Error building and installing custom python package
<p>I'm trying to distribute my custom python package through GCP Artifact repository and use it in my project but got a dependent error.</p> <p>pyproject.toml:</p> <pre><code>... dependencies = [ &quot;pandas&gt;=2.2.3&quot;, &quot;numpy&gt;=1.26.4&quot;, &quot;sentence-transformers&gt;=3.0.1&quot;, &quot;sciki...
<python><pip><pyproject.toml>
2024-11-28 14:50:06
1
1,264
Alberto Sanmartin Martinez
79,234,345
18,904,265
Subscriber only receives first 2/3 of messages from publisher when using QoS1 or above for publishing
<p>I am testing a mosquitto server using two python programs. The mosquitto broker is a docker on a linux machine, the python programs are running on my windows machine. One is subscribed to the topic &quot;Test&quot; and constantly listening and will print all received messages to stdout + add them to a log file. The ...
<python><mqtt><mosquitto><paho>
2024-11-28 14:48:34
0
465
Jan
79,234,318
15,835,974
How to replace a value including the column in a structure
<p>When I use <a href="https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.replace.html" rel="nofollow noreferrer">DataFrame.replace</a>, it doesn't replace the values that are in a structure.</p> <p>In this example, it doesn't replace the value of <code>my_struct.struct_stri...
<python><pyspark>
2024-11-28 14:41:54
2
597
jeremie bergeron
79,234,157
1,743,124
Gradio Image() component to download image with random names
<p>I have 3 <code>gr.Image()</code> where they only have output when the LLM inference happen.</p> <pre><code>img1 = gr.Image( label=&quot;Generated Image&quot;, type=&quot;pil&quot;, format=&quot;png&quot;, interactive=False, show_share_button=False, elem_classes=&quot;generated-image&quot; ) <...
<python><huggingface><gradio><image-generation>
2024-11-28 13:48:13
0
4,792
Mayeenul Islam
79,234,004
5,406,294
Llama-3.2-1B-Instruct generate inconsistent output
<p>I want to use <code>Llama-3.2-1B-Instruct</code> model, and although I have set <code>&quot;temperature&quot;: 0.0, &quot;top_p&quot;:0.0 and &quot;top_k&quot;:0</code>, it still generates inconsistent output. This is how my pipeline looks like:</p> <pre><code>pipe = pipeline( &quot;text-generation&quot;, mo...
<python><nlp><huggingface-transformers><large-language-model>
2024-11-28 13:02:37
2
548
parvaneh shayegh
79,233,998
19,146,511
how can i fuse embeddings in a manner such that it increase efficiency and score?
<p>I've been working on a problem where the goal is to supplement traditional embeddings with LLM-generated embeddings (I'm using the last_hidden_state for this purpose). So far, I've tried simply concatenating them and using a cross-attention mechanism. While concatenating the embeddings yields similar results to usin...
<python><machine-learning><nlp><large-language-model><vehicle-routing>
2024-11-28 13:01:00
0
307
lazytux
79,233,997
1,091,116
AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno'
<p>I need to run a subprocess pipeline that uses zstandard files (too large to fit in memory) both as their input and output. Consider the following example:</p> <pre><code>import subprocess import zstandard with zstandard.open('a.txt.zst', 'w') as f: f.write('hello\n') f_in = zstandard.open('a.txt.zst', 'rb') f_...
<python><subprocess><zstd><zstandard>
2024-11-28 13:00:52
2
11,756
d33tah
79,233,913
2,886,640
Why does alternative DB cursor remain loading forever on commit?
<p>I have a problem when using the <code>l10n_es_aeat_sii_oca</code> module. After a while I could locate the problem, and it is in this peace of code:</p> <pre><code>try: ... except Exception as fault: new_cr = Registry(self.env.cr.dbname).cursor() env = api.Environment(new_cr, self.env.uid, self.env.conte...
<python><odoo><odoo-16>
2024-11-28 12:34:51
0
10,269
forvas
79,233,548
10,020,283
OSMnx throws exception when called on graph created from graph_from_gdfs
<p>I'm trying to simplify a graph after modifying the <code>gdf_edges</code> and recreating the graph from the dataframes. My workflow is as follows:</p> <pre><code>ox.graph_from_polygon =&gt; graph_to_gdfs =&gt; modify gdf_edges =&gt; ox.graph_from_gdfs =&gt; ox.simplify_graph </code></pre> <p>However, this throws a T...
<python><networkx><osmnx>
2024-11-28 10:55:23
1
6,792
mcsoini
79,233,459
7,825,830
opening a stylized Tkinter GUI from a Tkinter button click event doesn't apply the style
<p>I have two files in a single folder: <code>MainApp.py</code> and <code>SecondApp.py</code>.</p> <p>Both have <code>ttk.Style()</code> applied to specific controls. And when you launch them individually, the styles are implemented accordingly.</p> <hr /> <p><strong>MainApp:</strong></p> <p><a href="https://i.sstatic....
<python><tkinter>
2024-11-28 10:24:34
1
578
Nii
79,233,300
21,049,944
Generate multiple disjunct samples from a dataframe
<p>I am doing some statistic of a very large dataframe that takes sums of multiple random samples. I would like the samples to be disjuct (no number should be present in two different samples).</p> <p>Minimal example that might use some numbers multiple times:</p> <pre class="lang-py prettyprint-override"><code>import ...
<python><python-polars>
2024-11-28 09:39:37
1
388
Galedon
79,233,261
9,542,989
Datashare writes are not authorized by producer or associated by consumer
<p>I am trying to query a datashare from AWS Data Exchange using Redshift in Python. <a href="https://aws.amazon.com/marketplace/pp/prodview-iopazp7irqk6s" rel="nofollow noreferrer">This</a> datashare, to be precise.</p> <p>This is how I am attempting to run my Python code:</p> <pre><code>import os import psycopg os....
<python><amazon-redshift><aws-data-exchange>
2024-11-28 09:30:33
0
2,115
Minura Punchihewa
79,233,242
6,256,241
How to get relative frequencies from pandas groupby, with two grouping variables?
<p>Suppose my data look as follows:</p> <pre><code>import datetime import pandas as pd df = pd.DataFrame({'datetime': [datetime.datetime(2024, 11, 27, 0), datetime.datetime(2024, 11, 27, 1), datetime.datetime(2024, 11, 28, 0), datetime.datetime(2024, 11, 28, 1), datetime.datetime(2024, 11...
<python><pandas><datetime><group-by><line-plot>
2024-11-28 09:22:39
2
3,969
Qaswed
79,233,050
2,443,525
Django model has ManyToMany field, how to get all IDs without fetching the objects?
<p>I have a data structure like this:</p> <pre class="lang-none prettyprint-override"><code>class Pizza(models.Model): name = models.CharField(max_length=100) toppings = models.ManyToManyField(Topping, related_name=&quot;pizzas&quot;) class Topping(models.Model): name = models.CharField(max_length=100) </c...
<python><django><django-models>
2024-11-28 08:12:26
2
426
Lodewijck
79,233,046
3,973,269
Python ssl issue with azure cosmos db emulator in github actions
<p>I am trying to make unit tests for my azure functions, written in Python. I have a python file that does some setup (making the cosmos db databases and containers) and I do have a github actions yaml file to pull a docker container and then run the scripts.</p> <p><strong>The error:</strong> For some reason, I do ge...
<python><azure-functions><github-actions><azure-cosmosdb>
2024-11-28 08:10:46
1
569
Mart
79,232,831
6,212,530
How to use Django {% querystring %} with GET form?
<p>In Django 5.1 <a href="https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#querystring" rel="nofollow noreferrer">{% querystring %}</a> was added. Is there some way to use it with GET form?</p> <p>For example, let's say we have template with:</p> <pre class="lang-html prettyprint-override"><code>&lt;span&g...
<python><django>
2024-11-28 06:48:35
2
1,028
Matija Sirk
79,232,800
183,717
Trying to traverse a linked list in Python 3
<p>I have a weird issue being able to traverse through a custom linked list. Here is the code for traversal.</p> <pre><code>from typing import Optional class ListNode: def __init__(self, val, next_node=None): self.val = val self.next_node = next_node @property def value(self): re...
<python><linked-list>
2024-11-28 06:33:39
3
9,853
name_masked
79,232,737
2,515,265
Cannot submit chat request to VLLM Pixtral in Python using MistralAI
<p>I have a Pixtral server running locally.</p> <p>I have installed <code>mistralai 1.2.3</code> on MacOS and am trying to interact with the server.</p> <p>When I run</p> <pre><code>curl -X POST http://localhost:8000/v1/chat/completions \ -H &quot;Content-Type: application/json&quot; \ -d '{&quot;model&quot;:...
<python><large-language-model><vllm>
2024-11-28 06:00:30
1
2,657
Javide
79,232,728
3,685,918
optimizeWarning: Covariance of the parameters could not be estimated in python
<p>I am trying to obtain the optimized parameters from the Nelson-Siegel model. Below is a simple example, but I know the optimized parameters are not fully optimized and contain some errors/warnings.</p> <p>I believe the warning message is related to the optimized parameters. Please tell me how to fix it.</p> <pre><co...
<python><optimization>
2024-11-28 05:49:56
0
427
user3685918
79,232,565
8,554,833
App Registration error AADSTS500011 show tenant is as domain instead of long string provided
<p>I've tried numerous times to register an app and connect to in in python:</p> <pre><code>app_id = '670...' tenant_id = '065...' client_secret_value = 'YJr...' import requests import msal authority = f'https://login.microsoftonline.com/{tenant_id}' scopes = ['https://analysis.microsoft.net/powerbi/api/.default'] a...
<python><azure><powerbi-embedded><azure-app-configuration>
2024-11-28 04:10:59
1
728
David 54321
79,232,303
491,637
Seaborn heatmap with extra row and extra column
<p>I made a seaborn heatmap and I would like to add an extra row and column like image. They must be independent, I will fill each one with its own data.</p> <p><a href="https://i.sstatic.net/eAVozS4v.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eAVozS4v.jpg" alt="heatmap with extra column and row" />...
<python><matplotlib><seaborn><heatmap>
2024-11-28 00:56:59
0
2,077
walves
79,232,261
259,485
How to use Google Cloud ADC to access Google Drive API from Python with personal account (not service account)
<p>Lets say you need to run a script locally that needs to connect to google workspace resources like drive and sheets. How do you do this from Python leveraging Google Application Default Credentials?</p>
<python><google-sheets><google-drive-api>
2024-11-28 00:26:27
2
8,714
Kristofer
79,232,116
345,716
What is the intended/best-practice PYTHONPATH workflow for developing a python module with a venv?
<p>I'm a relative python newbie and find myself going back and forth on how to set the <code>sys.path</code> &quot;nicely&quot; while developing my module with a <code>venv</code>, and thought I'd ask if/what the best-practice way is to make</p> <pre><code>python3 -m my_module.src1 args </code></pre> <p>use the files ...
<python>
2024-11-27 22:59:03
1
16,339
Peter V. Mørch
79,232,088
4,180,670
Flask error related with SERVER_NAME after upgrading to Flask 3.1.0
<p>My application uses subdomains (every logged user has his own: user.domain.com) and Blueprints with no subdomains.</p> <p>Till now I didn't set <em>subdomain_matching</em> and I set SERVER_NAME = &quot;domain.com&quot; and SESSION_COOKIE_DOMAIN = &quot;.domain.com&quot;.</p> <p>After upgrading to Flask 3.1.0 from 3....
<python><flask>
2024-11-27 22:43:24
1
463
Marco Evasi
79,231,900
2,142,994
Parse JSON in scala and do get with default value
<p>Sample JSON read from file:</p> <pre><code>{ &quot;category&quot;: &quot;[{\&quot;a\&quot;:3,\&quot;b\&quot;:11,\&quot;c\&quot;:86}]&quot;, &quot;ids&quot;: &quot;[\&quot;1234\&quot;, \&quot;5678\&quot;]&quot;, &quot;uid&quot;: &quot;55555&quot;, &quot;flag&quot;: true } </code></pre> <p>Current Code:</p> <p...
<python><json><scala><jackson>
2024-11-27 21:13:23
1
28,435
Ani Menon
79,231,895
12,932,447
How to get updated values in NiceGUI
<p>I'm writing a NiceGUI frontend for my Python code. This is my first time writing frontend, and I'm not very used to web-framework concepts.</p> <p>Essentially, the use of this frontend is to ask to user to insert the following variables (I know <code>range</code> is not a good variable name):</p> <pre class="lang-py...
<python><nicegui>
2024-11-27 21:10:41
1
875
ychiucco
79,231,883
9,251,158
Frozen OS error when walking the file tree of an external drive
<p>I want to normalize filepaths (removing accents) in an external drive and I use <code>os.walk()</code>. At one point, the script freezes and after I cancel, I see this message:</p> <pre><code>^CTraceback (most recent call last): File &quot;~/normalize_filepaths.py&quot;, line 2 for root, dirs, files in os.walk...
<python><operating-system><runtime-error>
2024-11-27 21:06:37
1
4,642
ginjaemocoes
79,231,864
1,958,900
`typing.get_origin` vs. `TypeAlias.__origin__`
<p>Python's docs define <a href="https://docs.python.org/3/library/stdtypes.html#genericalias.__origin__" rel="nofollow noreferrer"><code>GenericAlias.__origin__</code> as:</a></p> <blockquote> <p>This attribute points at the non-parameterized generic class <code>list[int].__origin__ # returns list</code></p> </blockq...
<python><python-typing>
2024-11-27 20:55:35
1
7,145
Aaron
79,231,789
5,965,685
Python json.dump scientific notation formatting
<p>Due to suspected platform differences between developers, <code>json.dump</code> is formatting scientific notations in different ways (one person's machine, it formats to <code>1e-6</code>, and on others it formats to <code>1e-06</code>). The files are committed to our git history, so having to constantly revert the...
<python><json><format><dump>
2024-11-27 20:28:59
2
431
mitchute
79,231,554
1,079,075
Pydantic nestled list type with sub-list minimum length
<p>I want to create a Pydantic class wrapping a list with string sub-lists that have to be at least of length two.</p> <p>For example, the following are valid:</p> <ul> <li><code>[]</code> empty list with no sublists is valid</li> <li><code>[[&quot;a&quot;, &quot;b&quot;], [&quot;c&quot;, &quot;d&quot;, &quot;e&quot;]<...
<python><pydantic>
2024-11-27 18:54:25
2
9,446
Seanny123
79,231,473
7,995,293
Can Polars with calamine engine be coerced into failing more gracefully?
<p>I have 10s of thousands of excel files to which I'm applying validation using Polars. Some excel files have a problem that spawns an <code>index out of bounds</code> panic in the py03 runtime, when using <code>engine=calamine</code>. This issue does not occur when using <code>engine=xlsx2csv</code>. The excel proble...
<python><exception><python-polars><pyo3>
2024-11-27 18:26:03
1
399
skytwosea
79,231,405
4,119,822
No enum for numpy uintp?
<p>I am trying to wrap a C pointer array of type <code>size_t</code> with a numpy <code>ndarray</code> via Cython using the following:</p> <pre class="lang-none prettyprint-override"><code>cimport numpy as cnp from libcpp.vector cimport vector cnp.import_array() cdef size_t num_layers = 10 cdef vector[size_t] steps_ta...
<python><numpy><cython>
2024-11-27 18:01:49
1
329
Oniow
79,231,381
2,800,329
Convert JSON to set of nested Python classes
<p>I need to process multiple messages in JSON format. Each message has its own nested structure. I would like to create a Python SDK to process these messages. My idea is to map each JSON structure into a set of nested Python classes. Currently, I'm doing it manually. But it is a tedious task.</p> <p>Please find an ex...
<python><json><dictionary><class>
2024-11-27 17:51:57
2
1,053
mabalenk
79,231,179
405,017
Determining base class signatures for subclasses of a Pydantic BaseModel
<p><strong>TL;DR</strong>: Is there a way to:</p> <ul> <li>have a custom initializer on a sub-subclass of a <code>pydantic.BaseModel</code>,</li> <li>that shows a full and complete signature in Pylance,</li> <li><em>without</em> manually copying all the field names into every subclass constructor?</li> </ul> <h3>Simpli...
<python><python-typing><pydantic><pyright>
2024-11-27 16:47:26
1
304,256
Phrogz
79,231,172
662,345
`python -m build` can't find numpy include files when running in cibuildwheel
<p>I'm building a python module that contains a cython file which uses numpy. In some environments <code>python -m build</code> works as is; in other environments I need to set <code>C_INCLUDE_PATH=`python -c &quot;import numpy; print(numpy.get_include())&quot;` </code> beforehand.</p> <p>But when I type <code>cibuildw...
<python><numpy><pip><cython><setuptools>
2024-11-27 16:45:09
1
7,039
Antonis Christofides