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
78,587,828
7,201,487
Possibility to factorize configuration for multiple project
<p>I have the following use case. I am working on a large project with multiple subtasks. For example, we are performing classification on some datasets, segmentation on others, and translation on yet another set of datasets (see below).</p> <p>Each task has its own configuration. However, there is a part of the config...
<python><fb-hydra>
2024-06-06 16:00:08
1
559
schlodinger
78,587,778
9,544,507
How to disable autocomit with ibm db2 for i in SqlAlchemy
<p>How do i turn off autocommit with ibm_db_sa and sqlalchemy?</p> <p>If the table has journaling on, this is not required, but this one table does not have journaling on, as such, autocommit must be OFF.</p> <p>I have tried:</p> <pre class="lang-py prettyprint-override"><code>smt = f&quot;db2+ibm_db://{user}:{password...
<python><sqlalchemy><db2><db2-400>
2024-06-06 15:50:31
1
333
Wolfeius
78,587,761
4,146,344
Open a new window when clicking on a mesh in Open3D
<p>Below is an example in Open3D, in which I created a bunny mesh, as well as a circle mesh. Now I want to create a new window and show an image when I click on the circle mesh. Does anyone know how to do that ? Thank you very much.</p> <pre><code>import numpy as np import open3d as o3d def main(): mesh = o3d.io.r...
<python><point-clouds><open3d>
2024-06-06 15:48:05
1
710
Dang Manh Truong
78,587,587
9,100,431
Send error messages to catch with subprocess.check_output()
<p>I'm writing a web app (app.py) that when calling an API, runs a python script (main.py).</p> <p>I'm interested in two things:</p> <ul> <li>Printing/logging the logs of main.py in real time to the console</li> <li>Obtaining 'custom' error messages from main.py</li> </ul> <p>Right now, I do the first point, and try to...
<python><error-handling><subprocess>
2024-06-06 15:15:18
1
660
Diego
78,587,486
14,282,714
Upgrade streamlit with Conda doesn't work
<p>I'm trying to upgrade my streamlit version from 1.12.2 to its latest version. I followed the documentation like described <a href="https://docs.streamlit.io/knowledge-base/using-streamlit/how-upgrade-latest-version-streamlit" rel="nofollow noreferrer">here</a>. First I activate my conda environment:</p> <pre><code>c...
<python><streamlit>
2024-06-06 14:59:29
0
42,724
Quinten
78,587,280
263,844
python3.9 how to find a compatible Spacy version
<p>I need to re-deploy an existing very old python GCP Cloud Function that uses Spacy and other NLP stuff (that I am not familiar with) - to use a newer python runtime (3.9 or above) .</p> <p>Sparing the details of an insane dependencies version conflicts chasing and adjustments ... I came to the need to upgrade versi...
<python><google-cloud-platform><google-cloud-functions><spacy>
2024-06-06 14:23:19
1
4,074
Marina
78,587,066
14,824,108
plt.subplots() with gridspec in matplotlib
<p>Given that I plot the following:</p> <pre><code>real = results['real'] pred = results['pred'] # Create the subplots with specified grid ratios fig_sub, axs_sub = plt.subplots(2, 2, figsize=(8, 6), gridspec_kw={'hspace': 0, 'wspace': 0, ...
<python><matplotlib>
2024-06-06 13:47:23
1
676
James Arten
78,586,938
9,360,663
SQLAlchemy create_all() doesn't create tables
<p>I'm trying to create a set of tables using SQLAlchemy 2.0</p> <pre class="lang-py prettyprint-override"><code>import logging import logging.handlers logging.basicConfig( level=logging.INFO, format='%(asctime)s [%(name)-5s] [%(levelname)-3s] %(message)s' ) from typing import List, Dict # from DAL.database i...
<python><postgresql><sqlalchemy>
2024-06-06 13:28:59
1
1,154
po.pe
78,586,918
4,900,991
Multiprocessing with multiple class objects
<p>I have different python classes and all of them having a method called push. What I am trying to is</p> <ol> <li>Create multiple class objects one from each class</li> <li>Call push method</li> <li>All these methods should execute in parallel</li> <li>Log messages coming from push method as and when its complete</li...
<python><multiprocessing>
2024-06-06 13:24:54
2
1,943
Sandeep Lade
78,586,815
1,022,260
Bind Model schema similar to binding Model database
<p>How can I dynamically bind a schema, similar to binding a model:</p> <pre><code>db = PooledPostgresqlExtDatabase( cfg_db, max_connections=8, stale_timeout=300, user=cfg_user, password=cfg_password, host=cfg_host, port=cfg_port ) db.bind([BaseModel]) # How do I set the schema for base model here?? <...
<python><peewee>
2024-06-06 13:08:29
1
11,513
mikeb
78,586,783
5,433,628
How to use `pycountry.db.Country` objects as a `pd.DataFrame` index?
<p>I am creating a dataset collecting data for a given set of countries. To avoid any ambiguity, I would like to use a <a href="https://pypi.org/project/pycountry/" rel="nofollow noreferrer"><code>pycountry.db.Country</code> object</a> to represent each country.</p> <p>However, when setting the country as the index of ...
<python><pandas><dataframe><indexing><country-codes>
2024-06-06 13:03:36
3
1,487
ebosi
78,586,719
3,070,181
Tkinter validation triggers an unexpected function causing application to hang
<p>I have a tkinter app. On load the focus is set to the first entry widget (self.entry_a). When I tab out of the entry (self.entry_a) for the first time it triggers the validation for the second entry (self.entry_b). This means that if I return <em>False</em> from the function <em>validate_b</em>, the application hang...
<python><validation><tkinter>
2024-06-06 12:54:43
1
3,841
Psionman
78,586,671
27,912
Using Luigi for a small POC to run process which do not create files, and it doesn't seem to work
<p>I want to execute <em>MyTask1</em> and <strong>then</strong> <em>MyTask2</em>. Only <em>MyTask1</em> executes. Luigi reports that I have an <code>Unfulfilled dependency</code>. However, it prints...</p> <pre><code>==================== MyTask1: 5 ==================== </code></pre> <p>so I know that <em>MyTask1</em...
<python><workflow><luigi>
2024-06-06 12:44:55
1
905
Jason V
78,586,632
14,824,108
Imposing KDE plots on top of a scatter plot
<p>I have a parity plot deriving from Machine Learning model predictions vs actual values. I would like to create some density plots to be shown on top and right corners of the main figure. The effect that I would like to achieve can be seen here (<a href="https://www.microsoft.com/en-us/research/blog/mattergen-propert...
<python><matplotlib>
2024-06-06 12:39:04
0
676
James Arten
78,586,621
3,306,091
HuggingFace pipeline - Debug prompt
<p>I've defined a pipeline using Huggingface transformer library.</p> <pre><code>pipe = pipeline( &quot;text-generation&quot;, model=myllm, tokenizer=tokenizer, max_new_tokens=512, ) </code></pre> <p>I'd like to test it:</p> <pre><code>result = pipe(&quot;Some input prompt for the LLM&quot;) </code></pr...
<python><nlp><huggingface-transformers>
2024-06-06 12:36:47
1
1,204
MarcoM
78,586,599
857,390
Annotate factory method in parent class that returns instances of subclasses
<p>I'm trying to add type annotations to a factory method in a parent class that returns instances of subclasses:</p> <pre class="lang-py prettyprint-override"><code>class Parent: @classmethod def make(cls, param: int): if param &gt; 0: return ChildA() else: return ChildB...
<python><python-typing>
2024-06-06 12:32:47
1
10,575
Florian Brucker
78,586,529
7,729,563
How to run ptpython on Windows 11 in asyncio mode
<p>I have Windows 11 and Python 3.12.3 and wish to experiment with the asyncio REPL. It works fine with the built-in REPL:</p> <pre class="lang-py prettyprint-override"><code>PS C:\&gt; python -m asyncio asyncio REPL 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32 Use &quot;aw...
<python><python-3.x><python-asyncio><ptpython>
2024-06-06 12:20:24
0
529
James S.
78,586,501
312,444
Building a "real-time" outbox pattern on Python / SQLALchemy
<p>I have create a outbox messages in my FastAPI/SQLAlchemy/Postgres application. The application is hosted in GCP. Now I need to publish this events, &quot;reading&quot; from the outbox table. I need to have this events to be published in real time. What are the options that i have?</p> <ol> <li>A Cron that will read ...
<python><postgresql><google-cloud-platform><outbox-pattern>
2024-06-06 12:16:48
0
8,446
p.magalhaes
78,586,497
6,941,400
Getting openai.BadRequestError: Error code: 400: 'Extra inputs are not permitted' with an LLM model hosted on an on-prem GPU
<p>I am not really able to find that much on this. Here's some discussion on <a href="https://github.com/langchain-ai/langgraph/discussions/187" rel="nofollow noreferrer">Github</a>. I was following this <a href="https://github.com/anurag899/openAI-project/blob/main/Multi-Agent%20Coding%20Framework%20using%20LangGraph/...
<python><langchain><langgraph><mixtral-8x7b>
2024-06-06 12:16:02
0
576
Anshuman Kumar
78,586,256
3,015,186
How to force DuckDB to reconnect to a file and prevent it from remembering contents of a deleted database file?
<h3>Motivation</h3> <p>I'm working on a larger dashboard application which uses duckdb. I found out a bug which in a nutshell is like this:</p> <pre class="lang-py prettyprint-override"><code># create new connection con = duckdb.connect('/somedir/duckdb.db') # do something # remove or replace the file Path('/somedir/...
<python><duckdb>
2024-06-06 11:26:22
2
35,267
Niko Fohr
78,586,213
1,169,096
have top-level parser and subparsers act on the same variable
<p>i have an <code>ArgumentParser</code> with sub-parsers. Some flags are common for all sub-parsers, and I would like to be able to specify them <em>either</em> before or after the sub-command, or even mix before and after (at the user's discretion).</p> <p>Something like this:</p> <pre class="lang-bash prettyprint-ov...
<python><argparse><subparsers>
2024-06-06 11:15:27
3
32,070
umläute
78,586,140
7,626,198
QUARTO does not find python
<p>I am using quarto in vscode. When I run <code>quarto check</code>, the output is:</p> <pre><code>Unable to locate an installed version of Python 3. Install Python 3 from https://www.python.org/downloads/ </code></pre> <p>However, when I open any *.py vscode detects my python. I installed python from windows store. P...
<python><visual-studio-code><quarto>
2024-06-06 11:00:29
4
442
Juan
78,585,952
9,671,120
pytest equivalent of unittest.main()
<p>I can run in debug mode a unit test <code>test_foo.py</code> by simplying pressing F5 in my IDE of choice:</p> <pre class="lang-py prettyprint-override"><code># test_foo_module.py import unittest class TestFoo(unittest.TestCase): def test_foo(self): self.assertTrue(True) if __name__ == '__main__': ...
<python><unit-testing><pytest>
2024-06-06 10:20:41
2
386
C. Claudio
78,585,814
3,488,901
How to catch if-then (and optional else) block from rsyslog config file?
<p>I'd like to catch the following conditional blocks from rsyslog conf file:</p> <pre><code>if (($fromhost-ip == '127.0.0.1') and ($syslogfacility-text == &quot;local7&quot;)) then { if (re_match($msg, &quot;^[ ]*[A-Z0-9]{4}\\|[^|]+\\|&quot;)) then { action(type=&quot;omfile&quot; DynaFile=&quo...
<python><regex><syntax><rsyslog>
2024-06-06 09:55:15
1
417
ibt23sec5
78,585,754
19,392,385
Tight subplot axes without their plot to the figure
<p>I have made a subplot in matplotlib and managed to to put the different cmap I have on the same column. For a minimal working example (with dummy cmaps):</p> <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt import numpy as np # Generate sample data data1 = np.random.rand(10, 10) data2...
<python><matplotlib><subplot>
2024-06-06 09:42:12
2
359
Chris Ze Third
78,585,559
3,813,424
Python issue with importing from submodule including scripts that also import from submodule?
<p>My Python project has the following file structure.</p> <pre><code>module/ ├── __init__.py ├── main.py │ └── sub_module/ ├── __init__.py ├── foo1.py └── foo2.py </code></pre> <p>My goal is to import a class <code>Bar</code> from <strong>foo1.py</strong> in <strong>main.py</strong>:</p> <pre class="lang-p...
<python><python-3.x><python-import><python-module>
2024-06-06 09:05:14
2
319
St4rb0y
78,585,454
1,841,839
Create Image from bytes results in ValueError: not enough image data
<p>I am downloading images from an offline system (Google Photos) I can download the files and save them locally that works fine.</p> <p>However what i am trying to do is download them and turn them into a PIL Image so that i can use them and not have to store them locally first.</p> <h1>Works fine to save a file</h1>...
<python><python-imaging-library>
2024-06-06 08:43:51
1
118,263
Linda Lawton - DaImTo
78,585,241
12,694,438
conda install python UnsatisfiableError
<p>I'm trying to update my python version with this command:</p> <pre><code>conda install python=3.12.0 </code></pre> <p>But I get an insanely long UnsatisfiableError message. <strong>I've read another <a href="https://stackoverflow.com/questions/42075581/conda-install-python-3-6-unsatisfiableerror">question</a> regard...
<python><conda>
2024-06-06 08:05:03
0
944
splaytreez
78,585,018
3,133,018
Programatically pass primary_key in SQLAlchemy PostgreSQL insert_on_conflict_nothing method
<p>I'm trying to insert several Pandas DataFrames to corresponding PostgreSQL tables, each with a different Primary Key. I've attempted to implement the following <code>method</code> according to the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html#r689dfd12abe5-1" rel="n...
<python><pandas><postgresql><sqlalchemy>
2024-06-06 07:20:33
1
496
zkvvoob
78,584,901
1,559,331
Create dataframe from Nested JSON
<p>I have the below json</p> <pre><code>[{&quot;Name&quot;:&quot;Tom&quot;,&quot;Age&quot;:&quot;40&quot;,&quot;Account&quot;:&quot;savings&quot;,&quot;address&quot;: { &quot;city&quot;: &quot;New York&quot;, &quot;state&quot;: &quot;NY&quot; }}] </code></pre> <p>Now I need to create dat...
<python><json><apache-spark><pyspark>
2024-06-06 06:53:50
1
932
dileepVikram
78,584,847
2,210,825
Convert count row to one hot encoding efficiently
<p>I have a table with rows in this format where the integers are a count:</p> <pre><code> A B C D E 0 a 2 0 3 x 1 b 1 2 0 y </code></pre> <p>I'd like to convert it into a format where each count is a one hot encoded row:</p> <pre><code> A B C D E 0 a 1 0 0 x 1 a 1 0 0 x 2 a 0 0 1 x...
<python><pandas><vectorization><one-hot-encoding>
2024-06-06 06:42:24
5
1,458
donkey
78,584,531
17,778,275
OpenCV code fail to detect overlapping rectangles in an image
<p>I am using OpenCV to detect rectangles in an image based on their color. The code works well for non-overlapping rectangles, but it fails to detect overlapping rectangles. Here's code I am using</p> <pre><code>image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) lower_blue = np.array([110, 50, 50]) upper_blue = np...
<python><opencv><computer-vision><contour>
2024-06-06 04:44:40
1
354
spd
78,584,279
7,267,480
Correct Visualization of data using np.meshgrid and ax.pcolormesh of matplotlib, error in visualization
<p>Trying to make a visualization to understand the <a href="https://en.wikipedia.org/wiki/Time_of_flight" rel="nofollow noreferrer">time-of-flight experiment</a></p> <p>The Idea is simple provided 2 values for energy - calculate corresponding time of flight values and energies and visualize it on the xy plot where col...
<python><matplotlib><meshgrid>
2024-06-06 02:49:43
1
496
twistfire
78,584,169
4,594,924
QT designer Layout margins are not editable
<p>I have UI file generated in QT designer 6.5.1 using python 3.9. This was pushed into git. Now I have downloaded in new machine where I have installed python 3.12.3 with QT designer 6.7.1. Like to fix if there is any gap on newer version and make code cleaner.</p> <p>Now I found that I could not edit any frame layout...
<python><qt><qt-designer><designer><python-3.12>
2024-06-06 01:57:39
1
798
Simbu
78,584,128
11,901,732
How to set max row height in pandas
<p>One column in my pandas dataframe is too long. How can I set max row height (<strong>not number of rows in a dataframe</strong>) in pandas so that I can truncate the cells with too much content and have a balanced view of all columns?</p> <p>Not asking for</p> <pre><code>pd.set_option('display.height', 500) pd.set_o...
<python><pandas><numpy>
2024-06-06 01:35:45
1
5,315
nilsinelabore
78,584,114
10,755,628
Best way to stream using langchain `llm.with_structured_output`
<pre><code>import asyncio from langchain_core.pydantic_v1 import BaseModel, Field from langchain_openai import ChatOpenAI class Joke(BaseModel): setup: str = Field(description=&quot;The setup of the joke&quot;) punchline: str = Field(description=&quot;The punchline to the joke&quot;) # Define the model with s...
<python><artificial-intelligence><langchain><langgraph>
2024-06-06 01:25:50
2
3,387
minglyu
78,584,084
3,369,879
Numpy type overloading
<p>I'd like to add typehints to a function that accepts either <code>np.float32</code> arrays or <code>np.float64</code> arrays and returns the same type:</p> <pre class="lang-py prettyprint-override"><code>from typing import overload, Union import numpy as np import numpy.typing as npt NPArray_FLOAT32 = npt.NDArray[...
<python><numpy><mypy><python-typing>
2024-06-06 01:10:13
1
2,015
Alex Kaszynski
78,584,058
18,149
In Python colorsys is there a way to convert hlsa_to_rgb?
<p>I am looking at colors pulled from the background color cells of an excel spreadsheet using Python.</p> <p>Oddly, what I pull from the fill color in RGB does not match what I am getting in the excel spreadsheet in python for the color.</p> <p>It leads me to believe that excel is using hlsa as it's storage format; be...
<python><excel><colors><webcolors>
2024-06-06 00:55:45
0
26,592
leeand00
78,584,013
20,591,261
How to chain multiple with_columns in Polars?
<p>I'm using Polars to transform my DataFrame, and I want to chain multiple <code>with_columns</code> transformations. However, I encounter an issue when trying to perform operations on a newly created column within the same <code>with_columns</code> context. I end up needing to save the DataFrame after each transforma...
<python><dataframe><python-polars>
2024-06-06 00:25:42
2
1,195
Simon
78,583,922
6,144,940
module 'matplotlib' has no attribute 'colormaps'
<p>I am using package <code>WindroseAxes</code>, whose function <code>.bar</code> has a parametere <code>cmap</code> for defining the color map. See <a href="https://windrose.readthedocs.io/en/latest/api.html?highlight=bar#windrose.WindroseAxes.bar" rel="nofollow noreferrer">https://windrose.readthedocs.io/en/latest/a...
<python><matplotlib><windrose>
2024-06-05 23:37:05
1
473
Justin
78,583,862
850,781
How do I make Tkinter not block Jupyter like Matplotlib does?
<p>I have <a href="https://matplotlib.org/" rel="nofollow noreferrer"><code>matplotlib</code></a>-based GUI app which takes inputs and plots graphs. It works just fine except that the UI is abysmally non-responsive (seconds before it reacts to mouse clicks or keyboard, on a fairly powerful windows box). I start it from...
<python><matplotlib><tkinter>
2024-06-05 23:08:57
0
60,468
sds
78,583,831
15,524,510
What is the format / notation / units of price and liquidity data for tick entity in uniswap API?
<p>I am pulling liquidity pool data from the uniswap API and I don't recognize the format or notation of the numbers that are being generated. Here is the code for ETH/USDT on uniswap v3:</p> <pre><code>import requests query = &quot;&quot;&quot; { pool(id: &quot;0x11b815efb8f581194ae79006d24e0d814b7697f6&quot;) { ...
<python><uniswap>
2024-06-05 22:54:57
1
363
helloimgeorgia
78,583,808
7,321,700
Sum Pandas Dataframe rows based on multiple conditions
<p><strong>Scenario:</strong> I have a dataframe in which I want to sum rows inside a column, based on values of others columns.</p> <p><strong>DF Example:</strong></p> <pre><code>+----------+----------------------------+---------------------+---------+ | SCENARIO | PRODUCT | FLOW | 2...
<python><pandas><dataframe>
2024-06-05 22:42:38
1
1,711
DGMS89
78,583,755
365,102
PyTorch F.interpolate for many dimensions (e.g. 4D, 5D, 6D, 7D, ..., n-D)
<p>I want to apply N-d interpolation to an (N+2)-d tensor for N&gt;3.</p> <pre class="lang-py prettyprint-override"><code>import torch import torch.nn.functional as F x = torch.randn(1, 1, 2, 3, 4, 5, 6, 7) output_size = (7, 6, 5, 4, 3, 2) y = F.interpolate(x, size=output_size, mode=&quot;linear&quot;) </code></pre> <...
<python><pytorch><interpolation>
2024-06-05 22:24:19
1
27,757
Mateen Ulhaq
78,583,338
11,117,255
Celery Task Logs Not Showing Up in Google Cloud Logging
<p>I'm trying to set up Google Cloud Logging for my Celery tasks, but I'm having trouble getting the logs to appear in Google Cloud Logging. I've added the logger configuration to my script, but the logs still do not go up. Below is my setup:</p> <h4>Logger Configuration:</h4> <pre class="lang-py prettyprint-override">...
<python><logging><google-bigquery>
2024-06-05 20:23:03
0
2,759
Cauder
78,583,009
1,609,514
TypeError: unhashable type: 'ArrayImpl' when trying to use Equinox module with jax.lax.scan
<p>I'm new to Equinox and JAX but wanted to use them to simulate a dynamical system.</p> <p>But when I pass my system model as an Equinox module to <a href="https://jax.readthedocs.io/en/latest/_autosummary/jax.lax.scan.html" rel="nofollow noreferrer">jax.lax.scan</a> I get the unhashable type error in the title. I un...
<python><jax><equinox><computation-graph>
2024-06-05 18:59:08
1
11,755
Bill
78,582,986
2,535,316
ydata_profiling not working with Python 3.9
<p>I have a Jupyter notebook. Why would this snippet work when the Python kernel is 3.8.12 but not when I use 3.9.19?</p> <p><code>import pandas as pd</code></p> <p><code>from ydata_profiling import ProfileReport</code></p> <p>On 3.9.19, the error is:</p> <p>ModuleNotFoundError: No module named 'ydata_profiling'</p> <...
<python><pandas><pandas-profiling>
2024-06-05 18:52:24
0
705
Stewart Wiseman
78,582,925
6,546,694
A weird issue (to me) with converting the dict values to a list in python (debugger)
<p>I am not sure I can explain the issue better than a screenshot. Either I am severely underslept or I have lost it (or, both)</p> <p><a href="https://i.sstatic.net/nuSTE73P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nuSTE73P.png" alt="enter image description here" /></a></p> <p>chunks is a list of...
<python><list><pdb>
2024-06-05 18:38:04
1
5,871
figs_and_nuts
78,582,914
6,509,519
Custom package install leads to subprocess.CalledProcessError -> No module named pip
<h1>Important(?) Details</h1> <ul> <li>Windows 10, version 10.0.19045</li> <li>Python 3.12.2</li> <li>PyCharm 2024.1 (Professional Edition)</li> <li>GitBash 2.45.1.windows.1</li> </ul> <h1>The Setup</h1> <p>I'm trying to install <code>pygraphviz</code> with my package in a virtual environment.</p> <p>I've written a cus...
<python><pip><subprocess><setuptools><python-venv>
2024-06-05 18:36:46
1
3,325
Ian Thompson
78,582,693
4,399,016
Clustering using Python
<p>I have data that resembles this:</p> <pre><code>import pandas as pd import random random.seed(901) rand_list1= [] rand_list2= [] rand_list3= [] rand_list4= [] rand_list5= [] for i in range(20): x = random.randint(80,1000) rand_list1.append(x/100) y1 = random.randint(-200,200) rand_list2.append(...
<python><pandas><cluster-analysis><k-means>
2024-06-05 17:38:14
2
680
prashanth manohar
78,582,566
1,841,839
Get batch predictions for Gemini - Vertex AI returns unsupported
<p>I have been chasing my tail all day trying to get <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/batch-prediction-gemini" rel="nofollow noreferrer">Get batch predictions for Gemini</a> to work.</p> <p>I have been digging around in all the samples and documentation that i can find and have ...
<python><google-bigquery><google-cloud-vertex-ai><google-gemini>
2024-06-05 17:13:10
1
118,263
Linda Lawton - DaImTo
78,582,471
9,042,093
How to add default pickle type value in sqlalchemy in python
<p>I have defined the pickle type column like below and create a table called test.</p> <p>My intension is to add pickle data to the column and commit it.</p> <p>Also if there is no value I want to add default pickle value (may be empty list or empty dict) to be added to the column.</p> <p>If I try to execute below cod...
<python><sqlalchemy>
2024-06-05 16:53:11
2
349
bad_coder9042093
78,582,415
1,022,260
How to access tags for current route from Middleware
<p>Using FastAPI, I have a route like this:</p> <pre class="lang-py prettyprint-override"><code>@app.get(&quot;/apps&quot;, tags=['bearer']) async def apps(): return get_apps() </code></pre> <p>I have middleware, and need to get a list of tags for the current route in the middleware.</p> <p>How do I do that?</p> <p...
<python><fastapi>
2024-06-05 16:37:53
0
11,513
mikeb
78,582,392
11,951,910
Is there a function or argument to remove quotes when writing to csv file in python
<p>I am appending a large amount of data and writing to a csv file.</p> <p>Data is a list that is appended to an example: <code>data = ['438.0337145,438.0178423,0.0158\n', '438.0497017,438.0337145,0.01598\n']</code></p> <pre><code>with open(uuidCSV, 'w') as csvFile: wr = csv.writer(csvFile, lineterminator=&quot;\n&...
<python><csvwriter>
2024-06-05 16:32:28
2
718
newdeveloper
78,582,282
2,123,706
apostrophe-like character appears in DataFrame as 'â\x80\x99'
<p>I am reading from SQL using sqlalchemy</p> <pre><code>q = &quot;&quot;&quot;select * from table_name&quot;&quot;&quot; data = pd.read_sql_query(q,con) </code></pre> <p>It appears ok when I view the results on screen</p> <p><a href="https://i.sstatic.net/MBPDhHSp.png" rel="nofollow noreferrer"><img src="https://i.sst...
<python><sql-server><pandas><sqlalchemy><pyodbc>
2024-06-05 16:09:43
2
3,810
frank
78,582,268
6,691,780
building pybind11 package that wraps .so file with Rye and setuptools
<p>I try to build a python package that wraps C++ code. I use pybind11 to create the necessary bindings. I manage the project using <a href="https://rye.astral.sh/" rel="nofollow noreferrer">Rye</a> with setuptools instead of the default hatchlings as build system (because the pybind11 docs use setuptools).</p> <p>I ha...
<python><c++><linux><setuptools><pybind11>
2024-06-05 16:07:01
0
1,529
Jonas
78,582,226
2,153,235
Avoid full cross-join in testing each record against every other record
<p>The <code>merge</code> in pandas has a cross-join function. I was hoping to avoid a full cross-join in pairing each record of a large dataframe with upto (say) a dozen records in another dataframe (possibly the same dataframe) based on complex criteria involving a function of multiple fields, i.e., not necessarily ...
<python><pandas>
2024-06-05 15:58:56
1
1,265
user2153235
78,582,174
719,276
How to wait until multiprocessing.connection.Client is available in python?
<p>I have a <code>process.py</code> script:</p> <pre class="lang-py prettyprint-override"><code>from multiprocessing.connection import Listener with Listener(('localhost', 6000)) as listener: with listener.accept() as connection: message = connection.recv() # [...] connection.send(message) ...
<python><sockets><multiprocessing><client>
2024-06-05 15:48:53
2
11,833
arthur.sw
78,582,172
3,908,009
One liner HTTP server responding in JSON?
<p>There are times when I want to just launch a quick http server on a basic linux machine with no special software installed.</p> <p>I run the following:</p> <pre><code>python3 -m http.server 8080 </code></pre> <p>This returns the directory listing HTML page with response code 200.</p> <p>Is there a similar one-liner ...
<python><http>
2024-06-05 15:48:40
1
1,086
Neil
78,582,171
1,676,006
Is there any way to read and process an azure blob as a stream using the python sdk without loading the whole blob into memory?
<p>I'd like to be able to treat an azure blob like an IO object using the python SDK. As far as I can tell, this requires me to either:</p> <p>a) use <code>.readinto()</code> to read the blob into an IO object (thus loading the whole undefined-size blob into memory inside a container with 256Mb of memory)</p> <p>b) man...
<python><azure-blob-storage><bson><azure-python-sdk>
2024-06-05 15:48:34
1
703
ChickenWing
78,582,091
4,445,584
How import external packages correctly using Nuitka
<p>I need some help about how importing external packages. I am using Eclipse with PyDev plugin to develop Python applications, I have a workspace containing all my projects and all the libraries/package I use in them. Also the libs/packages are projects by themselves. So the filesystem structure is:</p> <pre><code>/ (...
<python><nuitka>
2024-06-05 15:31:19
1
475
Massimo Manca
78,582,042
4,129,131
How to solve the xmlsec Error: (100, 'lxml & xmlsec libxml2 library version mismatch')
<p>I am facing the following error when deploying my Django (version 4.1) Backend, I have the following Dockerfile (some non-relevant parts omitted) and need to install python3-saml (which has dependencies like lxml and xmlsec). The documentation mentions the following: <a href="https://i.sstatic.net/7TijfZeK.png" rel=...
<python><django><lxml><saml><xmlsec>
2024-06-05 15:23:07
1
670
Philippe
78,581,853
5,281,775
Multi-positional one-hot encoding based update
<p>I have some array, and a given index/array of indices. Using this index/indices, I have to update another array. These updates shouldn't be in-place. I am able to do this for a single index, but unable to achieve the right result for array of indices. Here is an example:</p> <pre class="lang-py prettyprint-override"...
<python><arrays><numpy>
2024-06-05 14:49:54
0
2,325
enterML
78,581,797
6,330,106
How can I create an in-memory file object that has a file descriptor in Python?
<p>I plan to use <code>subprocess.Popen</code> (in Python 3.11.2) to implement <code>git mktree &lt; foo.txt</code>. Now I face the question.</p> <p>In order to reproduce my situation, here is the script that creates the environment.</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/bash export GIT_AUTHOR_N...
<python><python-3.x>
2024-06-05 14:42:40
1
31,575
ElpieKay
78,581,563
6,930,340
Create pandas time series DataFrame using hypothesis
<p>I need to create a <code>pd.DataFrame</code> with a <code>datetime</code> or <code>pd.date_range</code> index. I have the following code, which almost generates what I need.</p> <p>However, a time series index is characterized by the fact that you have increasing dates/times. My code fails on this point.</p> <pre><c...
<python><pandas><python-hypothesis>
2024-06-05 14:03:13
1
5,167
Andi
78,581,219
8,995,555
DigitalOcean App Platform says Out of Memory during docker build
<p>I have setup a flask web service using a Dockerfile for the deployment. I have added some ML related packages such as <code>torch</code> <code>torchvision</code> etc. and a lot of others.</p> <p>The docker image builds fine in my local mac, but fails in digital ocean after the following.</p> <p>It remains in the <co...
<python><flask><digital-ocean>
2024-06-05 13:10:17
1
1,014
RukshanJS
78,581,188
2,245,709
Decorator in python-flask is giving "AssertionError: View function mapping is overwriting an existing endpoint function"
<p>I am writing a flask endpoint with decorator added for <strong>JWT decoding</strong>, but it keeps giving me the error</p> <pre><code>AssertionError: View function mapping is overwriting an existing endpoint function </code></pre> <p>I am trying to decode the JWT token (using the decorator) then passing the payload ...
<python><flask>
2024-06-05 13:04:17
1
1,115
aiman
78,581,162
12,881,307
Python Kmeans consistently label clusters
<p>I have a high dimension variable dataset which I want to classify into different groups. The data within can be confidently classified into 5 distinct groups.</p> <p>I want to use the result of this clusterization process to create visual charts showcasing the difference within the resulting groups. As part of this ...
<python><scikit-learn>
2024-06-05 12:59:40
1
316
Pollastre
78,581,052
3,120,501
'Output states' in Dymos?
<p>I'm building a model in Dymos/OpenMDAO. There are a few states which are required for calculating the dynamics, and then some which I'd just like to derive and output. For example, say I had a very simple model with dynamic states of displacement x and velocity v, and a force input u. Then the dynamics would be x_do...
<python><optimization><openmdao>
2024-06-05 12:39:58
1
528
LordCat
78,580,994
7,442,673
Python 3 process non-printable characters in a unicode string
<p>I'm reading text that contains non-printable characters such as backspaces from a file <code>example.log</code>. If I'm reading the content of the file in a terminal running <code>cat example.log</code>, I obtain a well formatted string:</p> <p><code>Loading file /path_to/some_db/hold_fix_crash.db</code></p> <p>But ...
<python><python-3.x><string><non-printing-characters>
2024-06-05 12:28:50
1
3,202
m.raynal - bye toxic community
78,580,775
2,849,491
Continuously read journald with Python
<p>I wrote a monitoring plugin that reads the systemd-journal for a given unit and process it. My code looks like this:</p> <pre><code># Once on start of the monitoring from systemd import journal j = journal.Reader() j.seek_realtime(datetime.now()) j.add_match(&quot;_SYSTEMD_UNIT=postfix.service&quot;) j.add_match(&qu...
<python><systemd><systemd-journald>
2024-06-05 11:48:59
0
371
Nudin
78,580,737
10,816,965
Understanding the details of equality in Python
<p>When trying to construct an example where <code>a == b</code> is not the same as <code>b == a</code>, it seems that I have accidentally constructed an example where <code>a == b</code> is not the same as <code>a.__eq__(b)</code>:</p> <pre><code>class A: def __eq__(self, other: object) -&gt; bool: return...
<python><equality>
2024-06-05 11:43:32
3
605
Sebastian Thomas
78,580,725
308,204
Annotate Django JSONField to convert all values to strings
<p>I'm using Django's full text search features, and want it to search through a model called Row, which has a JSONfield .data that has a value like:</p> <pre><code>[[&quot;A1&quot;, 87, 987, &quot;blue&quot;], [&quot;B1&quot;, null, null, &quot;white&quot;]] </code></pre> <p>Code to do the search:</p> <pre><code>sear...
<python><django><django-models>
2024-06-05 11:41:39
0
9,044
Mathieu Dhondt
78,580,609
8,964,393
How to vertically concatenate hundreds of .png files in python
<p>I have about 250 .png files in one directory.</p> <p>I need to vertically concatenate them from python.</p> <p>Here is the code I have so far.</p> <pre><code>list_im = [] &lt;- this is the list of .png files &lt;- How do I populate it if I have 250 files in one directory? imgs = [ Image.open(i) for i in list_im ...
<python><list><concatenation><png>
2024-06-05 11:18:36
1
1,762
Giampaolo Levorato
78,580,345
7,047,037
Can dbt cloud execute python scripts?
<p>I am pretty sure that natively this is not possible, but I might be wrong. Do you know if I can execute Python scripts inside dbt? Not talking about python models. I basically have a python code that generates Sql models based on informations that i give. I run it on VS code on my dbt-core. But I wonder if I can exe...
<python><dbt>
2024-06-05 10:31:03
1
676
Catarina Ribeiro
78,580,331
18,910,865
Python version is higher in virtual environment than the one specified in pyproject.toml
<p>I've currently set my <code>pyproject.toml</code> as follows</p> <pre class="lang-ini prettyprint-override"><code># ... [tool.poetry.dependencies] python = &quot;^3.8.0&quot; pandas = &quot;^2.0.0&quot; numpy = &quot;^1.21.0&quot; requests = &quot;^2.25.1&quot; # ... </code></pre> <p>I do then the following:</p> <pr...
<python><python-packaging><python-poetry><pyproject.toml>
2024-06-05 10:28:14
1
522
Nauel
78,580,229
6,197,439
Synchronising dual x axes in a dual (sub)plot in interactive Matplotlib 3.8.1?
<p>Some years ago, I have posted the question <a href="https://stackoverflow.com/questions/58415862/synchronising-dual-x-axes-in-a-dual-subplot-in-interactive-matplotlib">Synchronising dual x axes in a dual (sub)plot in interactive Matplotlib?</a> , which ended up having a working solution, which was behaved like this:...
<python><python-3.x><matplotlib>
2024-06-05 10:07:39
1
5,938
sdbbs
78,580,140
12,881,307
Integrating Custom Python Environment with Power BI Service
<p>I've created a chart using python and pipenv. I want to integrate this chart into my company's main <code>PowerBI</code> environment. I've read that I can use python scripts within <code>PowerBI Desktop</code>, as long as I provide a path to a local python installation.</p> <p>From what I understand, I can control m...
<python><powerbi>
2024-06-05 09:51:14
1
316
Pollastre
78,579,944
12,304,000
handling special characters while loading data from s3 into mysql
<p>In my S3, I have a csv file that looks like this:</p> <pre><code>&quot;id&quot;,&quot;created_at&quot;,&quot;subject&quot;,&quot;description&quot;,&quot;priority&quot;,&quot;status&quot;,&quot;recipient&quot;, </code></pre> <p>Now, one the <strong>description</strong> column's <strong>row</strong> looks like this...
<python><sql><mysql><amazon-s3><special-characters>
2024-06-05 09:17:00
1
3,522
x89
78,579,640
9,601,720
Folium filter markers dynamically by property
<p>I have the following code to draw circles at different locations, using Folium:</p> <pre><code>import folium data = [ {&quot;lat&quot;: 37.7749, &quot;lon&quot;: -122.4194, &quot;value&quot;: 10, &quot;name&quot;: &quot;Location A&quot;}, {&quot;lat&quot;: 34.0522, &quot;lon&quot;: -118.2437, &quot;value&qu...
<python><folium><folium-plugins>
2024-06-05 08:20:42
0
660
thmasker
78,579,582
6,195,489
Understanding task stream and speeding up Distributed Dask
<p>I have implemented some data analysis in Dask using dask-distributed, but the performance is very far from the same analysis implemented in numpy/pandas and I am finding it difficult to understand the task stream and memory consumption.</p> <p>The class that sets up the cluster looks like:</p> <pre><code>class some_...
<python><dask><dask-distributed>
2024-06-05 08:09:09
1
849
abinitio
78,579,156
14,818,993
“OperationalError: Could not translate host name “db” to address" in Dockerized Django App with Datadog
<p>I have a very complex django project that uses postgresql as database, where I have setup datadog to send traces and events. It works fine locally and I am receiving traces and events in datadog. However, if I try to run my app using docker, it won't send traces and events to datadog. Following is my <code>docker-co...
<python><django><postgresql><docker><datadog>
2024-06-05 06:38:45
1
308
Huzaifa Arshad
78,579,132
2,398,430
Pytest parameter id access in test
<p>I am using pytest and I have the id set for each parameter of a test. I use:</p> <pre><code>pytest.param([], id = &quot;meaningful_string&quot;) </code></pre> <p>The test can access the param list. Is it also possible for the test to access the param id?</p>
<python><pytest>
2024-06-05 06:33:50
1
366
stackQA
78,579,128
5,567,893
How can I randomly replace the values remaining at least one value using python?
<p>I tried to replace the some of major values in the tensor with the unique value while maintaining at least one value.</p> <p>For example, given <code>edge_index</code>, I want to change it as below.</p> <pre class="lang-py prettyprint-override"><code>edge_index = torch.as_tensor([[0, 0, 1, 2, 3, 4, 6, 7, 7, 8], ...
<python><pytorch>
2024-06-05 06:33:23
1
466
Ssong
78,578,790
12,231,242
Tkinter back and forward buttons re: visited history
<p>My app displays details for one person at a time based on a <code>current_person_id</code> and other information related to that person which is stored in a database. I wanted to change the details displayed based on the order in which different persons' details had been seen, so it would work like a browser's back/...
<python><tkinter><back-button>
2024-06-05 04:47:13
1
574
Luther
78,578,679
3,452,340
Using SSE in Flask
<p>I'm using Flask to develop a web app. I have a <code>/stream</code> route in my python code, an <code>index.html</code> file, and a <code>stream_page.html</code> that triggers the stream route.</p> <p>I want to trigger a stream from <code>stream_page.html</code>, calling the <code>/stream</code> route with a POST ca...
<python><html><flask>
2024-06-05 03:52:18
1
907
miara
78,578,563
2,813,606
How to parse out text from PDF into pandas dataframe
<p>I am working on scraping data from several infographics on ridership data for Amtrak. I want to collect the yearly ridership #s and addresses of each station in the US.</p> <p>Here is my code for one station:</p> <pre><code>import requests from bs4 import BeautifulSoup import pandas as pd import fitz url_abe = 'h...
<python><pandas><parsing><beautifulsoup><python-requests>
2024-06-05 02:56:36
2
921
user2813606
78,578,556
4,592,891
Freegpt-webui python displays "No matching distribution found for mailgw_temporary_email" when installing
<p>complete error message</p> <pre><code>ERROR: Could not find a version that satisfies the requirement mailgw_temporary_email (from versions: none) ERROR: No matching distribution found for mailgw_temporary_email </code></pre> <p>I tried searching for this package in pip, but it didn't exist at all.</p> <p>Now the ins...
<python><pip>
2024-06-05 02:51:30
1
980
aboutjquery
78,578,185
1,217,810
How do I carry over an import carried out in a 2nd file back to the calling file in python?
<p>The code below is a utility I wrote that installs and restarts a script automatically without having the user need to parse through errors to install. Ideal usage would be below:</p> <pre><code>#file1.py from file2 import import_and_install succ = import_and_install(&quot;numpy&quot;) #import numpy succ |= import_an...
<python><python-import><python-importlib>
2024-06-04 23:37:18
1
567
Painguy
78,578,124
8,849,071
How are connections handled by SQLAlchemy internally
<h2>Context</h2> <p>Hello, I mostly use Django for my main backend monolith. In Django, you do not need to handle db connections on your own, this is abstracted (because Django uses the Active Record pattern instead of the Data mapper pattern used by Sqlalchemy).</p> <p>I have been doing some reading and I feel like I ...
<python><django><sqlalchemy><fastapi><connection-pooling>
2024-06-04 23:13:38
1
2,163
Antonio Gamiz Delgado
78,578,045
4,927,864
How to get MySQL result values as string or number?
<p>I'm currently using PyMySQL to make queries to my MySQL DB. I wanted the results to be a dictionary, where the columns are the keys and with their associated values, and I've got that. But I've noticed that values for types like dates and decimals are returned as objects, which is not what I've encountered with othe...
<python><pymysql>
2024-06-04 22:37:10
1
2,395
kenshin9
78,577,998
214,526
How to use pandera to validate non numeric columns against numeric datatype in schema and raise error
<p>How can I use pandera to validate dataframe columns to ensure errors are raised if data-type does not match against the schema?</p> <p>Say, I have the schema defined as following -</p> <pre><code>import re from typing import Any, Dict, List, Pattern # import jsonschema import pandas as pd import numpy as np import ...
<python><pandas><dataframe><pandera>
2024-06-04 22:22:35
1
911
soumeng78
78,577,887
6,141,885
How to define the forward pass in a custom PyTorch FasterRCNN?
<p>I'm trying to write a custom PyTorch FasterRCNN that's based on an existing PyTorch model, <code>fasterrcnn_resnet50_fpn</code>, but I'm getting stuck on how to correctly write the forward pass. Following <a href="https://discuss.pytorch.org/t/how-to-retrieve-the-loss-function-of-fasterrcnn-for-object-detection/1741...
<python><pytorch><loss-function><faster-rcnn>
2024-06-04 21:58:00
0
1,327
morepenguins
78,577,881
4,271,491
A task won't trigger after a BranchPythonOperator calls it
<p>I'm trying to achieve max performance in the case I'm working on. <br> I'm parsing jsons and when the first three tasks:<br></p> <ul> <li>check_cm_files_present_task</li> <li>check_cmts_struct_files_present_task</li> <li>check_cmts_meas_files_present_task</li> </ul> <p>detect any new file in either one of three GCS ...
<python><airflow>
2024-06-04 21:56:30
1
528
Aleksander Lipka
78,577,849
6,365,949
How to get the track name in Audacity scripting?
<p>I am working with the <a href="https://en.wikipedia.org/wiki/Audacity_(audio_editor)" rel="nofollow noreferrer">Audacity</a> mod-script-pipeline to write a script which goes through every clip of every track, and gets the name of each track.</p> <p>My code works with everything, except getting the track name, but I ...
<python><audacity>
2024-06-04 21:43:45
0
1,582
Martin
78,577,834
14,345,989
NumPy: get a matrix of distances between values
<p>If I have a set of points:</p> <pre><code>points = np.random.randint(0, 11, size=10) print(points) </code></pre> <p>Output:</p> <pre class="lang-none prettyprint-override"><code>[ 5 4 9 7 4 1 2 10 4 2] </code></pre> <p>And if I want to get a matrix representing the distance from each point to each other poin...
<python><numpy><matrix>
2024-06-04 21:36:21
2
886
Mandias
78,577,784
3,478,605
How can I split a Sum in SymPy?
<p>SymPy understands that <code>Sum</code> and <code>+</code> commute.</p> <pre class="lang-py prettyprint-override"><code>from sympy import symbols, Idx, IndexedBase, Sum i, n = symbols(&quot;i n&quot;, cls=Idx) x = IndexedBase(&quot;x&quot;, shape=(n,)) s = Sum(x[i] + 1, (i, 1, n)) t = Sum(x[i], (i, 1, n)) + Sum(1, ...
<python><sympy>
2024-06-04 21:18:26
1
4,738
Valéry
78,577,720
4,751,700
Python: How to type a Union of TypeVarTuple
<p>I have a function that receives 3 parameters: <code>a: dict[str, str]</code>, <code>b:dict[str, str]</code>, and <code>c: dict[str, str]</code>. The values/keys of these parameters are &quot;linked&quot;. They are based on a existing protocol and some combinations are not possible.</p> <p>The keys in <code>b</code> ...
<python><python-typing>
2024-06-04 21:01:33
1
391
fanta fles
78,577,645
1,898,218
How to get conda to install pytorch-gpu rather than pytorch-cpu Ubuntu cuda 11.4
<p>I've combed through all of the similar questions but to no avail. I have an older GPU that I'm trying to get to work with CUDA and pytorch. For some reason, I can't get conda to install pytorch gpu. No matter what I do, it tries to install the cpu version of pytorch.</p> <p>I build my conda like this - miniconda</p>...
<python><pytorch><conda>
2024-06-04 20:41:37
1
1,782
Halfstop
78,577,558
11,608,962
ImportError when attempting to create a header using borb PDF library in Python
<p>I'm trying to create a header in a PDF document using the <code>borb</code> library in Python. However, I'm encountering an ImportError when attempting to import the necessary modules. Here's my code:</p> <pre class="lang-py prettyprint-override"><code>from borb.pdf import Page from borb.pdf import Document from bor...
<python><pdf><borb>
2024-06-04 20:17:26
1
1,427
Amit Pathak