QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
βŒ€
77,940,596
3,706,723
Azure Devops and uploading a Python package to Artifacts using pipeline | authentication issue
<p>I am trying to use the Azure pipeline to publish a Python package to Artifact's feed. I could do it from my local machine and upload the package using Twine, but I have an authentication issue in the pipeline.</p> <pre><code>trigger: - main pool: vmImage: ubuntu-22.04 variables: pip_cache_dir: '$(Pipeline.Works...
<python><azure-devops><artifact><twine>
2024-02-05 11:31:14
2
963
prhmma
77,940,593
13,392,257
How to parametrize table column creation with help of list?
<p>I want to use a list with column names to generate CREATE TABLE <code>sql</code> script.</p> <p>I want to create a function.</p> <pre><code>def create_table(column_names: List[str]): pass </code></pre> <p>Example:</p> <pre><code>Input [&quot;col1&quot;, &quot;col2&quot;, &quot;colN&quot;] </code></pre> <p>Output...
<python><psycopg2>
2024-02-05 11:30:37
1
1,708
mascai
77,940,460
3,122,657
psycopg3 pool: all connections getting lost instantly after long idle time
<p>If it's a standalone persistant connection, I have no problem, connection lasts for hours.<br /> If I use psycopg(3) Connection pool, I make make requests, first requests are ok and my pool size stays at 5, at one point pool size decreases and I get a Pool Timeout when client makes a new request.<br /> Then I tried:...
<python><postgresql><psycopg2><psycopg3>
2024-02-05 11:12:26
1
3,374
comte
77,940,377
2,175,012
Mamba/Micromamba: Add path to environment
<p>Conda has the <code>conda develop</code> command, which can be used to add paths to local python projects (e.g. self-written libraries that aren't distributed as packages) to the module path of an environment.</p> <p>How can I achieve a similar effect with mamba / micromamba (or even independently of the package man...
<python><conda><mamba>
2024-02-05 10:56:08
0
2,156
Xaser
77,940,303
258,009
Python mocking: basic errors mocking a class using patch/MagicMock
<p>Although I've successfully used google test and mock successfully for C++, I'm getting nowhere when it comes to using mocking in Python.</p> <p>I'm trying to mock a small class in my code so that I can ensure the response from a particular function. I want to mock the whole class since the constructor does things th...
<python><unit-testing><mocking><magicmock>
2024-02-05 10:43:37
1
10,557
Component 10
77,940,195
3,842,823
Overriding list entry in Hydra, from another YAML
<p>In Hydra config YAML files, I have the following structure in the file <code>inner.yaml</code>:</p> <pre class="lang-yaml prettyprint-override"><code>key_a: - entry_a_1: xxxx entry_a_2: xxxxx - entry_a_3: xxxx entry_a_4: xxxxx </code></pre> <p>What I want is to be able to override the <code>entry...
<python><fb-hydra>
2024-02-05 10:24:46
1
1,951
Xxxo
77,940,051
365,872
`asyncio.get_event_loop()` works in plain python but not in ipython
<p>I observe different behavior of <code>asyncio.get_event_loop()</code> in plain <code>python</code> console and in <code>ipython</code>.</p> <p>Plain <code>python</code> - all as expected:</p> <pre class="lang-py prettyprint-override"><code>Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux Type &quot...
<python><python-asyncio><ipython>
2024-02-05 10:02:17
0
28,682
ffriend
77,940,019
5,168,463
Spark read table from a specific location
<p>I have saved a dataframe as a table using the following code:</p> <pre><code>yearly_calltype.write.option(&quot;path&quot;, &quot;/home/user/tables/firstProject&quot;).saveAsTable('yearly_calltype_count') </code></pre> <p>But how do I read this table from this location?</p> <p>When I am trying to do:</p> <pre><code>...
<python><apache-spark><pyspark><apache-spark-sql>
2024-02-05 09:57:18
1
515
DumbCoder
77,939,988
11,046,379
Django Backend doesn't return json to Angular frontend
<p>I have web project, backend on Django , frontend on Angular</p> <p>Backend started as:</p> <pre><code>python3 manage.py runserver 192.168.1.195:8080 </code></pre> <p>Frontend started as:</p> <pre><code>ng serve --host 192.168.1.195 </code></pre> <p>on the 4200 port.</p> <p>On the Django in CORS_ORIGIN_WHITELIST s...
<python><django><angular>
2024-02-05 09:52:55
0
1,658
harp1814
77,939,981
1,047,788
How to handle diamond dependency in Python?
<p>My project has two dependencies, and each of them transitively depends on a different major version of protobuf.</p> <p>The general situation is well described</p> <ul> <li>in an article <a href="https://jlbp.dev/what-is-a-diamond-dependency-conflict" rel="nofollow noreferrer">Google Best Practices for Java Librarie...
<python><dependency-management>
2024-02-05 09:51:45
1
29,820
user7610
77,939,970
11,092,636
Inconsistent behaviour with Python loggings when creating a package (__init__.py and from . import module)
<p>Here is a MRE:</p> <p><code>my_package/__init__.py</code></p> <pre class="lang-py prettyprint-override"><code>import logging from . import module, a_second_module logging.basicConfig(level=logging.INFO) </code></pre> <p><code>my_package/module.py</code></p> <pre class="lang-py prettyprint-override"><code>import lo...
<python><logging><package>
2024-02-05 09:49:29
0
720
FluidMechanics Potential Flows
77,939,924
859,591
Importing pandas and cplex in a conda environment raises an ImportError: libstdc++.so.6: version `GLIBCXX_3.4.29' not found
<p>Importing the Python libraries <a href="https://pandas.pydata.org/" rel="nofollow noreferrer"><code>pandas</code></a> and <a href="https://en.wikipedia.org/wiki/CPLEX" rel="nofollow noreferrer"><code>cplex</code></a> in an conda raises the following exception:</p> <pre><code>ImportError, because 'GLIBCXX_3.4.29 not ...
<python><pandas><conda><shared-libraries><glibc>
2024-02-05 09:41:49
1
9,363
lumbric
77,939,687
2,305,768
Cuda Pytorch Error: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0
<p>I am trying to train a deep neural network on cuda. I found some code and I am trying to make it compatible to cuda. My code is as below:</p> <pre class="lang-py prettyprint-override"><code>class UnsupervisedModel(torch.nn.Module): def __init__(self): super(UnsupervisedModel, self).__init__() #...
<python><pytorch><pytorch-lightning>
2024-02-05 09:02:59
1
478
sersem1
77,939,544
8,920,642
Python H5PY warning getlimits.py:511: UserWarning: Signature <class 'numpy.float128'> does not match any known type
<p>I get following warning on RedHat 8.8 for H5PY Package:</p> <p>Is there any way to fix this? I dont want to use <strong>warnings.filterwarnings(&quot;ignore&quot;)</strong></p> <pre><code>bash-4.4$ python3 Python 3.11.6 (main, Oct 16 2023, 03:41:34) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] on linux Type &quot;help&qu...
<python><python-3.x><linux><numpy><h5py>
2024-02-05 08:34:54
1
398
Ashish Shirodkar
77,939,099
9,495,110
How to import a Python class from a directory which has dependency in the same directory?
<p>I want to use a class <code>A</code>, which is in a subdirectory <code>dir</code> in file <code>A.py</code>. It has dependency with file <code>B.py</code> which is also in the same directory <code>dir</code>. I want to use the <code>A</code> class from its parent directory. The file tree looks like this:</p> <pre><c...
<python><python-3.x><python-module>
2024-02-05 07:00:07
1
1,027
let me down slowly
77,938,918
4,699,441
How to get Python imports to work consistently?
<p>The <a href="https://stackoverflow.com/questions/77936303/">solution to this question</a> works only for the special case of importing from the same directory.</p> <p>However, if I put the <code>Child</code> class into a sibling directory then that solution doesn't work. Same goes if I do not <code>from [something] ...
<python><python-3.x><python-import>
2024-02-05 06:07:09
5
1,078
user66554
77,938,831
119,527
Disambiguating expressions in Lark syntax
<p>I have a (Lark) grammar that I think should be unambiguous, but depending on the version of Lark, fails to parse in one way or another:</p> <pre class="lang-py prettyprint-override"><code>import lark syntax = r&quot;&quot;&quot; stmt: mov_stmt | special_stmt mov_stmt: reg ASSIGN (reg | const) special_stmt: (&q...
<python><ebnf><lark-parser>
2024-02-05 05:41:47
1
138,383
Jonathon Reinhart
77,938,797
264,136
Using python to build a jenkins job: how to pass checkbox values
<pre><code>jenkins_server = jenkins.Jenkins(project_path, username=&quot;moyemoye&quot;, password=password, timeout=120) parameters = { 'IMG_PATH': &quot;IMG_PATH&quot;, 'vcpu': &quot;2&quot;, 'Topo_Traffic_Type': &quot;imix,1518/1400&quot;, 'RUN_CEF_SUITE_FEATURE_LIST': &quot;all&quot;, 'clean_relo...
<python><jenkins><jenkins-plugins><jenkins-api>
2024-02-05 05:30:04
1
5,538
Akshay J
77,938,741
3,121,975
Join based on substring operation
<p>Suppose I have two DataFrames, <code>a</code> and <code>b</code> with columns &quot;Name&quot; and &quot;ID&quot; respectively. What I'm trying to do is to find all the columns in <code>a[&quot;Name&quot;]</code> that are a substring of a value in <code>b[&quot;ID&quot;]</code> so that when I join <code>b</code> to ...
<python><pandas>
2024-02-05 05:06:43
2
8,192
Woody1193
77,938,707
16,405,935
How to find the first first occurrence of a character
<p>I have a simple dataframe as below:</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame({'BAS_DT': ['2023-01-02', '2023-01-03', '2023-01-04', '2023-01-02', '2023-01-03'], 'CUS_NAME': ['A', 'A', 'A', 'B', 'B'], 'Y/N': ['Y', 'Y', 'Y', 'N', 'Y'], ...
<python><pandas><dataframe>
2024-02-05 04:52:44
1
1,793
hoa tran
77,938,422
5,896,591
python: How to set F_NOTIFY from non-main thread?
<p>I am trying to watch a directory using F_NOTIFY in Linux (Ubuntu 16, Python 3.5.2). However, it only works if I call <code>fcntl</code> from the main thread. Why are there no signals when I call <code>fcntl</code> from other threads? (I don't see any mention of threads in the python <a href="https://docs.python.org/...
<python><linux><signals><fcntl>
2024-02-05 02:58:04
0
4,630
personal_cloud
77,938,379
21,107,707
Why does `math.log` not have a `__text_signature__` in Python?
<p>I was playing around in the Python REPL and I noticed most <code>math</code> functions have the <code>__text_signature__</code> attribute; I notice it provides information regarding function signatures, and is non-None for every function in the <code>math</code> module (this is Python 3.11) except the <code>log</cod...
<python>
2024-02-05 02:40:13
1
801
vs07
77,938,305
18,730,707
Doesn't df.style.format() apply to Excel in version 2.1.4 of pandas?
<p>I want to apply number formatting. I know how to apply it through <code>df.style.map</code>. However, it is not possible to apply it to all rows using <code>df.style.format()</code>. I'd like to know if I'm doing something wrong.</p> <p>Currently pandas is using version 2.1.4. I wrote code like this:</p> <pre class=...
<python><pandas>
2024-02-05 02:08:06
1
878
na_sacc
77,938,228
2,135,504
Complex query in SQLalchemy with dictionary like in MongoDB
<h1>Problem</h1> <p>In pymongo, I can define my query using rather complex dictionaries:</p> <pre class="lang-py prettyprint-override"><code>one_week_ago = datetime.utcnow() - timedelta(days=7) query_dict = { 'name': {'$regex': 'John'}, 'age': {'$in': [25, 30, 35]}, 'created_at': {'$gte': one_week_ago}, } r...
<python><sqlalchemy><pymongo>
2024-02-05 01:20:22
1
2,749
gebbissimo
77,938,199
15,476,955
langchain dynamic way to handle keys issues
<p>I know it's too open question for some moderators but let me explain before attacking.</p> <p>Langchain is a really recent library, I have dozens of errors to post to the stackoverflow site so I prefer to begin with the good question: what should be the way of thinking to understand what the developers of langchain ...
<python><langchain><large-language-model>
2024-02-05 01:06:13
0
1,168
Utopion
77,938,187
2,612,259
How can I display text when hovering over a legend item in Python Plotly?
<p>Sorry for asking a question with very little info, but its a very simple question. I have looked thru the documentation of Plotly (python) and can't find a way to simply add hover text when hovering over an item in the legend. The names of the traces are very long, so I am just using the defaults , ie trace 0. I w...
<python><plotly>
2024-02-05 01:01:17
1
16,822
nPn
77,938,167
5,016,028
LiteLLM and Llama-Index Service Context creation
<p>I am going crazy with finding a solution to this. I am working with a proxy server for OpenAI models. I'm using an ssh tunnel to hit the server on my localhost.</p> <pre><code>from openai import OpenAI client = OpenAI(base_url=&quot;http://localhost:8000&quot;, api_key=&quot;sk-xxx&quot;) response = client.chat.co...
<python><python-3.x><openai-api><large-language-model><llama-index>
2024-02-05 00:48:48
1
4,373
Qubix
77,938,105
2,658,228
Unable to fix frame size in app - customtkinter, tkinter
<p>I'm working on an app to covert some files. The interface consists of two frames - one that displays selected files, the other will contain parameters the users can modify (e.g. file pre-fix, location etc.).</p> <p>I'd like the <code>frame</code> width and height to be fixed (300px each) but it changes when I add wi...
<python><python-3.x><tkinter><customtkinter>
2024-02-05 00:14:27
1
2,763
Gautam
77,937,995
12,369,606
in a yaml file, use the output of one target function as input parameters for a different function
<p>I have a python script that uses a yaml file to call a function. Currently it is formatted like this:</p> <pre><code>name: DataSet _target_: some.function.here _params_: root: ${paths.datadir} label_name: label version: 0.1.0 log_level: ${log_level} </code></pre> <p>I have another function, <code>my.label.f...
<python><yaml>
2024-02-04 23:27:26
0
504
keenan
77,937,994
8,484,261
Find the rows in two dataframe where a 2nd column's value has changed for a 1st column which is a key column?
<p>I am trying to comparing <code>dataframe df1</code> with <code>df2</code> by column <code>cust_id</code> and town_id, and get all rows pf cust_id for which the town_id has changed. I can use list comprehension to get the list of <code>cust_id</code> which are in <code>df21</code> but not in <code>df2</code> or vice-...
<python><pandas><list-comprehension>
2024-02-04 23:27:09
1
3,700
Alhpa Delta
77,937,790
3,498,864
Stuck formulating an adjacency constraint with pyomo
<p>I'm trying to assign <code>attributes</code> into a 3 x 3 matrix based on an adjacency constraint, but I'm stuck formulating the adjacency constraint. I keep thinking I've got the answer, then when I try it the result isn't as expected.</p> <p>So, <code>element</code>s are pre-arranged into an <code>element_map</cod...
<python><optimization><sparse-matrix><linear-programming><integer-programming>
2024-02-04 22:13:49
1
3,719
Ryan
77,937,698
476,074
One print expression strangely depends on another print expression
<p>I have this Jinja2 template:</p> <pre><code>{% set input = 1 %} {% set steps = [1, 2, 3, 4]|select(&quot;greaterthan&quot;, input) %} {{ steps|list }} {{ steps|first if steps|list|length &gt; 0 else None }} </code></pre> <p>It prints:</p> <pre><code>[2, 3, 4] None </code></pre> <p>Now I remove <code>{{ steps|list }}...
<python><jinja2>
2024-02-04 21:44:25
1
33,938
AndreKR
77,937,367
4,063,520
Why ctypes misses ptrdiff_t?
<p>I'm puzzled by the absence of <code>ptrdiff_t</code> type in <code>ctypes</code>.</p> <p>Out of 3 types defined in <code>stddef.h</code>, <code>wchar_t</code> and <code>size_t</code> are present in <code>ctypes</code>. But not <code>ptrdiff_t</code>.</p> <p>I've been working with Fortran's iso_c_binding, and there m...
<python><python-3.x><cython><ctypes>
2024-02-04 19:51:05
0
1,943
Dmitry Mikushin
77,937,329
11,938,023
Major Speedup Question for a for loop in Pandas/Numpy on a bitwise_xor accumulate
<p>Ok i am using a for loop as show below to convert this data from to the one below using xor accumulate. For the entries i have (830401) rows and this is very very slow. is there any way to speed up this kind of accumulate in pandas or using numpy and then assiging it back the numpy array itself</p> <pre><code> In [...
<python><pandas><numpy><bitwise-operators>
2024-02-04 19:38:00
1
7,224
oppressionslayer
77,937,287
1,016,428
Better way to find nonzero indices and values in a 2D array
<p>I am still fighting against the problem of finding the <code>i</code>, <code>j</code> indices (and the corresponding values) of nonzero entries in a <strong>dense</strong>, <strong>single precision</strong>, <strong>Fortran-ordered</strong> 2D array. I am using Cython via Python with some C in the middle.</p> <p>I a...
<python><c><gcc><cython><simd>
2024-02-04 19:26:43
1
1,449
Infinity77
77,937,285
1,028,289
Python error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdb in position 0: unexpected end of data
<p>I am trying to append a column of a csv file in a jsonl file using python. I tried fol code:-</p> <pre><code> import csv import json def csv_column_to_jsonl(csv_file, column_index, jsonl_file): with open(csv_file, 'r', encoding='utf-8-sig') as file: reader = csv.reader(file) data = [row[c...
<python><json><csv><google-colaboratory><codec>
2024-02-04 19:25:33
1
391
jaykio77
77,937,064
960,115
OpenPyXL Set Worksheet Formula and Value
<p>I'm trying to create an Excel workbook in Python that includes formulas, and want to parse the workbook later without needing to open it in Excel first to evaluate the formula. E.g., I have a formula with a known computation result, and want to store both the formula and its resulting value using OpenPyXL.</p> <p>H...
<python><python-3.x><openpyxl>
2024-02-04 18:22:56
0
4,735
Jeff G
77,936,766
14,250,641
Mapping embeddings to labels in PyTorch/Huggingface
<p>I am currently working on a project where I am using a pre-trained transformer model to generate embeddings for DNA sequences (some have a '1' label and some have a '0' label). I'm trying to map these embeddings back to their corresponding labels in my dataset, but I'm encountering an IndexError when attempting to d...
<python><tensorflow><pytorch><huggingface-transformers><word-embedding>
2024-02-04 17:06:58
2
514
youtube
77,936,762
2,977,164
Making a shiny application using YOLOv5
<p>I want to create a dashboard application in Shiny in Rstudio using Python. The objective is to deploy a TensorFlow model inside a Shiny app. We will build a model that can classify insects in images; then, we will build a Shiny app that lets you upload an image and get predictions from this model. My idea is to crea...
<python><r><shiny><yolo>
2024-02-04 17:05:30
0
1,883
Leprechault
77,936,741
18,346,591
Plot arrow on each point towards the line in graph
<p>I am trying to plot arrows from each data point towards the line in the graph using matplotlib.</p> <p><a href="https://i.sstatic.net/sCkRn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sCkRn.png" alt="Graph" /></a></p> <p>I want the arrow to represent the distance between each point and the line. H...
<python><matplotlib><machine-learning><graph><least-squares>
2024-02-04 17:00:07
3
662
Alexander Obidiegwu
77,936,723
3,674,127
Conftest discovery with tests as part of application code
<p>I'm using pytest and decided to go with <a href="https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#tests-as-part-of-application-code" rel="nofollow noreferrer">Tests as part of application code</a> pattern. Everything works fine besides conftest discovery.</p> <p>I have the following structure:</p> <pr...
<python><pytest><pytest-fixtures><conftest>
2024-02-04 16:55:41
1
4,295
Golan Kiviti
77,936,303
4,699,441
Python tests separate directory from production code: cannot get consistent imports
<p>In a submodule I have a class <code>Parent</code> that uses an auxillary class <code>Child</code> located in the same module.</p> <p><strong>Problem</strong>: depending on whether I execute the tests or run the application, the <code>import</code> statement in the <code>parent.py</code> needs to look different.</p> ...
<python><python-import>
2024-02-04 15:02:57
1
1,078
user66554
77,936,268
12,931,358
There are two subfolders A and B under a large folder. How to import the .py file from B into A?
<p>the structure of my folder like,</p> <pre><code>my_proj(large folder) -__init__.py -dosomething(A) --__init__.py --test.py -calculate(B) --__init__.py --add_num.py </code></pre> <p>While</p> <pre><code>#in add_num.py def my_add_num(a, b): return a + b #in __init__.py from .add_num import my_add_num </code></...
<python><python-3.x>
2024-02-04 14:54:03
0
2,077
4daJKong
77,935,843
1,020,139
How to convert existing `TypeVar` into Python 3.12's type parameter syntax?
<p>Consider the following <code>TypeVar</code> declaration:</p> <pre><code>T = TypeVar(&quot;T&quot;, bound=RedisCache) def make_redis_client(c: ReadableContainer, cache_factory: Type[T], db: BffRedisDB) -&gt; T: return cache_factory(redis=redis.Redis(host=c[BffEnvData].get_redis_connection_url(), port=c[BffEnvDa...
<python><python-3.x>
2024-02-04 12:47:39
1
14,560
Shuzheng
77,935,689
20,771,478
Python: MSAL --> Getting token with username and password
<p>I am following the <a href="https://learn.microsoft.com/en-us/entra/identity-platform/scenario-desktop-acquire-token-username-password?tabs=python" rel="nofollow noreferrer">Microsoft documentation for aquiring an MSAL token by username and password</a>.</p> <p>For understanding how MSAL works I try something very s...
<python><azure><azure-active-directory><token><msal>
2024-02-04 12:02:50
1
458
Merlin Nestler
77,935,507
9,779,999
How to create a Chromadb after VectorstoreIndexCreator for your CSV?
<p>I have successfully created a chatbot that can answer question by referencing to the csv. My code is as below,</p> <pre><code>loader = CSVLoader(file_path='data.csv') # load the csv index_creator = VectorstoreIndexCreator() # initiation docsearch = index_creator.from_loaders([loader]) # embedding </code></pre> <p>My...
<python><excel><csv><embedding><chromadb>
2024-02-04 11:05:10
1
1,669
yts61
77,935,397
4,862,162
Python InfiniteDefaultRevisionDictionary, any implementations?
<p>In programming, certain dictionary-based data structures are very useful and important. For example:</p> <ol> <li><p>Revision dictionary: Revision dictionary is a sub-type of dictionary that keeps keys sorted in the order of last modification. It is commonly used in cache handling which remembers most recently used ...
<python><dictionary><defaultdict><revision><infinite-recursion>
2024-02-04 10:29:39
1
1,615
xuancong84
77,935,269
10,628,959
Performance results differ between run_in_threadpool() and run_in_executor() in FastAPI
<p>Here's a minimal reproducible example of my FastAPI app. I have a strange behavior and I'm not sure I understand the reason.</p> <p>I'm using ApacheBench (<code>ab</code>) to send multiple requests as follows:</p> <pre><code>ab -n 1000 -c 50 -H 'accept: application/json' -H 'x-data-origin: source' 'http://localhost:...
<python><python-asyncio><fastapi><starlette><apachebench>
2024-02-04 09:46:30
3
475
Raphael Obadia
77,935,143
1,615,635
pip won't install requirements.txt because I'm missing a dependency, even though I already installed the dependency
<p>I used <code>pip install -r requirements.txt</code>, which I think is supposed to automatically install dependencies. I got <code>Exception: Building py-lmdb from source on Windows requires the &quot;patch-ng&quot; python module.</code>. Running <code>pip install patch-ng</code> just says <code>Requirement already s...
<python><pip>
2024-02-04 09:06:28
0
7,481
DanielLC
77,935,013
199,554
How to convert Python time.monotonic to walltime accurately
<p>I have a time returned by <code>time.monotonic()</code> that I want to convert to walltime (i.e. <code>time.time()</code>, suitable for formatting with <code>time.strftime</code>). Is there a precise/atomic way to get the offset between both? I know I can just request both <code>time.monotonic()</code> and <code>tim...
<python><time>
2024-02-04 08:17:16
1
11,282
Wim
77,934,941
7,647,857
Algorithm for generating a non-overlapping rectangles
<p>I'm working on a problem where I need to generate a rectangle (let's call it 'box') within a larger rectangle ('field'), ensuring that the box doesn't overlap with a smaller rectangle ('window') contained within the field. For simplicity, <em>all the coordinates are integers greater or equal to 0</em>.</p> <p>Here's...
<python><algorithm><numpy>
2024-02-04 07:41:31
3
399
user7647857
77,934,898
11,152,487
Gstreamer image overlay not working based on seconds
<p>I have this pipeline in python that im using to add images over a mp4 video but the output video is same as input one and when i used <code>GST_DEBUG=3</code> i got</p> <pre><code>0:00:00.046586337 11711 0x279d380 WARN gdkpixbufoverlay gstgdkpixbufoverlay.c:562:gst_gdk_pixbuf_overlay_start:&lt;gdkpixbufoverlay0&gt; ...
<python><gstreamer><python-gstreamer>
2024-02-04 07:17:14
1
331
Sagar Yadav
77,934,699
5,267,751
How can I prevent the cell from being run if some conditions are satisfied in IPython shell?
<p>Assume I run the following code in IPython interactive shell:</p> <pre class="lang-py prettyprint-override"><code>def pre_run_cell(info): raise RuntimeError(&quot;please don't run&quot;) get_ipython().events.register(&quot;pre_run_cell&quot;, pre_run_cell) </code></pre> <p>Then, each time before a cell is run, ...
<python><ipython>
2024-02-04 05:30:03
1
4,199
user202729
77,934,581
8,035,425
ppo_trainer generate and training step is extremely slow
<p>I am running the code exactly as shown in this Github repo: <a href="https://github.com/joeljang/RLPHF/blob/main/training/rlhf.py" rel="nofollow noreferrer">https://github.com/joeljang/RLPHF/blob/main/training/rlhf.py</a></p> <p>For some reason, this code block:</p> <pre><code>for steps, batch in tqdm(enumerate(ppo_...
<python><machine-learning><pytorch><large-language-model>
2024-02-04 04:17:33
0
539
dooder
77,934,327
1,398,834
HTMX and Flask form can only Submit once
<p>I am working on a simple web app using HTMX and Flask, I have my <code>app.py</code> set up as follows:</p> <pre><code>from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/submit', methods=['POST']) def submit(): ...
<python><flask><htmx>
2024-02-04 01:25:33
2
2,097
FlameDra
77,934,324
1,646,928
Importing Library in Python does not work
<p>Using both Visual Studio 1.86.0 and Microsoft Visual StudioΒ Community 2022 the error is the same:</p> <pre><code>Import &quot;lxml&quot; could not be resolvedPylancereportMissingImports </code></pre> <p>Trying this basic example from Android tutorial:</p> <pre><code>from lxml import html html_content = &quot;&quot;...
<python><pip>
2024-02-04 01:22:03
0
529
JamesB
77,934,209
1,192,335
docker compose asyncio.sleep block statements before
<p>I've been beating myself to solve this problem that seems very weird. Consider this python code:</p> <pre class="lang-py prettyprint-override"><code>import asyncio async def main(): print(&quot;hello&quot;) await asyncio.sleep(10) print(&quot;world&quot;) asyncio.run(main()) </code></pre> <p>I'd like t...
<python><docker-compose><python-asyncio>
2024-02-04 00:18:13
2
951
elaich
77,934,099
2,905,108
Tileable object placement algorithm
<p>I've used noise algorithms like Perlin noise that produce textures that are tileable. I'm working on a tool for randomly placing objects on a canvas. The problem is the results do not tile i.e. if I take the image and repeat it on a grid, there are clear seams.</p> <p>What I have so far is very basic:</p> <pre><code...
<python><algorithm>
2024-02-03 23:19:48
1
487
Gordon13
77,934,004
823,859
Prevent pip in conda environment from using a global install
<p>I am trying to install a number of packages within a <code>conda</code> environment, using <code>pip</code>. I installed <code>pip</code> within the <code>conda</code> environment, as well.</p> <p>However, a while ago I must have installed some of these packages globally. <code>pip</code> is using these global insta...
<python><pip><anaconda><conda>
2024-02-03 22:42:19
1
7,979
Adam_G
77,933,879
7,347,925
How to submit response for Google Invisible reCaptcha?
<p>I'm trying to log into website like this: <a href="https://google-invisible-captcha-m2.magento-demo.amasty.com/customer/account/create/" rel="nofollow noreferrer">https://google-invisible-captcha-m2.magento-demo.amasty.com/customer/account/create/</a></p> <p>It is easy to get the site key info:</p> <pre><code> ...
<python><selenium-webdriver><web-scraping><recaptcha><invisible-recaptcha>
2024-02-03 21:53:16
0
1,039
zxdawn
77,933,809
313,768
Neato output for Mrecord produces significant overlap
<p>Given this demo graph, it renders (vaguely) well in the default engine, and awfully in Neato:</p> <pre class="lang-py prettyprint-override"><code>import graphviz a = [ [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0], [0, 0], [0, 0], [0, 18.442211], [0, 1.5577889]], ] e = [ [0, 7.878787...
<python><graphviz><neato>
2024-02-03 21:26:40
3
16,660
Reinderien
77,933,780
10,574,250
xlsxwriter .add_table() set columns works for one dataframe but not the other
<p>I am trying to add a data table in Excel using python library xlsxwriter</p> <p>My Dataframe named <code>whole</code> has 26 columns (exactly the letters in the alphabet) and so I am trying to set them using this code:</p> <pre><code>workbook = xlsxwriter.Workbook(f'workbook.xlsx', {&quot;nan_inf_to_errors&quot;: Tr...
<python><xlsxwriter>
2024-02-03 21:19:01
1
1,555
geds133
77,933,542
13,783,624
Running one jupyter notebook from another and passing arguments with magic commands
<p>I am unable to pass arguments and or access variables from one jupyter notebook to another:</p> <h1>using %run with args</h1> <p>First issue I am having is not being able to pass arguments from one notebook to another when using the %run magic command. <a href="https://ipython.readthedocs.io/en/stable/interactive/ma...
<python><jupyter-notebook><jupyter>
2024-02-03 20:02:37
1
331
Duke3e33
77,933,490
1,091,935
How to validate custom encoded data using @field_validator in Pydatic?
<p>I am trying to use a custom encoder and decoder in Pydantic (V2). My goal is to convert a reference to another class into its name instead of encoding the whole class and all its children, and resolve it back to the class instance when the JSON is decoded. Example:</p> <pre><code>from pydantic import BaseModel, fiel...
<python><validation><types><pydantic>
2024-02-03 19:44:05
1
518
DirkR
77,933,460
5,790,653
python telegram bot conversationbot horizontal buttons instead of vertical
<p>In <a href="https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/conversationbot.py" rel="nofollow noreferrer">this sample</a>, it show buttons like this:</p> <pre><code>Number1ToChoose Number2ToChoose Number3ToChoose Number4ToChoose Number5ToChoose </code></pre> <p>While I'm going to see ...
<python><telegram><telegram-bot><python-telegram-bot>
2024-02-03 19:32:48
1
4,175
Saeed
77,933,446
4,408,275
Independently set Label width of Frames in multi-frame tkinter App
<p>I want to create a GUI, that has two labels at the bottom of the GUI for status (<code>Status 0</code> and <code>Status 1</code>) and the the upper part of the GUI, that has all the GUI stuff of the main application.</p> <p>Basically the GUI layout should look like this:</p> <pre><code>┏━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━...
<python><user-interface><tkinter>
2024-02-03 19:29:09
1
1,419
user69453
77,933,376
6,837,086
TypeError: 'type' object is not subscriptable in Airflow timetable overridden serialize method
<p>I am trying to implement a parameterized timetable following this <a href="https://airflow.apache.org/docs/apache-airflow/stable/howto/timetable.html#parameterized-timetables" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-airflow/stable/howto/timetable.html#parameterized-timetables</a> and I am g...
<python><airflow><timetable>
2024-02-03 19:10:34
2
307
Luis Lema
77,933,206
3,179,179
pyproject.toml dynamic version dependency
<p>I have a Python package (aabbcc) in namespace form consisting of two sub-packages (aabbcc-core, aabbcc-aws) that I am converting over to pyproject.toml format for packaging. I would like them to be versioned together and I got that to work using dynamic version reference pointing to a text file VERSION - below is my...
<python><setuptools><pyproject.toml>
2024-02-03 18:13:17
1
441
Aleksandr Krymskiy
77,932,948
7,408,848
purpose of variable annotation in python
<p>Trying to understand the rationale for using annotations in python. I have come across code that looks like this</p> <pre><code>import logging logger: logging.Logger = logging.getLogger(__name__) def example(a,b): return a+b if __name__ == '__main__': example() </code></pre> <p>vs</p> <pre><code>logger = l...
<python><python-typing>
2024-02-03 16:49:44
0
1,111
Hojo.Timberwolf
77,932,884
14,824,108
Histogram without vertical separation lines and with custom contour width
<p>I'm wondering how to obtain the following result in <code>plotly</code> for histograms, i.e. no vertical lines displayed and a custom line width for contour</p> <p><a href="https://i.sstatic.net/CmhSE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CmhSE.png" alt="enter image description here" /></a><...
<python><plotly><histogram>
2024-02-03 16:28:32
1
676
James Arten
77,932,861
630,517
pipenv: Permission denied for ~/.local/share/virtualenvs
<p>I'm working with a codebase that uses pipenv to install dependencies as part of its setup. However, I'm getting the following error when the <code>pipenv install --deploy --dev</code> command is run:</p> <p><code>PermissionError: [Errno 13] Permission denied: '/Users/XXX/.local/share/virtualenvs'</code></p> <p>I've ...
<python><macos><pipenv>
2024-02-03 16:22:34
2
1,129
Joshua Sullivan
77,932,770
1,612,986
scipy optimize.root_scalar() with multiple arguments each being a list
<pre><code>def f(m_l, m_B, y): value = -1.0 + np.sum(m_l*np.exp(-m_B*y)) return value def df(m_l, m_B, y): value = -np.sum(m_B*m_l*np.exp(-m_B*y)) return value </code></pre> <p>where m_l and m_b is a numpy array. I use give the following input</p> <pre><code> m_l = np.array([0.0036132256153053369,0....
<python><scipy><root-finding>
2024-02-03 15:55:15
1
1,415
user1612986
77,932,526
4,788,546
Setting GStreamer custom logging from Python triggers Segmentation fault
<p><strong>Notes</strong>:</p> <ul> <li><p>That there's already an (almost) identical question, but I wanted to give more context (and marked that one as a duplicate)</p> </li> <li><p>I'll be comparing log levels (probably using terms like: <em>lower</em>, <em>higher</em>, <em>smaller</em>, <em>greater</em>, <em>decrea...
<python><c><gstreamer><pygobject><nvidia-deepstream>
2024-02-03 14:47:35
1
41,517
CristiFati
77,932,375
16,374,636
Loading from list of tuples fails
<p>I am trying to load a list of tuples into a <code>pl.Dataframe</code>.</p> <pre class="lang-py prettyprint-override"><code>data = [ (1, UUID('some-uuid'), None, datetime.datetime(2023, 2, 3, 6, 18, 11), None, 24040228, None, 0.0625, False, &lt;Fruit.BANANA: 'BANANA'&gt;, None), ] pl.DataFrame(data, orient='row')...
<python><dataframe><python-polars>
2024-02-03 14:03:05
1
407
zacko
77,932,262
6,842,112
Flask/Python: localhost => ok, Heroku => error
<p>I read <a href="https://stackoverflow.com/questions/40714887/flask-web-app-getting-error-on-heroku-but-working-on-localhost">this</a>, <a href="https://stackoverflow.com/questions/50711572/heroku-runs-ok-local-but-deployment-app-crash-flask-and-python">this</a>, <a href="https://stackoverflow.com/questions/20772104/...
<python><flask><heroku>
2024-02-03 13:30:36
0
921
Maryna K.
77,932,167
6,109,283
SPI connection in Docker containerβ€”permission denied
<p>I have a Raspberry Pi Zero W (armv6) and an RFID MFRC522 module. I can use it fine from Python as follows:</p> <pre class="lang-py prettyprint-override"><code>import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 reader = SimpleMFRC522() try: id = reader.read()[0] print(&quot;The ID for this card is:&q...
<python><docker><raspberry-pi><spi>
2024-02-03 12:59:05
0
410
AlvaroP
77,931,910
1,194,864
Process data in panda frame and replace nan with zero
<p>I do have a spreadsheet file that I would like to process read some of the columns sequentially and perform some calculations per row. To make my life easier I will need to replace all the nan values with zero to perform the calculations. So my code looks like:</p> <pre><code>df = pd.read_csv('documents/doc.csv', er...
<python><pandas>
2024-02-03 11:31:33
1
5,452
Jose Ramon
77,931,704
6,282,576
decorator declared and used inside of class
<p>I wrote a manager class to interact with Metabase and I wish to write a decorator inside this class to renew sessions if they're expired.</p> <pre class="lang-py prettyprint-override"><code>import requests from datetime import datetime, timedelta from typing import Callable, Any from urllib.parse import urljoin fr...
<python><python-decorators>
2024-02-03 10:23:41
0
4,313
Amir Shabani
77,931,620
3,628,119
How to avoid O(n+1) problem with peewee object?
<p>I have these following models in peewee:</p> <p>db.py</p> <pre><code>class Item(BaseModel): item_id = IntegerField() item_name = CharField() class Sales(BaseModel): sales_id = IntegerField() class SalesItem(BaseModel): sales_item_id = Integer_Field() sales = ForeignKeyField(Sales, backref='item...
<python><peewee>
2024-02-03 09:55:01
2
357
user3628119
77,931,609
5,091,467
Why does pandas sum() give wrong answers for Sparse dataframe?
<p>In a <code>Sparse</code> dataframe, the <code>sum()</code> method applied on the whole dataframe gives wrong results, while <code>sum()</code> applied to specific column or to a dataframe subset works.</p> <p>It looks like an overflow issue for <code>sum()</code> when applied to the whole dataframe, since type <code...
<python><pandas><sum><sparse-matrix><integer-overflow>
2024-02-03 09:52:34
1
714
Dudelstein
77,931,440
1,795,245
View value in Data Viewer stopped showing - view Dataframes
<p>Yesterday it worked, but now it has stopped working. <br /><br /><a href="https://i.sstatic.net/YxccO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YxccO.png" alt="Menu" /></a><br /><br />It's probably something simple that I've missed. I've restarted the computer, checked that I have Jupyter instal...
<python><visual-studio-code>
2024-02-03 08:54:27
1
649
Jonas
77,931,366
4,710,828
What is "python-fwf" engine in pandas read_csv() method and when to use it?
<p>I was going through the pandas documentation, and going through read_csv() method <a href="https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html" rel="nofollow noreferrer">here</a>, I saw that the latest version (2.2 stable) mentions only 3 engines:</p> <pre><code>engine: {β€˜c’, β€˜python’, β€˜pyarrow’}, opti...
<python><pandas>
2024-02-03 08:27:10
1
373
sdawar
77,931,280
1,129,194
String representation of nested function with stackframe/inspection
<p>I am working on generating a call graph for a large codebase, and I would like to generate a nice string representation for nested functions/closures - e.g. something like <code>Test.a.b</code> for this function:</p> <pre class="lang-py prettyprint-override"><code>class Test: def a(self): def b(): ...
<python><trace>
2024-02-03 07:48:18
1
9,013
Alex L
77,931,118
6,837,086
TypeError: __init__() missing 2 required positional arguments in Airflow timetable
<p>I am trying to implement a parameterized timetable following this <a href="https://airflow.apache.org/docs/apache-airflow/stable/howto/timetable.html#parameterized-timetables" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-airflow/stable/howto/timetable.html#parameterized-timetables</a> and I am g...
<python><airflow><timetable>
2024-02-03 06:45:20
1
307
Luis Lema
77,930,942
5,324,306
Sum of frequency/probability distributions vs convolutions
<p>From my understanding, the sum of independent random variables will be the same as the convolution of the input distributions.</p> <p>However, when experimenting with it, I see the distribution of the sum of the variables does not match that of the convolution result.</p> <p>For example: The sum of two independent r...
<python><numpy><scipy><probability><convolution>
2024-02-03 05:08:47
1
1,090
JackDaniels
77,930,920
7,662,164
JAX `vjp` fails for vmapped function with `custom_vjp`
<p>Below is an example where a function with a custom-defined vector-Jacobian product (<code>custom_vjp</code>) is <code>vmap</code>ped. For a simple function like this, invoking <code>vjp</code> fails:</p> <pre><code>@partial(custom_vjp, nondiff_argnums=(0,)) def test_func(f: Callable[..., float], R: Arr...
<python><vectorization><jax><automatic-differentiation>
2024-02-03 04:56:18
1
335
Jingyang Wang
77,930,695
11,277,108
Output the result of an input generator and then the result of a translation of the result of the generator
<p>The following code:</p> <pre><code>def test(x): for i in x: yield i i = list(i) i[1] = &quot;X&quot; yield tuple(i) list(test(it.product([&quot;A&quot;, &quot;B&quot;], [&quot;C&quot;]))) </code></pre> <p>Outputs the following list:</p> <pre><code>[('A', 'C'), ('A', 'X'), ('B', '...
<python><generator><python-itertools>
2024-02-03 02:37:42
1
1,121
Jossy
77,930,656
13,498,838
How to Schedule Async Coroutine Functions with APScheduler?
<p>I am developing a service in Python to send automated emails and am facing challenges with scheduling asynchronous coroutine functions using <strong>APScheduler</strong>. The service is built with <strong>FastAPI</strong> to handle user inputs and <strong>aiomysql</strong> for asynchronous database operations. My go...
<python><python-asyncio><apscheduler>
2024-02-03 02:17:19
0
1,454
jda5
77,930,609
2,840,697
How to change column values as new column in python pandas
<p>I have a table like</p> <pre><code> Name Class Rank Karl Math 1 George English 1 Karl English 2 George Math 3 Rex Math 2 Rex English 3 </code></pre> <p>to change to something like</p> <pre><code> Name Math English ...
<python><pandas>
2024-02-03 01:43:52
1
942
user98235
77,930,212
22,674,380
Multitask learning to classify on dog images
<p>I'm trying to train a multitask classification model (mobilenet). Basically, a single model that given an image of a dog, it classifies both the color and the breed. Each dataset simply has directories for each class, and images inside those classes. <a href="https://filebin.net/5or5r8h2mswzbmhe" rel="nofollow noref...
<python><tensorflow><keras><deep-learning><classification>
2024-02-02 22:43:46
1
5,687
angel_30
77,930,211
16,717,009
Removing duplicates in a Pandas dataframe for only a specified value
<p>Let's say I have a dataframe:</p> <pre><code>df = pd.DataFrame({ 'ID': [1, 2, 3, 1, 2, 3], 'Value': ['A', 'B', 'A', 'B', 'C', 'A'] }) </code></pre> <p>If I wanted to only remove duplicates on ID when ID is a specified value (let's say 1), how would I do that? In other words, the resulting dataframe would loo...
<python><pandas><dataframe>
2024-02-02 22:43:26
1
343
MikeP
77,930,209
5,790,653
python how to add new key in dictionary with range function
<p>This is json file:</p> <pre class="lang-json prettyprint-override"><code>[ {&quot;name&quot;: &quot;Saeed&quot;}, {&quot;name&quot;: &quot;Joseph&quot;}, {&quot;name&quot;: &quot;Mary&quot;}, {&quot;name&quot;: &quot;Peter&quot;} ] </code></pre> <p>I'm going to iterate over it and then add a new key called <...
<python>
2024-02-02 22:43:24
2
4,175
Saeed
77,930,157
594,355
python: Incorrect(?) time difference between `datetime` objects spanning a daylight saving time change
<hr /> <p>(edited to add)</p> <p><strong>PROLOG:</strong> Today I became aware of the concept of &quot;wall time&quot;. I will always and forever consider it harmful.</p> <hr /> <p>I have two <code>datetimes</code>, one representing a certain time-of-day just before a time change, and the other representing the same t...
<python><datetime><dst>
2024-02-02 22:29:55
2
739
smcdow
77,930,099
2,142,728
Python generics for Scala programmers
<p>I come from the Scala world where the type system allows for very powerful abstractions.</p> <p>What I'm trying right now is very simple, yet the Python mechanisms are confusing me a lot: I want to create a type alias that swaps the type params of a <code>dict</code>.</p> <p>In Scala I can do:</p> <pre class="lang-s...
<python><mypy><python-typing>
2024-02-02 22:12:33
2
3,774
caeus
77,930,086
736,479
How to alter python's json encoder to convert NaN to None
<p>Say I have this (all this is Python 3.11 in case that matters):</p> <pre><code>not_a_number = float(&quot;NaN&quot;) # this actually comes from somewhere else json.encode([not_a_number]) </code></pre> <p>The output is an (invalid) JSON literal <code>NaN</code>. I've been trying to create an JSONEncoder subclass tha...
<python><jsonencoder>
2024-02-02 22:07:49
1
619
machomeautoguy
77,930,045
1,574,054
Randomly run "a few" tests with pytest
<p>I am working on a numeric calculation application and have two sets of &quot;unit&quot; tests. &quot;Fast&quot; tests which run in &lt; 10ms per tests and &quot;long&quot; tests which take several minutes per test. Let's assume that this is necessary here, for example, when testing an example for the integration of ...
<python><testing><pytest>
2024-02-02 21:55:59
3
4,589
HerpDerpington
77,930,020
5,790,653
python load json file and print values in different line
<p>This is <code>file.json</code>:</p> <pre><code>[ {&quot;date&quot;: &quot;1402/11/03&quot;, &quot;time&quot;: &quot;18-21&quot;, &quot;count&quot;: 5}, {&quot;date&quot;: &quot;1402/11/04&quot;, &quot;time&quot;: &quot;12-15&quot;, &quot;count&quot;: 2}, {&quot;date&quot;: &quot;1402/11/05&quot;, &quot;t...
<python>
2024-02-02 21:50:46
1
4,175
Saeed
77,929,999
11,277,108
How to generate name combinations with initials
<p>Given a string of a person's name:</p> <pre><code>&quot;Richard David&quot; </code></pre> <p>I'd like to create a list of all combinations of this name where up to all but one of the individual names are replaced with initials:</p> <pre><code>[ &quot;Richard David&quot;, &quot;R David&quot;, &quot;Richar...
<python>
2024-02-02 21:46:05
3
1,121
Jossy
77,929,966
20,006,915
Performance of Sorting Output of Database (python/sqlite)
<p>I'm writing a function to output certain fields of data within a database, based on a provided sort key. The key signals to the function if the output should be sorted by either title, year or budget (these are the only 3 attributes which need to be displayed).</p> <p>Example database:</p> <pre><code>ID | name | ye...
<python><database><sqlite>
2024-02-02 21:37:38
0
536
Jackxx
77,929,959
9,560,908
com_error (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352561), None)
<p>I'm writing a python script that interfaces with a VBA project and I've encountered this error:</p> <pre><code>C:\Python37\lib\site-packages\win32com\client\dynamic.py in Add(self, Type, Operator, Formula1, Formula2, String, TextOperator, DateOperator, ScopeType) com_error: (-2147352567, 'Exception occurred.', (0, ...
<python><excel><vba>
2024-02-02 21:35:29
1
648
Terry Davis