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,146,984
3,649,594
guessing the precision of each of my solutions using fsolve (scipy)
<p>I want to know the error (or uncertainty) of each of my solutions in a system of equations when I'm using <code>scipy.optimize.fsolve</code> from. For example (from the documentation):</p> <pre><code>import numpy as np from scipy.optimize import fsolve def func(x): return [x[0] * np.cos(x[1]) - 4, x...
<python><scipy><scipy-optimize>
2023-09-21 03:15:24
1
477
oscarcapote
77,146,945
9,554,172
How to use python subprocess.run for calling other python files and bash files
<p>I am using python subprocess.run to call a .sh file and .py file that are located in another directory distant from the source. This is the only connection between the two directories making importing not practical. The code below has been simplified to the bare minimum.</p> <pre><code>parent-dir/ ├── dirA │ ├── m...
<python><bash><subprocess><pytest><windows-subsystem-for-linux>
2023-09-21 03:01:56
1
881
Lacrosse343
77,146,826
2,604,247
FastAPI Swagger Documentation Showing Incorrect Response Status?
<p>The route implemented via FastAPI (code snippet below) is working fine.</p> <pre class="lang-py prettyprint-override"><code>@app.post(path='/user/create/') async def create_user(response: Response, email: str = Form(), password: str = Form()) -&gt; None: &quot;&quot;&q...
<python><fastapi><httpresponse><asgi>
2023-09-21 02:16:21
1
1,720
Della
77,146,783
653,133
Finding the bottleneck for asyncio tasks slowing down overall
<p>For python asyncio, what are good tools do debug performance bottlenecks? I have a quart webserver that is the frontend for a backend that holds SSH connections (via <code>paramiko</code>) to multiple devices (about 30 or 40). What I notice is that, once all those connections are up and running, the web frontend see...
<python><python-asyncio><paramiko><yappi>
2023-09-21 01:54:54
0
2,870
Michael Ochs
77,146,775
3,204,212
How can I properly pass stdin inputs to my Python subprocess?
<p>I am using a CLI program, <a href="https://github.com/FiloSottile/age" rel="nofollow noreferrer">age</a>, to encrypt files with a passphrase. You cannot supply the passphrase as an argument or an environment variable; after the program starts, it prompts you to type it in. This is a pain to encrypt a large number of...
<python><subprocess>
2023-09-21 01:51:48
0
2,480
GreenTriangle
77,146,640
3,533,030
plotly / VS Code shows axes but does not show isosurface
<p>Simple (?) code, but nothing shows inside the plot.</p> <pre><code>import numpy as np import plotly.graph_objects as go # Create a three-dimensional grid of points. x = np.linspace(-1, 1, 100) y = np.linspace(-1, 1, 100) z = np.linspace(-1, 1, 100) # Calculate the distance from each point to the origin. r = np.sqr...
<python><visual-studio-code><jupyter-notebook><plotly>
2023-09-21 00:58:59
0
449
user3533030
77,146,492
9,588,300
Pandas merge on inequality
<p>So I have been searching a pandas equivalent of this SQL query</p> <pre><code>SELECT * FROM table1 LEFT JOIN table2 ON table1.columnX&gt;=table2.columnY </code></pre> <p>*<em>Note that I am joining by an inequality condition, <code>&gt;=</code>, not by matching columns.</em></p> <p>But it seems panda's merge is only...
<python><sql><pandas><dataframe><join>
2023-09-21 00:00:20
2
462
Eugenio.Gastelum96
77,146,428
3,245,747
Fitting an RNN model using a tensorflow dataset
<p>I'm still new to using TensorFlow datasets and would like some help with the following. Assume I have a matrix where each row is an observation and I would like to use the window function in order to prepare the data. A sample code is as follows:</p> <pre><code>import tensorflow as tf import numpy as np my_random =...
<python><tensorflow><keras><recurrent-neural-network>
2023-09-20 23:37:02
1
947
user3245747
77,146,349
2,469,032
Obtaining grouped max() or min() in Pandas without skipping NANs
<p>Consider a sample dateframe</p> <pre><code>df = pd.DataFrame({'group' : [1, 2, 2], 'x' : [1, 2, 3], 'y' : [2, 3, np.nan]}) </code></pre> <p>If I want to get the max value of variable 'y' <em>without</em> skipping NANs, I would use the function:</p> <pre><code>df.y.max(skipna = False) </code></pre> <p>The returned re...
<python><pandas><group-by>
2023-09-20 23:12:55
2
1,037
PingPong
77,146,241
687,739
How to nicely format the X-axis labels on a pandas bar chart
<p>Run the following code:</p> <pre><code>covid = pd.read_csv(&quot;https://covid.ourworldindata.org/data/owid-covid-data.csv&quot;) covid.set_index(&quot;date&quot;, inplace=True) covid.index = pd.to_datetime(covid.index) covid[covid.location==&quot;Denmark&quot;].new_cases_smoothed_per_million.plot() </code></pre> <p...
<python><pandas><plot>
2023-09-20 22:35:49
1
15,646
Jason Strimpel
77,146,194
102,694
pyarrow breaks pyodbc MySQL?
<p>I have a Docker container with MySQL ODBC driver, unixODBC, and a bunch of Python stuff installed. My MySQL driver works through <code>isql</code>, and it works when connecting from Python with <code>pyodbc</code>, if I do so in a fresh Python process:</p> <pre><code>sh-4.4# python Python 3.8.16 (default, May 31 202...
<python><mysql><pyodbc><pyarrow><unixodbc>
2023-09-20 22:19:14
1
1,652
Aron
77,146,081
1,471,980
how do you add the same column names in Pandas given the group name
<p>I have a data frame that has the same column names multiple times. I need to be able to add the values for the same column names and display the output. For example, I have this data frame:</p> <p>df</p> <pre><code>Server Model Slot Count40G Count40G server1 Cisco 1 10 5 server1 Cisc...
<python><pandas>
2023-09-20 21:45:25
2
10,714
user1471980
77,145,988
22,466,650
How to adjust the formatting of variable number of arguments?
<p>With this list as an input :</p> <pre><code>my_list = [ ['a', 'b'], ['c', 'd', 'e'], ['f', 'g'], ['h'] ] </code></pre> <p>I'm trying to print adjusted to the left strings but there are missing values :</p> <pre><code>for i in my_list: print('{:&lt;10}'.format(*i)) a c f ...
<python><string><formatting>
2023-09-20 21:20:58
2
1,085
VERBOSE
77,145,965
181,309
Does Pandas to_csv in append mode first read the target file into memory?
<p>I'm hitting out-of-memory errors when working on a big data set in chunks. The pattern in the memory chart makes me think that appending data to a file using to_csv is actually reading the existing file into memory, appending in-memory, and then dumping it all out to disk. Is that the way Pandas handles appends to...
<python><pandas>
2023-09-20 21:16:39
1
1,483
Chris
77,145,961
16,611,809
Installing PyQt5 on 'arm64' stopped working all of a sudden (some 'sip' issue)
<p>this is a pretty macOS specific question, but I didn't know where to put it. I have an Python script that uses PyQt5. Unfortunately there is no wheel for <code>pyqt5</code> to install it with <code>pip</code> so you have to build from source, if you are on <code>arm64</code>. This is how I successfully did it till t...
<python><pyqt5><sip><qmake><apple-silicon>
2023-09-20 21:15:05
1
627
gernophil
77,145,750
5,924,264
How to check 2 column values in a sql table aren't duplicated
<p>I attached a <code>src</code> database to a <code>destination</code>. Each database contains the columns <code>time</code> and <code>id</code>. I want to check that there is no row in <code>src</code> that has the same <code>time, id</code> pair as the one in <code>destination</code>.</p> <p>I tried the following qu...
<python><sql>
2023-09-20 20:26:04
1
2,502
roulette01
77,145,680
3,788
Algorithm to flatten JSON arrays to rows
<p>I'm writing an algorithm in pure Python to do something similar to Clickhouse's <a href="https://clickhouse.com/docs/en/sql-reference/functions/array-join" rel="nofollow noreferrer">arrayJoin</a> function: split nested arrays into individual lines.</p> <p>For example, with this input:</p> <pre class="lang-json prett...
<python><json><algorithm>
2023-09-20 20:13:12
1
19,469
poundifdef
77,145,578
2,459,179
Configuration for Kubernetes Flask and Prometheus
<p>I am trying to configure a prometheus to monitor a simple flask app, but its very weird that the prometheus does show the service in the drop down, but it shows nothing when I click in the dropdown:</p> <p><a href="https://i.sstatic.net/KeuEB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KeuEB.png" ...
<python><kubernetes><flask><prometheus>
2023-09-20 19:55:31
1
307
user2459179
77,145,404
15,189,432
How can I retrieve "TSV SCHOTT Mainz" from HTML using Python
<p><a href="https://i.sstatic.net/2KDgz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2KDgz.png" alt="Screenshot HTML Code" /></a></p> <p>Hello,</p> <p>I can't find a way to retrieve the words &quot;TSV SCHOTT Mainz&quot; from the HTML code because I don't understand which section to target here. I've ...
<python><html><python-requests>
2023-09-20 19:23:22
1
361
Theresa_S
77,145,378
4,076,764
Building a Wheel File with extra_requires using Tox
<p>I have a Python multi-module project with a setup.py file that defines extra dependencies using extra_requires. I want to use Tox to build a wheel file that includes these extra dependencies. However, I'm not sure how to achieve this with Tox.</p> <p>Here's my project structure:</p> <pre><code>my_project/ ├── se...
<python><setup.py><tox>
2023-09-20 19:18:19
0
16,527
Adam Hughes
77,145,360
788,153
looking for an efficient way to split columns in a text in pandas
<p>I have pandas dataframe and want to split the <code>text</code> column in such a way that each row has just two words. when splitting, I need to maintain the order so that I can combine them together based on <code>line</code>. Is there efficient way to do this. I can do list comprehension but was looking at more ef...
<python><pandas><nlp>
2023-09-20 19:14:38
3
2,762
learner
77,145,314
8,236,050
Previously working selenium script suddenly fails to establish a new connection
<p>I have been working with my python Selenium script for a while now, but suddenly I have started getting this error:</p> <blockquote> <p>urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=56467): Max retries exceeded with url: /session/c159fe7f3ae326faada8651af9241ac9/url (Caused by NewConnec...
<python><selenium-webdriver>
2023-09-20 19:04:12
1
513
pepito
77,145,042
931,123
How do I use .copy() method of a subclass of the list object in Python 2.x?
<p>I'm trying to use the .copy() method on a list subclass, but Python 2 is saying the copy() method doesn't exists.</p> <pre><code>class MyList(list): pass mylist = MyList() mylist.append(1) mylist.append(&quot;two&quot;) print(str(mylist[0]) + &quot; &quot; + mylist[1]) mylist2 = mylist.copy() mylist2.appe...
<python><list><copy>
2023-09-20 18:13:23
1
775
livefree75
77,144,952
8,382,028
Building a Django Q object for query
<p>I am having an issue wrapping my head how to build a <code>Q</code> query in Django while setting it up as a dict.</p> <p>For example: I have a list of pks for properties and I am trying to filter and see if those pks are associated with either item = <code>['6', '21', '8', '13', '7', '11', '10', '15', '22']</code><...
<python><django>
2023-09-20 18:00:19
1
3,060
ViaTech
77,144,903
21,540,734
Capturing a screenshot of a fullscreen game fails
<p>This works on a normal window but in a fullscreen game this is returning a black screen so I changed the <code>dtype = numpy.uint8</code> to <code>dtype = numpy.uint16</code> and now I'm getting the this error. I think it has something to do with the 4 in the tuple.</p> <pre><code>File &quot;C:\Users\phpjunkie\Pytho...
<python><winapi><pywin32><screen-capture><game-automation>
2023-09-20 17:52:39
1
425
phpjunkie
77,144,861
6,351,763
dbt - pass return value of dbt macro to python
<p>Since version 1.5, dbt can be invoked directly from within a python script, like:</p> <pre class="lang-py prettyprint-override"><code>from dbt.cli.main import dbtRunner, dbtRunnerResult # initialize dbt = dbtRunner() # create CLI args as a list of strings cli_args = [&quot;run-operation&quot;, &quot;get_something_...
<python><dbt>
2023-09-20 17:46:40
2
1,631
NemesisMF
77,144,665
785,494
How can I run Python as root (or sudo) while still using my local pip?
<p><code>pip</code> is recommended to be run under local user, not root. This means if you do <code>sudo python ...</code>, you will <em>not</em> have access to your Python libs installed via pip.</p> <p>How can I run Python (or a pip installed <code>bin/</code> command) under root / sudo (when needed) while having ac...
<python><pip><root>
2023-09-20 17:17:50
2
9,357
SRobertJames
77,144,614
5,924,264
Passing in private attributes into a utility function
<p>I have 3 classes with a merge operation that does identical operations with different arguments.</p> <p>Here's the skeleton code of what I currently do:</p> <pre><code>class FirstClass: def __init__(self): # define constructor def merge(self, other): # merge other into self merge_util(src=other, des...
<python><oop><encapsulation><private-members>
2023-09-20 17:10:17
1
2,502
roulette01
77,144,609
2,687,317
Finding a series value in a pandas df that includes a date/time field
<p>I have a pandas df like this:</p> <pre><code> Date_Time Time_slot Veh_ID Pwr Group_ID 0 2023-03-30 00:00:01 1 100 10 100_1 1 2023-03-30 00:00:01 2 100 12 100_1 2 2023-03-30 00:00:05 1 100 3 100_1 3 2023-03-30 00:00:05 2 100 ...
<python><pandas>
2023-09-20 17:09:41
1
533
earnric
77,144,496
10,765,629
Vscode tooltip not rendering markdown format when hovering in functions
<p>I used to comment my functions (in python at least) using a markdown format. And it render it correctly showing the Heading level, the variables, and so on. I do not know why it stopped working.</p> <p>And it shows like this:</p> <p><a href="https://i.sstatic.net/TiDtN.png" rel="nofollow noreferrer"><img src="https:...
<python><visual-studio-code>
2023-09-20 16:52:07
1
710
z_tjona
77,144,494
3,121,975
Printing a datetime, with timezone, but excluding the timezone name
<p>I have a datetime object that I've created like so:</p> <pre><code>dt = datetime(2023, 9, 18, 22, 30, 0, tzinfo=timezone(timedelta(hours=9))) </code></pre> <p>This corresponds to September 18th, 2023 at 10:30PM JST. I want to print this datetime like this:</p> <blockquote> <p>2023-09-18 22:30:00+09:00</p> </blockquo...
<python><datetime><iso8601>
2023-09-20 16:51:34
2
8,192
Woody1193
77,144,478
1,188,943
Issue in installing Facebook Seamless Communication on Mac
<p>I tried to install seamless_communication from Facebook on MacOS With Intel CPU. The error we get is:</p> <pre><code> Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done INFO: pip is looking at multiple versions of fairseq2 to determin...
<python><facebook>
2023-09-20 16:47:52
0
1,035
Mahdi
77,144,399
6,484,726
Using Depends() for global constants in FastAPI
<p>I was researching implementations of stable FastAPI applications and found Safir project which provides global HTTP client as a dependency using Depends()</p> <p>Here on the page for Safir project on which they suggest to do so: <a href="https://safir.lsst.io/user-guide/http-client.html#using-the-httpx-asyncclient" ...
<python><fastapi>
2023-09-20 16:33:07
1
398
hardhypochondria
77,144,326
6,082,378
sending logs to fluentd from python script via syslog protocol
<p>I have started the fluentd server with docker.My fluentd configuration is</p> <pre><code>&lt;source&gt; @type syslog port 514 bind 0.0.0.0 tag system &lt;/source&gt; &lt;match **&gt; @type stdout &lt;/match&gt; </code></pre> <p>The command I used to start the <code>fluentd</code> server is</p> <pre><code>...
<python><fluentd><syslog>
2023-09-20 16:21:26
1
774
Jayendra Parmar
77,144,116
9,640,238
Returning a DataFrame from Series.apply when the supplied function returns a Series is deprecated
<p>The way I have always split a column containing lists into multiple columns is:</p> <pre class="lang-py prettyprint-override"><code>df['column_with_lists'].apply(pd.Series) </code></pre> <p>This returns a new dataframe that can then be concatenated.</p> <p>With <code>pandas 2.1</code>, this now raises:</p> <blockquo...
<python><pandas><dataframe>
2023-09-20 15:50:05
1
2,690
mrgou
77,144,021
8,318,946
how to filter and sort fields in django-filter that are not in Django model?
<p>I am trying to filter values in 2 fields that I am creating in my serializer and I am wondering how to add last_run and lat_status to filtering and orting fieldset but when I am adding them I get <code>Cannot resolve keyword 'last_status' into field.</code> error.</p> <p>Is there any option to annotate these 2 field...
<python><django>
2023-09-20 15:37:29
1
917
Adrian
77,143,904
2,230,567
Find GPS coordinates of a local point using 2 reference points
<p><a href="https://i.sstatic.net/8SQMJ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8SQMJ.jpg" alt="enter image description here" /></a></p> <p>Given 2 reference points with known local coordinates and GPS (Decimal Degrees lat,lon) how can you calculate the GPS coordinates of any local point?</p> <p>...
<python><algorithm><gps><coordinates><transformation>
2023-09-20 15:22:37
1
404
pdrak
77,143,888
8,430,277
Python, Selenium, Chrome: How to set driver location in Selenium 4.12
<h3>Use case scenario</h3> <p>Selenium 4.12 (Chrome driver) behind proxy authentication and <strong>no access to github.io</strong>.</p> <h3>Problem</h3> <p>Somewhere along the way, <code>executable_path</code> arg in <code>webdriver.Chrome</code> method was deprecated. Instead, <code>webdrive_manager.chrome</code> mod...
<python><selenium-webdriver><selenium-chromedriver>
2023-09-20 15:21:16
1
1,450
Alberson Miranda
77,143,839
13,174,189
How could i append to list any output that my function gives, including errors?
<p>I want to apply my function <code>func</code> to a list of values and collect results. Sometimes it can output errors: JSONDecodeError, IndexError, etc.</p> <p>A list to which i collect results is result_list. And if there is error, it also should be included.</p> <p>So if i do:</p> <pre><code>for value in values_li...
<python><python-3.x><list><function><append>
2023-09-20 15:16:52
2
1,199
french_fries
77,143,681
3,511,977
How to Improve rigid registration for 2D images
<p>I am looking for a way to improve the rigid registration procedure of 2D images and evaluate metrics for better rigid registration using SimpleITK, here is my code</p> <pre><code>import SimpleITK as sitk import matplotlib.pyplot as plt import numpy as np import os moving_Image = sitk.ReadImage(&quot;mri_2d_moving.ti...
<python><image-processing><scikit-image><simpleitk><image-registration>
2023-09-20 14:55:26
0
355
DevanDev
77,143,649
4,555,441
Overlay effect on image in python Pillow
<p>I am using python to get an overlay effect on an image on mouse click. How can I increase the transparency of the color so the underlying image remains visible. Currently the underlying image hides beneath. I couldn't find an option to control the opacity</p> <pre><code>import tkinter as tk from tkinter import filed...
<python><tkinter><python-imaging-library>
2023-09-20 14:52:09
1
648
pranav nerurkar
77,143,627
2,837,887
List of lists of mixed types to numpy array
<p>I have data imported from <code>csv</code> and they are stored in list of lists as:</p> <pre><code>data=[['1', ' 1.013831', ' 1.713332', ' 1.327002', ' 3.674446', ' 19.995361', ' 09:44:24', ' 2.659884'], ['2', ' 1.013862', ' 1.713164', ' 1.326761', ' 3.662183', ' 19.996973', ' 09:49:27', ' 2.668791'], ['3', ' 1.0138...
<python><python-3.x><list><numpy>
2023-09-20 14:48:33
1
1,400
atapaka
77,143,583
2,112,406
OpenMP + pybind11 (to be compiled with setup.py) on mac and linux
<p>I have a python module that I want to make usable in both macOS and linux, that uses C++ code with OpenMP. I'm having issues on macOS (because apple clang doesn't have OpenMP support, I guess). I have the following <code>*.cpp</code> code, <a href="https://iamsorush.com/posts/pybind11-openmp/" rel="nofollow noreferr...
<python><c++><openmp><pybind11>
2023-09-20 14:43:03
0
3,203
sodiumnitrate
77,143,424
12,474,157
PyDev Debugger Warnings in PyCharm: Unable to find real location for modules and slower performance
<p>I am currently debugging my Python code in PyCharm, and I've come across a series of warnings from the PyDev debugger. The key messages I'm seeing are:</p> <p>&quot;This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)&quot; &quot;The debugger may still function, but...
<python><python-3.x><debugging><pycharm><virtualenv>
2023-09-20 14:25:24
1
1,720
The Dan
77,143,316
1,652,219
Is it possible to test SQL queries on local tables?
<p>I would like to write and test my SQL queries without connecting to an SQL database. Is that possible? Most examples connect to a mysql database, but the one I have to test against is a mssql.</p> <p>As one can create these tables in sqlalchemy, can one not add data to them locally (before committing) and execute qu...
<python><sql><unit-testing><sqlalchemy>
2023-09-20 14:11:57
1
3,944
Esben Eickhardt
77,143,248
11,267,783
Pyqtgraph click outside the image
<p>I would like to know when I clicked outside the image matrix (on the screen attached, I would like to know when I clicked in the black space).</p> <p><a href="https://i.sstatic.net/Haydl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Haydl.png" alt="enter image description here" /></a></p> <p>The goa...
<python><pyqtgraph>
2023-09-20 14:04:07
1
322
Mo0nKizz
77,143,192
3,943,162
Get UUID from a EMF/XMI resource using PyEcore
<p>I have an XMI file serialized in a <a href="https://wiki.eclipse.org/index.php?title=Eclipse_Modeling_Framework&amp;redirect=no" rel="nofollow noreferrer">Java/EMF</a> program. Now, I need to read it using <a href="https://pyecore.readthedocs.io" rel="nofollow noreferrer">PyEcore</a>, and I want to set the UUID and ...
<python><uuid><eclipse-emf>
2023-09-20 13:58:14
1
1,789
James
77,143,167
8,621,823
In a single expression, why does multiple uses of object() return different or same id?
<p>I'm on python 3.10</p> <ul> <li><code>id(object()),id(object())</code> returns <code>(4519407312, 4519407312)</code> (Exact id is not important)</li> <li><code>object() is object()</code> returns <code>False</code></li> </ul> <p>Why do the <code>object()</code> in second expression contain different id while the <co...
<python>
2023-09-20 13:55:19
1
517
Han Qi
77,143,085
16,383,578
How to find number of common decimal digits of two arrays element wise?
<p>I have a complex function I want to approximate, and I use <code>np.polyfit</code> to find the polynomial to approximate it.</p> <p>And I want to find the statistics of correct decimal places to determine the quality of the approximation.</p> <p>But it is hard to do efficiently. Currently I just convert the elements...
<python><numpy>
2023-09-20 13:45:31
2
3,930
Ξένη Γήινος
77,143,064
7,683,041
Scipy spline interpolation outside data points region
<p>I am fitting 2d points on a 1d axis, using <code>scipy.interpolate.bisplrep</code>. This works better than the polynomial interpolation in general, but outside the points used for fitting, it gives bounded values. I can't find anything like <code>fill_value=&quot;extrapolate&quot;</code>, that we can use with <code>...
<python><scipy><interpolation><spline>
2023-09-20 13:43:46
1
1,310
PJ127
77,142,806
1,652,219
How to read CursorResult to Pandas in SQLAlchemy?
<p>How does one convert a CursorResult-object into a Pandas Dataframe?</p> <p>The following code results in a CursorResult-object:</p> <pre><code>from sqlalchemy.orm import Session from sqlalchemy import create_engine engine = create_engine(f&quot;mssql+pyodbc://{db_server}/{db_name}?trusted_connection=yes&amp;driver=...
<python><pandas><sqlalchemy>
2023-09-20 13:11:24
1
3,944
Esben Eickhardt
77,142,719
3,179,416
How do you manage training data in the local version of Vanna?
<p>The hosted version of Vanna has a <a href="https://vanna.ai/docs/vanna.html#get_training_data" rel="nofollow noreferrer"><code>vn.get_training_data(...)</code></a> function.</p> <p>However, when I try to run <a href="https://vanna.ai/docs/local.html" rel="nofollow noreferrer">locally following the examples</a> there...
<python>
2023-09-20 13:02:15
1
1,689
Zain
77,142,659
7,985,055
Is it possible to check a dynamic path in a python dictionary?
<p>I would like to know if it is possible to dynamically loop through paths in a a jira object and print the value if it doesn't match ?</p> <p>I have two objects, with have a bunch of fields....</p> <p>jira_object_1</p> <pre><code>{ &quot;key&quot;: &quot;3000&quot;, &quot;fields&quot;: { &quot;customf...
<python><dictionary><compare>
2023-09-20 12:54:58
2
525
Mr. E
77,142,566
9,102,437
Python multiprocessing imap iterates over whole itarable
<p>In my code I am trying to achieve the following:</p> <ol> <li>I get each result as soon as any of the processes finish</li> <li>Next iteration must only be called whenever it is necessary (if it is converted into a list, I will have RAM issues)</li> </ol> <p>To my knowledge <code>imap</code> <code>from multiprocessi...
<python><iterator><python-multiprocessing>
2023-09-20 12:43:42
2
772
user9102437
77,142,562
10,530,984
Pydantic v2 migration and string typecasting
<p>I'm tried to migrate my project to Pydantic v2 and tests fails on integer to string type conversation.</p> <pre class="lang-py prettyprint-override"><code>from pydantic import BaseModel class Foo(BaseModel): bar: str Foo(bar=1) </code></pre> <p>Code fails with exception:</p> <pre class="lang-bash prettyprint-...
<python><pydantic>
2023-09-20 12:42:43
3
655
Mastermind
77,142,461
16,613,821
Why is file.close() so slow, even when there is no buffering and/or file.flush() has already been called?
<pre class="lang-py prettyprint-override"><code>from time import perf_counter t = perf_counter() file = open('dummy', 'wb', buffering=0) print('open', perf_counter() - t) t = perf_counter() file.write(bytes(16 * 1024 ** 2)) print('write 16MB', perf_counter() - t) t = perf_counter() file.flush() print('flush', perf_coun...
<python><linux><filesystems>
2023-09-20 12:30:17
0
727
YouJiacheng
77,142,439
845,210
Pydantic dataclass with Field alias triggers pylint E1123 unexpected-keyword-arg
<p>I'm using the <a href="https://docs.pydantic.dev/latest/usage/dataclasses/" rel="noreferrer">dataclasses feature</a> in Pydantic v2.3.0 and I have a dataclass with an aliased field, like so:</p> <pre class="lang-py prettyprint-override"><code>from pydantic import Field from pydantic.dataclasses import dataclass @da...
<python><pylint><pydantic><python-dataclasses>
2023-09-20 12:28:28
0
3,331
bjmc
77,142,348
1,710,392
Efficient transfer to stdin of subprocess
<p>I am trying to make a data transfer more efficient in a linux program which has multiple clients and one server. At the beginning, the client spawns a subprocess and sends a big structure serialized using pickle (about 200MB). Then, depending on some events the clients send more data (not shown in this example code)...
<python><linux><ipc>
2023-09-20 12:17:23
0
5,078
Étienne
77,142,157
10,522,901
Pandas sort by length of list in column
<p>How do you sort a pandas DataFrame by the length of the list in a column?</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame( [ {&quot;val1&quot;: &quot;a&quot;, &quot;val2&quot;: [1,2,3]}, {&quot;val1&quot;: &quot;b&quot;, &quot;val2&quot;: [1]}, ...
<python><pandas><dataframe>
2023-09-20 11:54:48
1
316
vegarab
77,142,073
3,098,795
Insert or attach one excel workbook into another excel workbook using python
<p>I have generated multiple excel workbook using openpyxl. Now I need to create a consolidated kind of excel workbook, which would be having all the above created excel workbooks inside it as clickable.</p> <p>For example: consolidated excel workbook will look like:</p> <p><a href="https://i.sstatic.net/VC1yn.png" rel...
<python><excel><openpyxl><xlsxwriter>
2023-09-20 11:44:03
1
495
Nikita
77,141,942
13,268,160
What does the `U` in `argparse.FileType('rU')` mean?
<p>In the following code, what does the <code>U</code> mean in <code>argparse.FileType('rU')</code>?</p> <pre><code>#!/usr/bin/env python3 import argparse parser = argparse.ArgumentParser(&quot;Description&quot;) parser.add_argument('--input-file', required = True, type = argparse.FileType('rU')) args = parser.parse_...
<python><python-3.x><argparse>
2023-09-20 11:26:57
0
329
Sebastian Schmidt
77,141,928
11,596,051
I need to change specific characters in file names to uppercase
<p>I have roughly 20,000 files in a single directory whose filenames I need to change in the following manner:</p> <p>Target_file_name.jpg</p> <p>to</p> <p>Target_File_Name.jpg</p> <p>All of the filenames have at least two words in them, but some have three or even four, and all have the individual words separated by u...
<python>
2023-09-20 11:25:33
3
395
lrhorer
77,141,788
14,824,108
How to extract xvalues and yvalues from a kdeplot
<p>Given that I have a <code>seaborn.kdeplot</code> I want to extract the <code>x</code> and <code>y</code> points. Based on similar questions I have tried the following:</p> <pre><code>points = sns.kdeplot(targets, shade=True, label='train').get_lines()[0].get_data() x = points[0] y = points[1] </code></pre>...
<python><matplotlib><seaborn><kdeplot>
2023-09-20 11:07:14
1
676
James Arten
77,141,786
6,552,836
Filling the NaN values in a matrix using blocks of random heights
<p>I have a 5x5 dataframe below:</p> <pre><code> A B C D E 0 0.0 0.0 0.0 0.0 0.0 1 0.0 0.0 NaN 0.0 NaN 2 0.0 0.0 NaN 0.0 NaN 3 0.0 NaN 0.0 NaN NaN 4 0.0 NaN 0.0 NaN NaN </code></pre> <p>Trying to create a function that takes in a data frame above and...
<python><pandas><dataframe><numpy>
2023-09-20 11:07:03
2
439
star_it8293
77,141,633
15,915,737
Prefect : ImportError: cannot import name 'SecretField' from 'pydantic'
<p>I'm currently using prefect to orchestrate some simple task in python. It's working fine until I get this error :</p> <pre><code>Traceback (most recent call last): File &quot;test.py&quot;, line 2, in &lt;module&gt; from prefect import flow File &quot;/Users/.../.venv/lib/python3.8/site-packages/prefect/__in...
<python><pydantic><prefect>
2023-09-20 10:44:24
1
418
user15915737
77,141,598
1,072,825
Poetry config for torch installation
<p>I have the following poetry config for installing torch</p> <pre><code>torch = [ # Mac with apple silicon { markers = &quot;sys_platform == 'darwin'&quot;, version = &quot;^2.0.1&quot;, source = &quot;pypi&quot; }, # Mac with arm docker container { markers = &quot;sys_platform == 'linux' and platform...
<python><pytorch><python-poetry>
2023-09-20 10:39:27
0
4,840
Pavan K
77,141,578
14,244,437
Can i append the ethereum transaction's data input when generating a QR Code? Is there a better way to track transactions?
<p>My application manages sales with local payment methods and Ethereum/Bitcoin.</p> <p>When using crypto payments a QR Code will be displayed for the customer, with the wallet's address and amount.</p> <p>The issue I'm having is that if two transactions are made to two different customers with the same value, there'll...
<python><ethereum><cryptocurrency><web3py>
2023-09-20 10:36:17
1
481
andrepz
77,141,490
476,983
install python on windows via ansible
<p>I am trying to install python 3 on windows, via ansible. I use following tasks, but the install does nothing (except downloading installer).</p> <pre><code>--- # download works OK - name: Download python3.11 ansible.windows.win_get_url: url: &quot;https://www.python.org/ftp/python/3.11.5/python-3.11.5-amd64.e...
<python><windows><installation><ansible>
2023-09-20 10:25:08
1
758
michal
77,141,451
9,620,095
How to generate PDF report from Python code. Odoo 16
<p>I have a custom wizard with fields : &quot;file_name&quot;(Char), &quot;model_id&quot;(active model), &quot;content_report&quot;(html) . I added a print button in this wizard . When I click on this button I want to generate reporte with name = &quot;file_name&quot; and content of report = &quot;content_report&quot; ...
<python><pdf><odoo><report>
2023-09-20 10:21:10
1
631
Ing
77,140,920
14,830,534
How to rescale every sample individually in a pre-processing layer?
<p>I want to add a pre-processing layer to a <code>keras</code> model that both applies during training and when using the model. It is important it also applies when the model is used, so raw data can be fed to it. This layer should rescale every sample individually and put it on a <code>[-1, 1]</code> scale. With <co...
<python><tensorflow><machine-learning><keras>
2023-09-20 09:07:35
1
1,106
Jan Willem
77,140,905
11,208,548
Django file structure: cannot import main module without export PYPATH
<p>I am using Django 4.0.4</p> <p>Here is my project structure:</p> <pre><code>root/ | README.md |-- app/ | |-- init__.py | |-- manage.py | |-- project/ | | |-- __init__.py | | |-- settings.py | | |-- urls.py | | |-- etc... | |-- webapp/ | | |-- __init__.py | | |-- apps.py | | |-- ...
<python><django><import><module><django-4.0>
2023-09-20 09:05:50
1
501
Seglinglin
77,140,606
2,213,825
Use of CORS in Firebase Functions in Python to set allow-headers
<p>I am setting CORS in the following way</p> <pre class="lang-py prettyprint-override"><code>from firebase_functions.options import CorsOptions from firebase_functions import https_fn @https_fn.on_request(cors=CorsOptions(cors_origins=['*'], cors_methods=['POST'])) def my_function(req: https_fn.Request) -&gt; https_f...
<python><firebase><google-cloud-functions>
2023-09-20 08:22:48
0
4,883
João Abrantes
77,140,370
7,618,968
Selenium can't reach chrome in celery task while using supervisor
<p>I have a Django project that uses Celery as a task queue. The task is about running a chromedriver by Selenium and fetching data from some URLs. like this:</p> <pre><code>@shared_task(bind=True) def task_one(self): options = Options() options.add_argument(&quot;--start-maximized&quot;) options.add_argume...
<python><django><selenium-webdriver><celery><supervisord>
2023-09-20 07:51:17
1
482
Saeed Ramezani
77,140,031
1,852,526
Pandas line break on each comma separated list item when exporting to CSV
<p>I am using the following code using Pandas to export some data to Excel. The data is nothing but a List of some type. In this list, one of the items is a list again (Location). Here is a screenshot (when I expand one of the list items it's as follows) :</p> <p><a href="https://i.sstatic.net/HL9ES.jpg" rel="nofollow ...
<python><pandas><excel><dataframe>
2023-09-20 07:03:05
2
1,774
nikhil
77,139,790
10,829,044
pandas dynamically identify header row - Combine multiple xlsx files
<p>I have 10 excel sheets and each sheet is expected to the same header/column names.</p> <p>Files are named as <code>ABC.xlsx</code>, <code>DEF_123.xlsx</code> etc. There is no naming wildcard pattern in excel filenames.</p> <p>My problem is, some excel files have header appearing in the 1st row itself. whereas for so...
<python><pandas><excel><dataframe><list>
2023-09-20 06:25:53
3
7,793
The Great
77,139,684
6,266,370
How to store or save ssh client object in Django session?
<p>Below functions, I am creating the ssh client and trying to save it to django session object.</p> <pre><code>def create_ssh_client(host, user, password): client = SSHClient() client.load_system_host_keys() client.connect(host, username=user, passwor...
<python><django><session><ssh><django-sessions>
2023-09-20 06:05:57
2
344
codemastermind
77,139,482
10,504,481
Recursive model_json_schema in pydantic v2
<p>I'm using pydantic to create the schema for the usage with <a href="https://github.com/json-editor/json-editor" rel="nofollow noreferrer">https://github.com/json-editor/json-editor</a></p> <p>I'm using a &quot;main&quot; class to select a method as follows:</p> <pre class="lang-py prettyprint-override"><code>class A...
<python><pydantic>
2023-09-20 05:21:54
1
506
PythonF
77,139,182
395,857
How can I see the size of a HuggingFace dataset before downloading it?
<p>I want to download a HuggingFace dataset, e.g. <a href="https://huggingface.co/datasets/uonlp/CulturaX" rel="nofollow noreferrer"><code>uonlp/CulturaX</code></a>:</p> <pre><code>from datasets import load_dataset ds = load_dataset(&quot;uonlp/CulturaX&quot;, &quot;en&quot;) </code></pre> <p>How can I see the size of ...
<python><huggingface><huggingface-datasets>
2023-09-20 03:51:04
1
84,585
Franck Dernoncourt
77,139,177
4,778,587
Docker python api with auto_remove=True doesn't return stdout
<p>I need the auto_remove=True option instead of remove=True to have a more robust deletion mechanism. However, the following code doesn't allow me to get the stdout:</p> <pre><code>import docker client = docker.from_env() container_options = { 'image': 'age', 'command': [&quot;sh&quot;, &quot;/predictAge.sh&...
<python><docker>
2023-09-20 03:49:03
1
695
doom4
77,139,080
10,836,309
heyoo is not sending messages
<p>I am trying the following code:</p> <pre><code>from heyoo import WhatsApp messenger = WhatsApp(my_token,phone_number_id=my_phone_id) # For sending a Text messages messenger.send_message('Hello I am WhatsApp Cloud API', registered_number) </code></pre> <p>I am getting the following output:</p> <pre><code>{'messaging_...
<python><whatsapi><whatsapp-cloud-api>
2023-09-20 03:14:20
2
6,594
gtomer
77,138,938
264,003
Optional packages in setuptools using pyproject.toml
<p>Say I have a project like this:</p> <pre><code>pyproject.toml src/ cool/ __init__.py ... cool_cli/ __init__.py ... </code></pre> <p>I would like to be able do the following installs:</p> <pre><code>pip install cool # 1 pip install cool[cli] #2 </code></pre> <p>#1 is intended ...
<python><setuptools><pyproject.toml>
2023-09-20 02:29:46
0
2,634
zzz
77,138,707
4,634,061
Why are any of the inputs I provide to argparse set as unrecognized arguments?
<p>Goal: Create Simple Pipreqs to Generate requirements file script</p> <p>I'm already handling installing pipreqs and checking if a package exists in another file. That's not the problem. I already have read: <a href="https://docs.python.org/3/library/argparse.html#action" rel="nofollow noreferrer">https://docs.python...
<python><python-3.x><argparse>
2023-09-20 01:04:28
0
316
Annie
77,138,690
688,071
Shared Memory error while pickling object
<p>I'm messing around with <code>multiprocessing.shared_memory</code> and am simply trying to pass a <code>datetime.now()</code> value around processes. Piecing things together it seems that I can just pickle an object to turn it into bytes and place it on the shared memory buffer.... oh, if it was that simple.</p> <...
<python><python-3.x>
2023-09-20 00:56:44
1
2,512
Godzilla74
77,138,573
15,587,184
Chain method grouping and calculating differences in a Pandas DataFrame
<p>I have a Pandas DataFrame with the following structure:</p> <pre><code>import pandas as pd data = { 'glob_order': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 'trans': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'C'], 'chain': [1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2], 'date': ['1/08/2023', '2/08/2023', '3/0...
<python><pandas><methods><method-chaining>
2023-09-20 00:02:23
2
809
R_Student
77,138,505
3,633,653
Merging pandas dataframes, keep all rows and columns, without duplicates. If duplicates, keep left (_x) columns, unless right (_y) column value exist
<p>I am trying to merge two Pandas DataFrames. The first dataframe (animals_df) contains the original values, the second dataframe (update_df) contains new values that will replace or update the original values. I want to keep all rows (animals) and columns (metadata about the animals) from both dataframes, but no dupl...
<python><pandas><dataframe>
2023-09-19 23:33:49
2
612
iDevPy
77,138,324
7,274,267
With MySQL Connector in Python how do I create a stored procedure then use it right away?
<p>Using mysql-connector in python, I'm trying to create a stored procedure and then create another one which calls the first with this code :</p> <pre><code>def ExecuteQueryFromFile(query_name, path): try: with open(path, &quot;r&quot;) as file: sql_script = file.read() cursor.execute(sql_script) ...
<python><mysql><mysql-connector><mysql-connector-python>
2023-09-19 22:37:44
1
378
Jimmy Jacques
77,138,264
2,430,134
Tornado - how to get error when a child process dies immediately?
<p>I inherited an old Tornado project and am trying to update it. (I'm pointing out this context because it might not be set up according to current best practices.)</p> <p>Right now, it calls <code>tornado.process.fork_processes()</code> and starts the loop, only to end up in an infinite cycle of:</p> <pre><code> chil...
<python><tornado>
2023-09-19 22:22:16
1
1,885
Adair
77,138,199
2,687,317
Adding a series to pandas DF with a value based on groups of data in other series
<p>I'm trying to add a col to this dataframe as efficiently as possible (since it is huge):</p> <pre><code>Time Time_slot Veh_ID Pwr 1 1 100 10 1 2 100 12 2 1 100 3 2 2 100 13 3 1 100 22 3 ...
<python><pandas>
2023-09-19 22:05:16
1
533
earnric
77,138,178
8,820,463
Fill in zero values only in the center of a numpy array
<p>I'm working with a rasterio raster that I've 'read' into python, so it is now a numpy array. The outer edge of the np array are all zeros, and the interior are all ones, except, in the midst of the ones are occasional zeros, see the example array below. I want to leave all the zeros on the outside of the array alone...
<python><arrays><numpy>
2023-09-19 21:58:42
1
483
Ana
77,137,976
12,114,641
Python: Search for values from one csv file to another and get values from other columns
<p>I want to retrieve the <strong>Price</strong> and <strong>Stocks</strong> from bottom csv file and insert it in the top csv file.</p> <p>I can read both csv files and have two dictionaries, let's say <strong>top_dic</strong> &amp; <strong>bottom_dic</strong></p> <p>How do go through both dictionaries, take <strong>M...
<python><excel><csv>
2023-09-19 21:04:34
1
1,258
Raymond
77,137,961
21,787,377
Django:- Real-time Name Display Issue: 'Account Not Found' Despite Existing Account Number
<p>There is a <code>name</code> field in the <code>CustomUser</code> model that I want to display when a user inputs an account number in the <code>Transfer</code> model. What this means is validation: Imagine you want to transfer funds to someone's account. When the sender inputs the receiver's account number, I want ...
<python><jquery><django><django-views>
2023-09-19 21:01:19
1
305
Adamu Abdulkarim Dee
77,137,891
1,471,980
how do you merge two data frames
<p>I need to merge 2 data frames</p> <p>df1</p> <pre><code>Server Model Slot Count40G server1 Cisco 1 10 server1 Cisco 2 5 server1 Cisco 3 20 server2 IBM 5 10 server2 IBM 8 5 </code></pre> <p>df2</p> <pre><code>Server Model Slot ...
<python><pandas>
2023-09-19 20:45:41
3
10,714
user1471980
77,137,715
22,326,950
ValueError: The truth value of a DataFrame is ambiguous when trying to plot DataFrame with Datetime index
<p>I want to plot stacked bars using plotly express. I load the data from a .csv file but for simplification I have tried to rplicate some smaple data in my code snippet below:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import plotly.express as px d = {'Date': ['2020-09-17', '2020-09-18', ...
<python><pandas><plotly>
2023-09-19 20:16:09
1
884
Jan_B
77,137,684
452,587
Best way to refer to spreadsheet data by header name in Python?
<p>I have this data that is coming from a spreadsheet:</p> <pre class="lang-py prettyprint-override"><code>data = [ ['Column A', 'Column B', 'Column C'], ['Value A2', 'Value B2', 'Value C2'], ['Value A3', 'Value B3', 'Value C3'], ['Value A4', 'Value B4', 'Value C4'], ... ] </code></pre> <p>The data has about ...
<python><pandas><excel><dataframe>
2023-09-19 20:10:40
1
19,198
thdoan
77,137,564
10,007,302
Understanding [Errno13] permission denied when trying to access local copies of sharepoint Excel files via Python
<p>I'm struggling to figure out what/why is causing periodic permission-denied errors when trying to work with local SharePoint files. This is just one example of some of my code, which essentially uses Excel as my team's front end for uploading to a database.</p> <p>VBA code will call Python scripts that rely on <code...
<python><excel><sharepoint>
2023-09-19 19:47:43
0
1,281
novawaly
77,137,537
1,874,170
When does using floating point operations to calculate ceiling-integer-log2 fail?
<p>I'm curious what the first input is which differentiates these two functions:</p> <pre class="lang-py prettyprint-override"><code>from math import * def ilog2_ceil_alt(i: int) -&gt; int: # DO NOT USE THIS FUNCTION IT'S WRONG return ceil(log2(i)) def ilog2_ceil(i: int) -&gt; int: # Correct if i &lt;...
<python><math><floating-point><rounding-error>
2023-09-19 19:42:23
1
1,117
JamesTheAwesomeDude
77,137,398
688,071
Cachetools with multiprocessing
<p>I have an application that currently spins up multiple Processes in <code>main.py</code>, and each of those processes call a class Object to start, solely to have that class available to the <code>run()</code> function.</p> <p>This design has 2 big problems:</p> <ol> <li>It's very non-DRY</li> <li>Each process is in...
<python>
2023-09-19 19:20:19
0
2,512
Godzilla74
77,137,378
2,382,483
Numpy add.at not working with masked array
<p>I'm trying to sum some numbers in a masked array using <code>np.add.at</code> as follows:</p> <pre><code>acc = np.ma.zeros((1,), dtype=np.float64) arr = np.ma.masked_array([1.,2.,3.,4.,5.], mask=[0, 1, 0, 0, 0]) np.add.at(acc, [0,0,0,0,0], arr) assert acc[0] == 13 </code></pre> <p>This fails however. <code>add.at</c...
<python><numpy><masked-array>
2023-09-19 19:16:53
0
3,557
Rob Allsopp
77,137,232
6,626,632
Identifying source of and understanding OpenBLAS and OpenMP warnings
<p>I am developing a deep learning model using <code>pytorch</code>, <code>pytorch-lightning</code>, and <code>segmentation-models-pytorch</code>. When I run <code>pytorch_lightning.Trainer.fit()</code>, I get hundreds of the following warning:</p> <pre><code>OpenBLAS Warning : Detect OpenMP Loop and this application m...
<python><openmp><warnings><pytorch-lightning><openblas>
2023-09-19 18:50:37
2
462
sdg
77,137,225
3,616,293
Manual optimization (Lightning) prevents saving checkpoints
<p>I am referring to the official documentation for <a href="https://lightning.ai/docs/pytorch/stable/model/manual_optimization.html" rel="nofollow noreferrer">manual optimization</a>. To this end, I am trying to implement this using a custom learning-rate scheduler: linear warmup followed by step-decays. The code for ...
<python><pytorch><pytorch-lightning>
2023-09-19 18:49:53
1
2,518
Arun