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,194,916
13,491,504
Lambdify order of variables
<p>When I use <code>lambdify</code> to turn a sympy function into one that can be used numerically, I need to pass the variables in the function as the first argument. I know that the number of Arguments is important, but is the order also important? How do I know, which letter is assigned to which variable in the orig...
<python><sympy><lambdify>
2024-03-20 16:25:22
1
637
Mo711
78,194,891
2,612,235
Tox doesn't find pyproject.toml?
<p>It seems that I cannot manage <code>tox</code> to see my <code>pyproject.toml</code>. I've created a minimal example:</p> <pre><code>$ mkdir test $ cd test $ cat &lt;&lt;EOF &gt; pyproject.toml [build-system] requires = [&quot;cython&quot;, &quot;setuptools&quot;, &quot;wheel&quot;] build-backend = &quot;setuptools....
<python><tox><pyproject.toml>
2024-03-20 16:23:11
2
29,646
nowox
78,194,843
3,442,125
How can I get the local curvature of a scipy.CubicSpline?
<p>I'm using the scipy.interpolate.CubicSpline to compute a 2d function and want to analyse the curvature of the graph. The CubicSpline can compute a first and second derivative and my approach was to use curvature as k(t) = |f''(t)| / (1+f'(t)**2)**1.5 (<a href="https://math.stackexchange.com/questions/1155398/differe...
<python><scipy><spline>
2024-03-20 16:15:31
1
867
FooTheBar
78,194,811
4,635,470
script not working when arguments used from argparse rather than defaults
<p>I have tried to write a python script to extract zip files, copy to a directory and create PR. The default behaviour is to use no arguments and just use the defaults. When I do this it works perfectly. However when I pass the arguments <code>-z</code> or <code>-f</code> I get the following error:</p> <pre><code>235:...
<python>
2024-03-20 16:09:55
1
855
eekfonky
78,194,660
4,865,723
Differentiate between optional and mandatory in Python's argparse
<p>See this example:</p> <pre><code>#!/usr/bin/env python3 import argparse import sys def main(): parser = argparse.ArgumentParser() parser.add_argument('input', type=str) parser.add_argument('-d', '--debug', action='store_true') parser.add_argument('--version', action='version', version='0.1.2') ...
<python><argparse>
2024-03-20 15:46:11
0
12,450
buhtz
78,194,648
9,930,052
How to start a function in a python/propy script via c#?
<p>My python script (c:\Temp\StartPython\test.py) looks like this:</p> <pre><code>import arcpy import string, sys, os import ctypes logfile =&quot;C:\\Temp\\StartPython\\Logfile.log&quot; def Main(dataset): print (&quot;Started with argument &quot; + dataset) datei = open(logfile,'a') datei.write(&quot;St...
<python><c#><conda><arcgis>
2024-03-20 15:43:52
1
403
Gener4tor
78,194,480
4,380,772
Convert Python Flask Webservice to Windows Service
<p>I am very new to Python. I have a flask API written and I am facing some issues with that. I want to run this API in a server and initially I planned to create a bat file and run the service in the task scheduler. However I ran into some file permissions issues. I have a code snippet which generates the log file in ...
<python><flask>
2024-03-20 15:19:55
0
1,667
Karthik Venkatraman
78,194,368
301,774
roc_auc_score differs between RandomForestClassifier GridSearchCV and explicitly coded RandomForestCLassifier
<p>Why doesn't a trained <code>RandomForestClassifier</code> with specific parameters match the performance of varying those parameters with a <code>GridSearchCV</code>?</p> <pre><code>def random_forest(X_train, y_train): from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import Gr...
<python><scikit-learn><random-forest><gridsearchcv><auc>
2024-03-20 15:02:53
0
6,896
akaphenom
78,194,254
3,194,618
Using pyarrow.DictionaryArray instead of Categorical in pandas DataFrame
<p>I'm evaluating the possibility of using arrow-based data types in our data flows.</p> <p>Our flows are based on pandas and using <code>dtype_backend='pyarrow'</code> seems working pretty well (basically this options prioritize the arrow type in constructors). I'm finding some problems using <code>pyarrow.Dictionary...
<python><pandas><pyarrow>
2024-03-20 14:47:03
0
1,479
Glauco
78,194,178
8,618,380
GCP function to function HTTP call
<p>I am trying to call a GCP function (B) from another GCP function (A).</p> <p>So far, I have:</p> <ul> <li>Created a service account and granted function invoker role</li> <li>Added to function B the service account as Function Admin</li> <li>Downloaded a json key for the created service account</li> <li>Tried to run...
<python><google-cloud-platform><google-cloud-functions>
2024-03-20 14:36:39
1
1,975
Alessandro Ceccarelli
78,194,173
10,764,260
2D PointCloud Visualization in Python
<p>I have some 3D objects from ikea furniture and I would like to sample point clouds and display them as 2D image. In the PointNet Paper (<a href="https://arxiv.org/abs/1612.00593" rel="nofollow noreferrer">https://arxiv.org/abs/1612.00593</a>) they used a very nice visualization:</p> <p><a href="https://i.sstatic.net...
<python><matplotlib><point-clouds>
2024-03-20 14:35:47
0
308
Leon0402
78,193,859
1,668,622
What's a straightforward way to split a string on 'top level' only, regarding quotes and parentheses?
<p>I want to provide a function which takes a comma-separated string and splits it on separators, similar to <code>str.split()</code> but keeping (potentially nested) quoted and parenthesized parts. Examples include comma-separated key-value pairs (<code>a=b,c=d</code>) but also comma-separated shell commands which mig...
<python><csv><parsing><split>
2024-03-20 13:48:38
2
9,958
frans
78,193,854
6,714,667
Cannot find package "tests"
<p>i imported following:</p> <pre><code>from office365.sharepoint.client_context import ClientContext from tests import test_user_credentials, test_team_site_url </code></pre> <p>however &quot;tests&quot; is not recognized (Import tests could not be resolved) it's not clear what package needs to be installed. i pip in...
<python><sharepoint>
2024-03-20 13:48:02
1
999
Maths12
78,193,760
5,539,674
Understanding JSONDecodeError when using JsonOutputParser
<p>I am just getting started with output-parsers and I'm impressed with their usefulness when they work properly. I have, however, run into a case where every now and then, a chain returns an error that seems to be related to the JsonOutputParser that I use, as indicated by the following (condensed) error message:</p> ...
<python><langchain>
2024-03-20 13:35:56
1
315
O René
78,193,630
1,552,080
Python Pandas grouping DataFrame by blocks of sequential values
<p>I have a large pandas DataFrame having a timestamp column, a value column, a &quot;key&quot; column and a column with a flag indicating end of a block (and some more actually)</p> <pre><code>timestamp, value, key, last_in_block 12345, 1.0, 2, False &lt;-- start of block 1 12346, 0.5, 4, False 12347, 1.2, 1, False 12...
<python><pandas><group-by>
2024-03-20 13:17:31
2
1,193
WolfiG
78,193,572
3,907,561
Why so many python built-in functions has no in-code docs?
<p><code>train_kwargs</code> is a standard python <code>dict</code>, I don't know what does <code>update(...)</code> do, is it merge the new kwargs into itself or replace all key-values?</p> <p>So much so that I had to open the browser to check the official online documentation, which seriously affected my efficiency.<...
<python>
2024-03-20 13:09:17
1
1,167
huang
78,193,562
1,498,389
setuptools.package-data has no effect within a docker container
<p>So, I have this little pyproject.toml-based project (named <code>RecordEcos</code>) to do multi-camera recording with a minimalist interface (using PySimpleGUI). The interface make use of a placeholder image when the camera are not connected.</p> <p>I've added the following section to my pyproject.toml to ensure the...
<python><setuptools><pyproject.toml>
2024-03-20 13:07:39
1
5,140
NiziL
78,193,430
3,917,215
Generating graph like structure based on multiple columns using Python
<p>I have a dataframe with the following columns: Node1, Node2, Node1_REV, and Node2_REV. In this structure, Node1 serves as a parent node, while Node2 functions as a child node. Both Node1_REV and Node2_REV capture different revisions of their respective nodes. ChildNode values may possess their own child values, indi...
<python><pandas><dataframe>
2024-03-20 12:47:28
2
353
Osceria
78,193,207
9,251,158
How to add a specific number of silent samples to an audio file
<p>I am manipulating audio with pydub for use with video. I want to pad the end of an audio segment with silent frames so it fills a frame of video. At an audio sampling rate of 48kHz and a video sampling rate of 25 fps, I need each audio segment to have a multiple of 1920 samples (= 48 000 / 25).</p> <p>I followed <a ...
<python><audio><pydub>
2024-03-20 12:12:32
0
4,642
ginjaemocoes
78,193,123
16,525,263
How to use window function in pyspark dataframe
<p>I have a pyspark dataframe as below:</p> <pre><code>Mail sno mail_date date1 present abc@abc.com 790 2024-01-01 2024-02-06 yes abc@abc.com 790 2023-12-23 2023-01-01 nis@abc.com 101 2022-02-23 nis@abc.com 101 2021-01-20 202...
<python><apache-spark><join><pyspark>
2024-03-20 11:59:47
2
434
user175025
78,192,929
3,433,875
ax.get_position wont give me position of all plots on multiple subplots
<p>I am trying to overlap a matrix of subplots.</p> <p>The code I am using is:</p> <pre><code>fig, axes = plt.subplots(ncols =2, nrows = 2, figsize=(8,8), sharey=True, facecolor = &quot;#FFFFFF&quot;, subplot_kw=dict(polar=True) ,constrained_layout=True) fig.tight_layout(h_pad=-5) directions = [1,-1] for ax,direction...
<python><matplotlib>
2024-03-20 11:31:46
0
363
ruthpozuelo
78,192,905
1,194,864
Unexpected printouts interfere with tqdm progress bar in PyTorch training run
<p>I am trying to understand how the progress bar using <code>tqdm</code> works exactly. I have some code that looks as follows:</p> <pre><code>import torch import torchvision print(f&quot;torch version: {torch.__version__}&quot;) print(f&quot;torchvision version: {torchvision.__version__}&quot;) load_data() manual_tr...
<python><pytorch><tqdm>
2024-03-20 11:27:57
1
5,452
Jose Ramon
78,192,787
1,439,597
Celery worker container never restarts after getting MemoryError
<p>I am getting this annoying issue on my production machine, where I have a docker container for my celery container, configured like this:</p> <pre><code>worker: build: . env_file: - .env command: celery -A my_app worker --loglevel=info --concurrency 1 -E deploy: restart_policy: co...
<python><docker><docker-compose><celery><out-of-memory>
2024-03-20 11:07:03
1
4,850
SylvainB
78,192,584
3,212,623
Running AWS SAM locally throws aws_lambda_powertools not found
<p>I am trying to setup AWS SAM python project with <code>aws-lambda-powertools</code>. I have added the <code>aws-lambda-powertools</code> to requirements as well. When I deploy it to AWS, the import of <code>aws-lambda-powertools</code> works fine. However, when running locally <code>sam local start-api -t template.y...
<python><amazon-web-services><aws-lambda><aws-sam><aws-sam-cli>
2024-03-20 10:36:41
1
3,165
pnv
78,192,496
2,102,290
cdktf lifecycle ignore_changes doesn't seem to work for tags
<p>I have a terraform stack that is managed using the python version of <code>cdktf</code> where each instance has some tags associated with it, something like:</p> <pre class="lang-py prettyprint-override"><code>start_time = datetime.now(timezone.utc).strftime(&quot;%Y-%m-%d %H:%M&quot;) self.instance = Instance( ...
<python><terraform><terraform-cdk>
2024-03-20 10:23:04
0
582
Michael
78,192,477
13,954,738
Unexpected keyword argument 'as_tuple' error in Flask even after upgrading werkzeug version to 2.0.3
<p>While I am testing my API I recently started to get the error below.</p> <pre><code> if request is None: &gt; builder = EnvironBuilder(*args, **kwargs) E TypeError: EnvironBuilder.__init__() got an unexpected keyword argument 'as_tuple' </code></pre> <p>Code:</p> <pre><code>@pytest.fixture...
<python><flask>
2024-03-20 10:20:47
0
336
ninjacode
78,192,426
6,649,591
How to use Solr as retriever in RAG
<p>I want to build a RAG (Retrieval Augmented Generation) service with LangChain and for the retriever I want to use Solr. There is already a python package <code>eurelis-langchain-solr-vectorstore</code> where you can use Solr in combination with LangChain but how do I define server credentials? And my embedding model...
<python><solr><fastapi><langchain>
2024-03-20 10:12:33
1
487
Christian
78,192,256
9,472,819
Decorated function call now showing warning for incorrect arguments in PyCharm
<p>I'm having some problems when static type checking decorated functions. For instance, when I use an incorrect function argument name or type, I don't get any warning or error hints in the IDE, only at runtime.</p> <p><strong>What steps will reproduce the problem?</strong></p> <ul> <li><p>Add a decorator to a functio...
<python><pycharm><decorator><python-typing>
2024-03-20 09:43:57
1
749
tomas-silveira
78,191,944
13,086,128
What is the difference between read, scan, and sink in polars?
<p>In polars I see methods are <code>read</code>, <code>scan</code> and <code>sink</code> for the input.</p> <p>For the output, we have <code>write</code>.</p> <p>What is the difference between <code>read</code>, <code>scan</code>, and <code>sink</code> ?</p> <p><a href="https://docs.pola.rs/py-polars/html/reference/io...
<python><python-3.x><python-polars>
2024-03-20 08:52:46
1
30,560
Talha Tayyab
78,191,890
2,625,540
Relative Import: No Known Parent Package
<p>I'm trying to do a relative import. From my understanding, I should have an <code>__init__.py</code> file to suggest this is a module.</p> <p>Let's say I have:</p> <pre><code>$ ls __init__.py foo.py bar.py </code></pre> <p><code>__init__.py</code> is an empty file. Additionally:</p> <pre><code>$ cat foo.py from .bar...
<python><python-import><importerror>
2024-03-20 08:43:12
1
744
pgierz
78,191,884
1,537,366
DuckDB pandas pass DataFrame by name easily with IntelliSense support
<p>In DuckDB, we have to directly use the DataFrame variable name as a string in the SQL syntax (as shown <a href="https://duckdb.org/2021/05/14/sql-on-pandas.html" rel="nofollow noreferrer">here</a>):</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import duckdb mydf = pd.DataFrame({'a' : [1, ...
<python><pandas><visual-studio-code><duckdb>
2024-03-20 08:41:50
1
1,217
user1537366
78,191,881
12,415,855
Accessing with python and sshtunnel not possible on Mac?
<p>i try to access my mysql-database using a sshtunnel in python with the following code -</p> <pre><code>import mysql.connector import sshtunnel if __name__ == '__main__': with sshtunnel.SSHTunnelForwarder( (&quot;xyz.a2hosting.com&quot;, 7822), ssh_username=&quot;myName&quot;, ssh_pas...
<python><macos><mysql-connector><ssh-tunnel>
2024-03-20 08:41:22
0
1,515
Rapid1898
78,191,857
6,930,340
pandas.to_parquet pyarrow.lib.ArrowInvalid: Could not convert Timedelta
<p>I have a huge multiindex dataframe in long format. There's only one &quot;value&quot; column. Some entries in &quot;value&quot; are of type <code>pd.Timedelta</code>.</p> <p>I got an error when trying to save that dataframe as <code>parquet</code> file using <code>pd.to_parquet</code>:</p> <p><code>pyarrow.lib.Arrow...
<python><pandas><parquet><pyarrow>
2024-03-20 08:37:23
2
5,167
Andi
78,191,580
1,866,775
How to catch potentially undefined variables with pylint or mypy?
<pre class="lang-py prettyprint-override"><code>import time if time.time() &gt; 42: x = 1 print(x) </code></pre> <p>My IDE (PyCharm) warns me about <code>x</code> potentially being undefined:</p> <p><a href="https://i.sstatic.net/cSFrR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cSFrR.png" alt=...
<python><python-3.x><mypy><lint><pylint>
2024-03-20 07:47:11
3
11,227
Tobias Hermann
78,191,505
4,427,777
`pandas` datetime - correct way to do linear interpolation
<p>FYI: <code>pandas</code> version is 1.3.4 for now</p> <p>I have currently working code to interpolate non-monotonous timestamps (along with various other data not sampled monotonously) into a dataframe <code>out</code> with a monotonous (float-type) time <code>index</code>. The important part is here:</p> <pre><cod...
<python><pandas><datetime><type-conversion><interpolation>
2024-03-20 07:32:51
0
14,469
Daniel F
78,191,480
231,934
Register jupyter variable from an another module
<p>I created simple cell magic function for calling AWS Athena</p> <pre><code>import awswrangler as wr import inspect import pandas as pd from IPython.core.magic import (register_line_magic, register_cell_magic, register_line_cell_magic) @register_cell_magic def athena(line, cell): ...
<python><jupyter-notebook>
2024-03-20 07:27:35
1
3,842
Martin Macak
78,191,390
7,217,896
GPT python SDK introduces massive overhead / incorrect timeout
<p>I've been using openai python packge v0.28.1 with the <code>requests_timeout</code> param which worked OK. I then updated to the ^1. version only to find out that the timeout no longer works as expected (they have changed the param name from <code>requests_timeout</code> to <code>timeout</code>.</p> <p>Here is an od...
<python><openai-api><chatgpt-api><gpt-4>
2024-03-20 07:04:28
1
3,778
NotSoShabby
78,191,273
1,581,090
How to create and use a virtual environment with PyCharm on windows?
<p>I am new to PyCharm and need to run pytests within a virtual environment using PyCharm 2023.3.4 (Community Edition) on Windows 10. I am following the documentation <a href="https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html#python_create_virtual_env" rel="nofollow noreferrer">HERE</a> which se...
<python><windows><pycharm>
2024-03-20 06:40:27
1
45,023
Alex
78,191,214
1,202,995
python to_bytes() to return an even number of digits
<p>I'm trying to convert an int (i.e. 3490) into 2 bytes via the <code>to_bytes()</code> function and instead of returning <strong>b'\x0d\xa2'</strong>, I'm getting <strong>b'\r\xa2'</strong>. What am I missing here and how can I get the former to return?</p>
<python><hex><byte>
2024-03-20 06:24:39
2
308
tehawtness
78,191,158
894,126
Selenium fetches first 4 elements while scraping
<p>Scraping code below only fetches 4 elements of &quot;price&quot;, however once page is fully loaded there are 71 price related elements on the page.</p> <p>Scraping code:</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By fr...
<python><python-3.x><selenium-webdriver>
2024-03-20 06:13:34
1
510
Ayub
78,190,677
9,855,588
building python package with parent folder in structure
<p>I'm building a python package that contains the following structure:</p> <pre><code>foo/ __init__.py bar_module_one/ __init__.py do_something_cool.py buzz_module_two/ __init__.py youre_lazy.py </code></pre> <p>In <code>setup.py</code> I have the following:</p> <pre><code>from setuptools import find_packag...
<python><python-3.x>
2024-03-20 03:06:24
1
3,221
dataviews
78,190,543
1,089,957
Can Cython be used to define C-callable variadic functions?
<p>I'm writing <a href="https://github.com/JesseTG/libretro.py" rel="nofollow noreferrer">a Python library</a> for testing DLLs that implement a particular C API. This library also exposes functionality to the native DLLs through callback functions fetched at runtime. There's a specific function I'd like to implement, ...
<python><c><cython><ctypes><variadic-functions>
2024-03-20 02:16:25
0
2,195
JesseTG
78,190,525
5,087,283
Reparameterizing a model in PyTorch
<p>I am trying to optimize the parameters of a simple model which is implemented using the PyTorch library. For the purpose of optimization, I would like to use a different representation of the parameters than that which is specified by the model class. I would like, in particular, to represent my parameters as a sing...
<python><tensorflow><deep-learning><pytorch>
2024-03-20 02:12:02
1
811
Metamorphic
78,190,411
10,146,441
How to preserve newline characters in CSH when storing in a variable or echo
<p>I have a <code>python</code> script which is getting called from a <code>csh</code> script ( I can not use <code>bash</code>). The python script prints out string with the newline characters and I am storing the output in a csh variable. However, as soon I store it in a variable, I am losing all the newline characte...
<python><echo><csh>
2024-03-20 01:28:23
1
684
DDStackoverflow
78,190,205
1,447,953
pandas: how to aggregate records into rolling time windows at a given frequency?
<p>Here is my data:</p> <pre><code>times = pd.date_range(start=pd.Timestamp.now(), end=pd.Timestamp.now() + pd.Timedelta(minutes=1), periods=61) data = np.arange(61) df = pd.DataFrame({'times': times, 'data': data}) </code></pre> <p>output:</p> <pre><code> times data 0 ...
<python><pandas><group-by><pandas-rolling>
2024-03-19 23:57:19
0
2,974
Ben Farmer
78,190,193
901,426
best method to improve awk speed in writing to sqlite3 db
<p>I have a device that runs BusyBox, has ONE processor available for client use, and needs to run as a flow pulse counter (among other things), catching zero or many pulses of 20ms in width at random intervals within each second.</p> <p>The device has a second processor walled off from the client dedicated to creating...
<python><bash><awk>
2024-03-19 23:54:19
0
867
WhiteRau
78,190,160
6,329,217
Local vs NonLocal Scope Python
<p>I am trying to understand scopes in Python and am confused in the examples below (I am using Python 3.12.2) -</p> <p>1.</p> <pre><code>a = 10 def myfunc(): a = 2 print(a) print(a) myfunc() </code></pre> <p>This gives the output -</p> <pre><code>10 2 </code></pre> <ol start="2"> <li></li> </ol> <pre><code>a...
<python><scope>
2024-03-19 23:41:53
0
362
Aditi Garg
78,190,082
12,309,386
Polars list of values based on intersection of different column list with another dataset
<p>I have a dataframe with <code>people</code> and the <code>food</code> they like:</p> <pre class="lang-py prettyprint-override"><code>df_class = pl.DataFrame( { 'people': ['alan', 'bob', 'charlie'], 'food': [['orange', 'apple'], ['banana', 'cherry'], ['banana', 'grape']] } ) print(df_class) s...
<python><dataframe><python-polars>
2024-03-19 23:11:21
2
927
teejay
78,190,020
543,572
How to reset a group of comboboxes back to no selection tkinter?
<p>I'm using ttkbootstrap with tkinter and I have 15 ttkbootstrap comboboxes that I want to reset to no selection if a button is pressed. I tried this code I found somewhere, but it does nothing. I did verify I'm hitting the function with a print statement though:</p> <pre><code>import tkinter from tkinterr import * ...
<python><tkinter><combobox><ttkbootstrap>
2024-03-19 22:48:54
1
15,801
James-Jesse Drinkard
78,190,016
4,302,855
MessageBox with Timer buttons that looks like messagebox.showwarn()
<p>I used the top answer at <a href="https://stackoverflow.com/questions/61841410/messagebox-pause-python">MessageBox pause - Python</a> to make a dialog box that has a timed 'OK' button on it. However, the box is pretty sad looking and I'd like it to look like a standard messagebox.showwarn() message box even taking a...
<python><tkinter>
2024-03-19 22:47:14
1
845
boymeetscode
78,189,710
2,599,861
How to read a parquet file with arrays by ROW instead of array elements?
<p>I am using tensorflow-io to read a parquet file. This parquet file contains columns with lists or maps. Following is an example of my dataset in duck db, as you can see, there is a timestamp column and two array columns.</p> <p><a href="https://i.sstatic.net/zfnl5.png" rel="nofollow noreferrer"><img src="https://i.s...
<python><tensorflow><machine-learning><tensorflow-io>
2024-03-19 21:21:26
0
588
André Claudino
78,189,699
9,415,280
how to get continuous date index base on the first index values on Pandas
<p>I got an df with this index, at some point the date change from 2024-03-03 to 2023-02-25. I want to replace the wrong part (2023...) by the logical extend of the correct one</p> <p>sample:</p> <pre><code>2024-02-23 -5.60000 2024-02-24 -13.00000 2024-02-25 -27.20000 2024-02-26 -4.20000 2024-02-27 -11.2000...
<python><pandas><datetime>
2024-03-19 21:19:17
1
451
Jonathan Roy
78,189,344
5,619,073
Short of modifying Python's source C, is there any way to add a new format character to the struct module's format specification mini-language?
<p>I'm reading data from machines using the Modbus protocol. If you're not familiar with Modbus, I envy you. More seriously though, Modbus is a low-level protocol that allows you to read &quot;registers&quot; from a machine by specifying a start address and a number of registers to read. A &quot;register&quot; is just ...
<python><struct><modbus>
2024-03-19 19:58:47
1
437
Nick Muise
78,189,208
14,619,971
How to get the result of an excel formula in Python?
<p>I need to execute the following excel formula in Python:</p> <pre><code>STDEV.S(A1:A3) </code></pre> <p>Tried this code:</p> <pre><code>from openpyxl import Workbook from openpyxl.formula import Tokenizer wb = Workbook() ws = wb.active ws['A1'] = 10 ws['A2'] = 20 ws['A3'] = 30 ws['B1'] = &quot;=STDEV.S(A1:A3)&quo...
<python><excel>
2024-03-19 19:32:31
2
829
jkfe
78,188,979
820,013
Define a protocol that mimics QFileSystemModel.index() and its overloads
<p>I'm trying to implement a protocol that mimics QFileSystemModel so that I can use that protocol to define a new custom class. The protocol definition is generating a mypy error when trying to make sure that protocol is satisfied by current QFileSystemModel derived class. Here is what I've tried...</p> <pre><code>im...
<python><mypy><pyqt6>
2024-03-19 18:46:21
0
4,674
shao.lo
78,188,957
613,913
Decode binary file in AWS environment using PySpark
<p>Is it possible to consume a Netezza backup file in AWS environment and load it to Redshift. File is a compressed binary file created using the below query. This file can also be produced using NZ_BACKUP utility in Netezza for a full database.</p> <pre><code>CREATE EXTERNAL TABLE 'C:\filename.bak' USING (remotesource...
<python><pyspark><aws-glue><binaryfiles><netezza>
2024-03-19 18:41:47
1
373
need_the_buzz
78,188,898
114,265
Is it possible to create a Python application that subscribes to parts of a firebase project
<p>I have a scenario where there is a firebase project, and I would like to monitor certain events that they make public.</p> <p>An event happens, and I would like to subscribe to that, and send out a notification. From what I can see with python there is the firebase_admin library, and I can call initialize. The issu...
<python><firebase>
2024-03-19 18:27:15
1
3,290
Brian S
78,188,760
3,305,998
How to separate rust library and exported python extensions which wrap it
<p>I have a rust library which provides useful functionality for use in other rust programs. Additionally I would like to provide this functionality as a python extension (using <a href="https://github.com/PyO3/pyo3" rel="nofollow noreferrer">pyo3</a> and <a href="https://setuptools-rust.readthedocs.io/" rel="nofollow ...
<python><rust><pyo3>
2024-03-19 18:01:57
0
318
MusicalNinja
78,188,758
1,439,748
Subtracting polygons and converting them to not have holes in python
<p>I have several blue and red polygons. I would like the red ones subtracted from the blue ones.</p> <p>After this is done, some remaining polygons may have holes. I'd like those polygons with holes converted to polygons without holes.</p> <h1>What I've tried so far</h1> <pre class="lang-py prettyprint-override"><code...
<python><polygon><shapely>
2024-03-19 18:01:40
1
3,804
LCIII
78,188,638
6,195,489
Fast way to convert 2d string numpy array to a 3d int array
<p>I have a very large numpy array with entries like:</p> <pre><code>[['0/1' '2/0'] ['3/0' '1/4']] </code></pre> <p>I want to convert it/ get an array with the 3d array like</p> <pre><code>[[[0 1] [2 0]] [[3 0] [1 4]]] </code></pre> <p>The array is very wide, so a lot of columns, but not many rows. And there are around...
<python><numpy><numba>
2024-03-19 17:38:20
4
849
abinitio
78,188,519
991,703
how do I recover an old python environment?
<p>I am in a bit of a problem, as a server was upgraded, and some old python environments are no longer working. I cannot just activate the environment, but I would like to create a new environment which is a replica of the old environment to the extent possible.</p> <p>This means installing on the new environment the ...
<python><virtualenv><python-venv>
2024-03-19 17:15:23
1
4,761
kloop
78,188,399
5,266,998
is there parallelism inside Ollama?
<p>Below Python program is intended to translate large English texts into French. I use a for loop to feed a series of reports into Ollama.</p> <pre><code>from functools import cached_property from ollama import Client class TestOllama: @cached_property def ollama_client(self) -&gt; Client: return C...
<python><docker><mistral-7b><ollama>
2024-03-19 16:55:42
2
2,607
Januka samaranyake
78,188,264
6,197,439
Adding breakpoint in pdb results with "End of file"?
<p>I'm so tired of this ...</p> <p>Well, <a href="https://stackoverflow.com/questions/46317180/pdb-set-a-breakpoint-on-file-which-isnt-in-sys-path">pdb: set a breakpoint on file which isn&#39;t in sys.path</a> says:</p> <blockquote> <p>According to <a href="https://stackoverflow.com/questions/23071175/how-to-set-breakp...
<python><breakpoints><pdb>
2024-03-19 16:31:31
1
5,938
sdbbs
78,188,105
827,927
Python type hints: what should I use for a variable that can be any iterable?
<p>Consider the function:</p> <pre><code>def mysum(x)-&gt;int: s = 0 for i in x: s += i return s </code></pre> <p>The argument <code>x</code> can be <code>list[int]</code> or <code>set[int]</code>, it can also be <code>d.keys()</code> where d is a dict, it can be <code>range(10)</code>, as well as a...
<python><python-typing>
2024-03-19 16:07:51
1
37,410
Erel Segal-Halevi
78,188,083
20,920,790
Why doesn't sns.barplot legend show all values?
<p>I have the following graph. Why does the last graph legend not contain all labels? It should contain these values:</p> <pre><code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 21] </code></pre> <p><a href="https://i.sstatic.net/x8rSt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/x8rSt.png" alt="en...
<python><matplotlib><seaborn><legend>
2024-03-19 16:04:49
1
402
John Doe
78,188,054
7,949,129
Selenium with Python does not print console.log messages
<p>My problem is, I can not see any of <em><strong>console.log, console.error, console.warning</strong></em> messages in my logs when I run this Python script:</p> <pre><code>import time from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support i...
<python><google-chrome><selenium-webdriver><logging><selenium-chromedriver>
2024-03-19 16:01:10
1
359
A. L
78,188,005
2,578,846
MLFlow search for a registered model is not working in R
<p>I would like to query registered models in mlflow using R api: <code>mlflow::mlflow_search_registered_models(filter=&quot;name='model_xyz'&quot;)</code>. But, it is throwing following error:</p> <pre><code>Error : API request to endpoint 'registered-models/search' failed with error code 404. Reponse body: 'ENDPOINT_...
<python><r><mlflow>
2024-03-19 15:53:22
0
3,071
Sijan Bhandari
78,187,861
12,320,370
Appending tuples returned by for loop
<p>I am running some SQL queries using sqlalchemy. I have a for loop that runs queries against Snowflake tables.</p> <p>Current Code:</p> <pre><code>for x in list: results = cursor.execute(f&quot;SELECT TABLE_NAME as TABLE_NAME, 'TABLE_SCHEMA as TABLE_SCHEMA, MAX(DATE) as DATE FROM {database}.{schema}.{table}&quot...
<python><list><sqlalchemy><tuples><snowflake-cloud-data-platform>
2024-03-19 15:32:38
1
333
Nairda123
78,187,747
12,107,239
How to Replace Pydantic's constr for use outside of BaseModel in FastAPI?
<p>I'm working with FastAPI and Pydantic for a project where I've used <code>constr</code> for string validation. This has been particularly useful for ensuring that string inputs adhere to specific constraints, like length and format, directly in the route function signatures.</p> <p><a href="https://i.sstatic.net/aPO...
<python><fastapi><pydantic>
2024-03-19 15:15:57
1
323
rcepre
78,187,625
3,651,529
See if pandas character column is in the string column
<p>I want to see, by row, if values of a char column are present in a string column.</p> <p>For example, in</p> <pre><code>df = pd.DataFrame({ 'char': ['A', 'B', 'A', 'C', 'D'], 'str': ['WCCC', 'BFC', 'GFA', 'E', &lt;NA&gt;] }) </code></pre> <p>I want to see if the 'char' column is in the 'str' column.</p> <p...
<python><pandas><string>
2024-03-19 14:58:40
3
6,252
kangaroo_cliff
78,187,376
22,466,650
How to make a regex orderless when validating a list of texts?
<p>My input is this dataframe (but it could be a simple list) :</p> <pre><code>import pandas as pd df = pd.DataFrame({'description': ['ij edf m-nop ij abc', 'abc ij mnop yz', 'yz yz mnop aa abc', 'i j y y abc xxx mnop y z', 'yz mnop ij kl abc uvwxyz', 'aaabc ijij uuu yz mnop']}) </code></pre> <p>I also have a list of ...
<python><pandas>
2024-03-19 14:21:18
1
1,085
VERBOSE
78,187,218
3,079,439
Converting Pandas DataFrame structure into Pytorch Dataset
<p>Have a question regarding Pytorch framework that I started to use recently (while always used keras/tf in the past).</p> <p>So I would like to convert simple pandas <code>DataFrame</code> to the pytorch <code>Dataset</code>.</p> <pre><code>import pandas as pd df = pd.DataFrame(np.array([[1, 2], [4, 5], [7, 8]]), co...
<python><pandas><pytorch>
2024-03-19 14:00:13
1
3,158
Keithx
78,187,120
13,086,128
Drop all the columns after a particular column
<p>Suppose, I am reading a csv with hundreds of columns.</p> <p>Now, I know that after a particular column say <code>'XYZ'</code> all the columns are junk.</p> <p>I want to keep all the columns from the beginning till column <code>'XYZ'</code> and drop all the columns after column <code>'XYZ'</code>.</p> <p>In pandas, ...
<python><python-3.x><python-polars>
2024-03-19 13:43:56
2
30,560
Talha Tayyab
78,187,045
4,537,160
Trying to install Python3.11 in Docker image based on nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04, getting html5lib error
<p>I'm using this Dockerfile:</p> <pre><code>FROM nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu20.04 ENV DEBIAN_FRONTEND=noninteractive # the following line is needed in order for the build to succeed due to some outdated stuff in the docker image RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/c...
<python><docker><pip>
2024-03-19 13:35:21
1
1,630
Carlo
78,186,958
1,422,096
How to monkey-patch np.savez_compressed to add compression level, without editing numpy's source files?
<p>I need to modify the ZIP <code>compressionlevel</code> internally used in <a href="https://numpy.org/doc/stable/reference/generated/numpy.savez_compressed.html" rel="nofollow noreferrer"><code>np.savez_compressed</code></a>. There is a <a href="https://github.com/numpy/numpy/issues/20995" rel="nofollow noreferrer">f...
<python><arrays><numpy><compression><monkeypatching>
2024-03-19 13:21:12
1
47,388
Basj
78,186,669
12,415,855
Pytesseract / Recoginizing chars + digits + spaces
<p>i would like to recognize some text (with digits and spaces) from a image using the following code:</p> <pre><code>erg = pytesseract.image_to_string(img) </code></pre> <p>Generally this works fine with that but i also get character i don´t want like Ô</p> <pre><code>ÔAU OPTRONICS CORPORATION () Preliminary Specific...
<python><python-tesseract>
2024-03-19 12:37:39
1
1,515
Rapid1898
78,186,564
9,754,418
"ModuleNotFoundError: No module named 'sagemaker.huggingface' despite installing sagemaker package"
<p>I am trying to use the <code>sagemaker.huggingface</code> module to run a hugging face estimator as described in <a href="https://huggingface.co/blog/sagemaker-distributed-training-seq2seq#create-a-huggingface-estimator-and-start-training" rel="nofollow noreferrer">this blog</a>, but I encounter the following error:...
<python><conda><amazon-sagemaker><large-language-model><huggingface>
2024-03-19 12:20:47
0
1,238
Yann Stoneman
78,186,481
539,251
Polars DataFrames Python do replacement by using mask which itself is another Polars DataFrame
<p>How to change variables (or recreate) dataframe, with another boolean mask Polars DataFrame? So not just single column vectors (Series), but both a DataFrame.</p> <p>So set the following to 1000, where amount &gt; 270, value at the bottom would become 1000</p> <p>Input:</p> <pre><code> apples[0].amount a...
<python><python-polars>
2024-03-19 12:07:55
2
1,545
BigChief
78,186,362
1,288,071
How to apply `numpy.vectorize` on a subset of arguments?
<p>I have searched a lot but couldn't find a solution to this particular problem. I have a function with the following signature:</p> <pre><code>def my_function(self, number: float, lookup: list[str]) -&gt; float: # perform some operation return some_float_based_on_operation </code></pre> <p>I am trying to vect...
<python><numpy>
2024-03-19 11:49:43
1
1,735
Cashif Ilyas
78,186,300
18,519,921
Differrent behavior between numpy arrays and array scalars
<p>This is a follow-up on <a href="https://stackoverflow.com/questions/78180968/can-i-force-array-numpy-to-keep-its-uint32-type">this</a> question.</p> <p>When we use a numpy <strong>array</strong> with a specific type, it preserves its type following numeric operations.<br /> For example adding 1 to a <code>uint32</co...
<python><numpy><numpy-ndarray><numpy-scalar>
2024-03-19 11:40:19
1
35,449
wohlstad
78,186,148
12,780,274
Received duplicate pseudo-header field b':path' error when I send http2 requests in python
<p>I have a url that only responds to http2 requests.</p> <p>When I want send http/2 request with python to the URL, I get bellow <code>ERROR</code>:</p> <blockquote> <p><code>h2.exceptions.ProtocolError: Received duplicate pseudo-header field b':path'</code></p> </blockquote> <p>My <code>Code</code>:</p> <pre><code>fr...
<python><python-3.x><http2>
2024-03-19 11:14:08
2
643
henrry
78,185,983
108,390
What is the equivalent to df.to_markdown() for a Polars Dataframe?
<p>In Pandas, it is super easy to just do</p> <pre><code>from IPython.display import display, Markdown display(Markdown(my_df.to_markdown())) </code></pre> <p>In a Notebook to get nice-looking tables printed out.</p> <p>if you have a Polars dataframe, you (obviously) get</p> <blockquote> <p>AttributeError: 'DataFrame'...
<python><python-polars>
2024-03-19 10:48:32
1
1,393
Fontanka16
78,185,715
860,848
Passing and Returning Java Map to GraalVM python
<p>I want to pass java map to python code and access the map values in python, and then store the results in a map, then access the results in Java. I'm stuck with the first step to pass java map to python.</p> <p>I have tried with the following code, but didn't work</p> <pre><code>import java.util.HashMap; import java...
<python><java><graalvm><graalpython>
2024-03-19 10:07:28
1
607
Jay
78,185,606
726,730
multiproccessing broken pipe error when i am trying to send plot data from process
<p>I have made a pyqt5 app to test the microphones. I used pydub and pyaudio modules for this scope. I also plot the microphone data with matplotlib. I have a QDialog, which run an emitter to communicate with the qdialog and multiproccessing to read from pyaudio input stream. When from my ui i choose to normalize the m...
<python><pyqt5><multiprocessing><pipe>
2024-03-19 09:52:26
1
2,427
Chris P
78,185,518
2,729,831
Gcloud functions deploy crash
<p>Everytime I try to deploy a function I get an error:</p> <pre><code>ERROR: gcloud crashed (TypeError): expected string or bytes-like object </code></pre> <p>I uploaded the same code manually in a zip file and there were no problems.</p> <p>This is the command:</p> <pre><code>gcloud functions deploy myfunction \ --...
<python><google-cloud-functions><gcloud>
2024-03-19 09:38:40
1
473
blob
78,184,921
5,049,813
How can just using the += "syntactic sugar" cause an infinite loop?
<p>Let <code>a = [-1, -2, -3]</code>. I want to modify the list <code>a</code> so that <code>a == [-1, -2, -3, 1, 2, 3]</code>, and I want to use <code>map</code> to achieve that.</p> <p>I have the following different pieces of code I've written to do this:</p> <ol> <li><code>a = a + map(abs, a)</code></li> <li><code>a...
<python><addition><syntactic-sugar>
2024-03-19 07:46:23
1
5,220
Pro Q
78,184,551
5,884,886
Need help learning Python with non thread safe code
<p>I'm trying to work through a tutorial for Python 3.12.2. I'm at the section where it tries to demonstrate non-thread safe code. The tutorial said the following code would produce unpredictable results. Well, for me it produced very predictable results. The code is:</p> <pre><code># when no thread synchronization...
<python><multithreading>
2024-03-19 06:17:56
2
329
Barry S. Rayfield
78,184,545
9,749,972
Can we make parent class initialization less often than child class'?
<p>I tried to plot sine waves with different frequencies (<code>f</code>) and amplitudes (<code>a</code>) using class inheritance. But it doesn't seem to me it runs efficiently. Here is my code where I put common attributes f and a in the parent class and the variable t in the child class.</p> <pre><code>import math fr...
<python><class><inheritance>
2024-03-19 06:15:44
3
691
Leon Chang
78,184,542
14,367,125
How to scan Bluetooth BR/EDR (Classic) with Python on macOS?
<p>I'm developing a remote sensor using ESP32 to collect data and send it to my macOS via Bluetooth, and use Python to receive it from the macOS side. I hope I can build a small Python tool to:</p> <ol> <li>Scan surrounding Bluetooth devices.</li> <li>User selects the specific one they want (in this way, my ESP32 Bluet...
<python><macos><bluetooth>
2024-03-19 06:13:51
0
726
Yiming Designer
78,184,522
11,748,924
Count num of occurences of every 26 characters for every word in numpy
<p>I have this numpy array that stored on <code>wordlist_arr</code>:</p> <pre><code>[b'aabi\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00abcdefghijklmnopqrstuvwxyz' b'aabinomin\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\...
<python><arrays><numpy><count><character>
2024-03-19 06:04:38
1
1,252
Muhammad Ikhwan Perwira
78,184,361
726,730
PyQt5: How to center QDialog inside centralwidget of QMainWindow
<p>I have a QMainWindow like this:<a href="https://i.sstatic.net/tDtKJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tDtKJ.png" alt="enter image description here" /></a></p> <p>In the top of the window there is title bar (default windows behavior) with the title the program icon and the minimize, maxim...
<python><user-interface><pyqt5>
2024-03-19 05:19:26
1
2,427
Chris P
78,184,320
1,333,133
A conda activated virtual enviroment is not running the Python file when called from a flask webservice
<p>I have created a virutal environment using conda, and am trying to run a python script in it using a flask end point call. The code is not executing , whereas if I run the file from terminal by getting inside the virtual environment it runs in less than a minute. Any idea what am I missing?</p> <p>My venv name: py31...
<python><anaconda3>
2024-03-19 05:05:05
1
8,901
Satya
78,183,969
1,942,868
Python requires libmysqlclient.22.dylib but libmysqlclient.23.dylib exist
<p>I bumped into this error. when running django script using mysql</p> <pre><code>ImportError: dlopen(/Users/whitebear/.local/share/virtualenvs/cinnamon-admin-mg9y4sUV/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/mysql/lib/libmysqlclient.22.dylib </cod...
<python><mysql>
2024-03-19 02:37:26
0
12,599
whitebear
78,183,857
3,055,616
Could not find a version that satisfies the requirement torch when compiling
<p>I have a code running on a Mac mini M2 that requires torch and torch audio, and that works as expected when testing it in VSCode but when compiling into Docker I get this error, any idea how to fix it? I've found some other posts online regarding the python versions, I did try changing versions (3.10, 3.11) and even...
<python><docker><pytorch>
2024-03-19 01:50:32
1
685
AJ152
78,183,758
9,067,589
Python PyQt5 Add Remote Debugging To Compiled Application
<p>In my project I create an application which I then compile with pyinstaller.</p> <p>The application allows the end-user to add HTML5 files into a folder which the python script then runs as a web app using PyQt5. As described in the documentation <a href="https://doc.qt.io/qt-6/qtwebengine-debugging.html" rel="nofol...
<python><pyqt5><pyinstaller><remote-debugging>
2024-03-19 01:08:17
1
1,247
Miger
78,183,666
2,340,002
How to bind implicit constructor/conversion in Python with pybind11?
<p>I'm trying to mimic implicit conversion/construction of a simple struct in Python using <code>pybind11</code>:</p> <pre><code>struct MyType { double a; double b; }; void func(size_t foo, const MyType&amp; bar) { // ... } // ... PYBIND11_MODULE(pymylib, module) { // ... py::class_&lt; MyType &...
<python><c++><implicit-conversion><pybind11>
2024-03-19 00:25:47
1
1,767
joaocandre
78,183,619
1,390,639
too many ticks on log colorscale
<p>I am working in a <code>Jupyter</code> notebook with <code>Python 3.9.12</code> and <code>matplotlib 3.5.2</code>. I am trying to plot a contour plot using <code>contourf</code> with a logarithmic &quot;z&quot; or &quot;colorscale.&quot;</p> <p>The code that I'm using is here:</p> <pre><code>#set up a 1d plot fig,a...
<python><matplotlib><jupyter-notebook>
2024-03-19 00:06:34
0
1,259
villaa
78,183,300
169,083
How to return the full hierarchy of an XML node?
<p>Given the following XML snippet:</p> <pre><code>&lt;Profile&gt; &lt;Settings&gt; &lt;PresentationParameters&gt; &lt;Annualize&gt;True&lt;/Annualize&gt; &lt;LoadExAnteRiskForPresentation&gt;False&lt;/LoadExAnteRiskForPresentation&gt; &lt;MultiLegDisplayMode&gt;Legs&lt;/...
<python><xml><xpath>
2024-03-18 22:21:32
3
620
NoazDad
78,183,274
4,967,582
If I used recursion to solve Subset Product, would it "know" not to use combinations with a product > N to avoid redundancy?
<p>I'm solving Subset Product for positive integers, I'm given a list <strong>S</strong> of divisors and an integer <strong>N</strong>. I must decide if a combination exists that equals to target.</p> <p>I will remove non-divisors from <strong>S</strong>, remove duplicates of 1 as any combination equals 1 and this does...
<python><recursion><combinations>
2024-03-18 22:14:25
3
347
The T
78,183,246
15,412,256
Complex Polars Operation Using Subqueries and Threshold first hits
<p><code>df_original</code> represents the ice-cream inspector on station <code>A</code> and <code>B</code>:</p> <pre class="lang-py prettyprint-override"><code>df_original = pl.DataFrame( { &quot;station&quot;: [&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot...
<python><algorithm><python-polars>
2024-03-18 22:04:58
0
649
Kevin Li