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,629,917
1,914,781
python3 - print decrease progress the same line in win10
<p>I would like print a decrease number the same line in win10.</p> <pre><code>import time print(&quot;start:&quot;) for i in [10,9,8,7,6,5,4,3,2,1,0]: print(&quot;%d\r&quot;%i,end='',flush=True) time.sleep(1) print(&quot;done&quot;) </code></pre> <p>Current code output:</p> <pre><code>start: done </code></pre...
<python>
2023-12-09 02:16:11
2
9,011
lucky1928
77,629,866
13,849,446
Playwright page.pdf() only gets one page
<p>I have been trying to convert html to pdf. I have tried a lot of tools but none of them work. Now I am using playwright, it is converting the Page to PDF but it only gets the first screen view. From that page the content from right is trimmed.</p> <pre><code>import os import time import pathlib from playwright.sync_...
<python><pdf><playwright><playwright-python>
2023-12-09 01:40:06
1
1,146
farhan jatt
77,629,777
930,169
ModuleNotFoundError trying pyo3 with virtualenv
<p>This question is a follow-up question of <a href="https://stackoverflow.com/questions/77626939/pass-polars-dataframe-from-rust-to-python-and-then-return-manipulated-dataframe/77627003#77627003">this</a>.</p> <pre><code>// main.rs use polars::prelude::*; use pyo3::{prelude::*, types::PyModule}; use pyo3_polars::PyDat...
<python><rust>
2023-12-09 00:37:23
3
2,941
JACK M
77,629,738
19,675,781
YAML read filenames stored across multiple variables
<p>I have YAML data that contains file paths of hundreds of experiments results over a long time.<br/> The results are stored across different directories.<br/> All the results have a same base directory.<br/> Due to this I wanted to create a common variable for root directory and use the root directory variable across...
<python><path><yaml><markup>
2023-12-09 00:20:22
1
357
Yash
77,629,679
7,556,397
Optimizing Strawberry GraphQL API Performance: How to bypass object Instantiation for Pre-Formatted JSON from PostgreSQL?
<p>I'm developing a GraphQL API using Strawberry and FastAPI, where I directly extract and shape data from a PostgreSQL database into JSON, formatted as per the GraphQL schema.</p> <p>The data extraction is performed with SQL queries that utilize the selected fields as well as PostgreSQL's JSON capabilities, allowing t...
<python><graphql><strawberry-graphql>
2023-12-08 23:50:59
2
1,420
Lionel Hamayon
77,629,656
16,462,878
venv is installing packages globally
<p>I have fresh compiled version of <em>CPython</em>, 3.12, and wanted to start a new project in a new virtual environment with <code>venv</code>.</p> <p>I noticed that each time I install a package inside my virtual environment it is <em>not</em> going to be installed inside my project directory but in the global dire...
<python><bash><python-venv>
2023-12-08 23:45:32
0
5,264
cards
77,629,600
1,107,474
Save matplotlib as image so it can be resized later
<p>I am creating a graph using Python matplotlib, saving and displaying it:</p> <pre><code>import matplotlib.pyplot as plt # Not the real values, I have about 100,000 p = [1,2,3] t = [1,2,3] plt.plot(t, p) ax = plt.gca() ax.set_xticks(ax.get_xticks()[::10000]) plt.savefig('/path/filename.svg', format='svg') plt.show(...
<python><matplotlib>
2023-12-08 23:23:14
1
17,534
intrigued_66
77,629,566
789,750
How can I import this csv with some quoted lines into pandas?
<p>I have a csv with a structure like this:</p> <pre><code>project, location, badness foo, N/A, 0 bar, 'path/to/file:[7,23]', 120 </code></pre> <p>I want to import this into a Pandas dataframe. When I use <code>pd.read_csv(filename, quotechar=&quot;'&quot;, sep=&quot;.\s+&quot;)</code> right now, I get columns like:</p...
<python><pandas><csv><parsing>
2023-12-08 23:07:18
2
12,799
Dan
77,629,234
12,276,279
How to get second pandas dataframe showing net trade based on first pandas dataframe containing one-directional trade in Python?
<p>I have a pandas dataframe <code>df1</code> as shown below: It shows exports volume from A to B, B to A and A to C in three rows. Trade is possible in both directions. <a href="https://i.sstatic.net/p8qtb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/p8qtb.png" alt="enter image description here" /></...
<python><pandas><dataframe><group-by>
2023-12-08 21:21:31
4
1,810
hbstha123
77,628,661
1,234,434
How to print out another column after a value_counts in dataframe
<p>I am learning pandas and python.</p> <p>I have this dataframe:</p> <pre><code>dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020','4/4/2020','1/2/2020'], 'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats...
<python><pandas><dataframe>
2023-12-08 19:02:47
4
1,033
Dan
77,628,658
901,426
trouble assigning new values to mulitple object parameters from nested list
<p>i'm working up a test to populate multiple object's various parameters from a list that comes from an sqlite3 table.</p> <p>this is the code and the errors:</p> <pre class="lang-py prettyprint-override"><code>class thing(object): def __init__(self, data): self.name = data[0] self.spoot = data[1] ...
<python><list><variable-assignment>
2023-12-08 19:00:55
1
867
WhiteRau
77,628,455
2,681,662
mypy unreachable on Guard Clause
<p>I have a problem where when I try to check if the given value's type is not what I expect I'll log it and raise an error.</p> <p>However, <code>mypy</code> is complaining. What I'm doing wrong?</p> <p>Simplified example:</p> <pre><code>from __future__ import annotations from typing import Union from logging import g...
<python><mypy>
2023-12-08 18:08:31
1
2,629
niaei
77,628,411
11,163,122
How to convert AsyncIterable to asyncio Task
<p>I am using Python 3.11.5 with the below code:</p> <pre class="lang-py prettyprint-override"><code>import asyncio from collections.abc import AsyncIterable # Leave this iterable be, the question is about # how to use many instances of this in parallel async def iterable() -&gt; AsyncIterable[int]: yield 1 y...
<python><asynchronous><async-await><python-asyncio><python-collections>
2023-12-08 17:58:58
1
2,961
Intrastellar Explorer
77,628,396
3,234,562
How to get a graphviz node's position attribute?
<p>I'm making a graphviz graph in python, not loading it from a file. All I want to do is have a bunch of nodes arranged by neato, and get the position of each node. However, I can't seem to get the position attribute of the nodes; what's the right way to do this?</p> <pre><code>import graphviz def main(): dot = g...
<python><graphviz>
2023-12-08 17:56:08
1
2,712
IronWaffleMan
77,628,345
190,452
Operator overloading using Graalvm Polyglot with Scala and Python
<p>I'm playing around with Graalvm's very cool Polyglot feature so I can evaluate Python from a Scala application.</p> <p>The test REPL code is below. If I run it, and enter the following code I can evaluate <code>v.__add__(1)</code> fine. I get this:</p> <pre><code>&gt;&gt;&gt; v evaluating v evaluated got Value(7) &g...
<python><scala><graalvm>
2023-12-08 17:47:22
1
1,972
David
77,628,127
4,648,809
Transformers cross-entropy loss masked label issue
<p>I try to count cross-entropy loss for text, using gpt-2. Take the idea from this article <a href="https://huggingface.co/docs/transformers/perplexity" rel="nofollow noreferrer">https://huggingface.co/docs/transformers/perplexity</a></p> <pre><code>from transformers import GPT2LMHeadModel, GPT2TokenizerFast import to...
<python><huggingface-transformers><gpt-2>
2023-12-08 16:59:20
2
1,031
Alex
77,627,937
2,182,636
Pylint Not Rerunning
<p>I have what may be a silly question. I'll run pylint on the CLI and it will list the things it doesn't like.</p> <p>The command I'm using to run pylint is: <code>pylint ./src</code>.</p> <p>I'll then make whatever changes it suggests and execute the same command. However, it doesn't seem to be rescanning my code. ...
<python><pylint>
2023-12-08 16:23:18
0
586
cgivre
77,627,900
1,981,484
How to setup `pyi_out` path when using with rules-proto-grpc?
<p>I'm using rules-proto-grpc's <a href="https://rules-proto-grpc.com/en/latest/lang/python.html#python-grpc-library" rel="nofollow noreferrer"><code>python_grpc_library</code></a> rule to compile python files in my bazel project.</p> <p>As protoc generated python files use dynamic construction of classes, I want to us...
<python><protocol-buffers><grpc><bazel>
2023-12-08 16:16:27
0
417
Crt Tax
77,627,869
2,064,196
Importing a module sets the file's docstring to None
<pre><code>&quot;&quot;&quot; This here is a docstring &quot;&quot;&quot; print(f'Doc=[{__doc__}]') </code></pre> <p>prints</p> <pre><code>Doc=[ This here is a docstring ] </code></pre> <p>whereas</p> <pre><code>import sys &quot;&quot;&quot; This here is a docstring &quot;&quot;&quot; print(f'Doc=[{__doc__}]') </cod...
<python>
2023-12-08 16:10:37
2
6,091
Bulletmagnet
77,627,803
5,612,605
@pytest.fixture(scope=session) - called multible times im same testrun
<p><em>Im going to use a pytest fixture, which is created in the begin of my large testrun, used by every test in every file and module and destroyed in the end. How ever, for every file a new instance of the fixture is created.</em></p> <p>I would expect that <code>my_fixture</code> is only created once per testrun, a...
<python><pytest><pytest-fixtures>
2023-12-08 15:59:24
0
3,651
Cutton Eye
77,627,774
1,234,434
Best way to count number of values present in a dataframe column
<p>I have this dataframe:</p> <pre><code>dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020','4/4/2020','1/2/2020'], 'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats','Large','Large'], ...
<python><pandas><dataframe>
2023-12-08 15:53:33
1
1,033
Dan
77,627,725
231,957
Cannot connect to my couchbase cluster with python SDK
<p>I can reach my couchbase cluster with a simple cURL:</p> <pre><code>curl -u $CB_USERNAME:$CB_PASSWORD http://$CB_HOST/pools/default/buckets </code></pre> <p>but I do not manage to connect using the Python SDK:</p> <pre><code>from datetime import timedelta from couchbase.auth import PasswordAuthenticator from couchb...
<python><couchbase>
2023-12-08 15:46:55
1
17,160
Luc
77,627,700
14,190,747
How to avoid executing entire python script when a function is called without main after importing to another python script
<p>I have a python script which goes like this, which I'm NOT allowed to modify:</p> <pre><code>#file1.py def add(a, b): print(a + b) add(1, 2) #no main function whatsoever </code></pre> <p>and I HAVE TO IMPORT <code>file1.py</code> in my source code and use the function, I'm not allowed to rewrite the same funct...
<python>
2023-12-08 15:43:39
3
356
JustAnotherDev
77,627,546
3,490,622
Unable to import create_pandas_dataframe_agent due to langchain_core and langchain relative path issues
<p>I am trying to import <code>create_pandas_dataframe_agent</code> from <code>langchain.agents</code> (in Databricks), and I am getting the following strange error:</p> <pre><code>from langchain.agents import AgentType </code></pre> <pre><code>ValueError: '&lt;path_name&gt;/python3.0/site-packages/langchain/agents' i...
<python><pandas><langchain>
2023-12-08 15:16:15
2
1,011
user3490622
77,627,507
8,942,319
psycopg2 to redshift timing out but sql client connects ok
<p>I have connected a SQL client to a Redshift instance without issue, using basic user, pass, and SSH.</p> <p>The Redshift instance is in a VPC but has an associated security group that allows SSH connections for specific IP addresses. The Redshift instance is also publicly available. Again, the SQL client connects ju...
<python><amazon-web-services><ssh><amazon-redshift><psycopg2>
2023-12-08 15:11:31
0
913
sam
77,627,470
9,173,710
PySide6 preocessing of dropped files/folders locks source Explorer window
<p>I have implemented Drag and Drop feature for my app that analyzes video files.</p> <p>When dropping a folder, I show a dialog and then start processing the videos. During that the Explorer window I dragged the folder from is totally unresponsive, I cannot click anything and it doesn't update file changes.</p> <p>Oth...
<python><explorer><pyside6>
2023-12-08 15:05:39
0
1,215
Raphael
77,627,348
10,499,034
How to convert a PyObject to string in C#
<p>I am working with Pythonnet to create a C# GUI that uses backend Python code. I am just learning how the connection works and need to get a Python variable into C# and display it in a C# text box. How can I get the value computed for 'outer' in Python and display it in the textBox1? It works fine when sending the...
<python><c#><python.net><pyobject>
2023-12-08 14:44:24
0
792
Jamie
77,627,331
8,544,328
Nonlinear constraint propagation with z3?
<p>I am a Z3 newbie, and am trying to determine the marginal limits of a feasible region defined by a system of (in)equalities. My first (perhaps inefficient) approach is to define an Optimizer, assign limits, then minimize and maximize each variable in turn. This works great as long as the inequalities are linear. See...
<python><constraints><limit><z3><z3py>
2023-12-08 14:41:42
1
553
J.Galt
77,626,939
930,169
pass polars dataframe from rust to python and then return manipulated dataframe back to rust
<p>I have a rust program which is a usual backend program. It listens for computation request and forward some parameters(e.g. polars dataframe) to a python module with pyo3. The reason I need pyo3 is that python's ecosystem of data analysis is better. I have plenty of libs in python to do data work, for example scipy....
<python><rust>
2023-12-08 13:32:50
1
2,941
JACK M
77,626,758
4,742,074
How to skip first few lines from file in Python until line with required prefix is found, without writing a comparison function
<p>I need to read lines from the text file like this:</p> <pre><code>junk_line_1 junk_line_2 junk_line_3 real data starts here </code></pre> <p>so I need to skip the lines until the line starting with 'real data' is found.</p> <p>The solution I have is:</p> <pre><code>import itertools def has_prefix(line): return n...
<python><string><file>
2023-12-08 13:05:30
2
571
one_two_three
77,626,748
6,307,685
Differentiating a sum in Sympy
<p>I would like to differentiate the entropy H(T) of a discrete random variable T with respect to one of the masses q(t') using Sympy. The following implements the expression for H(T):</p> <pre class="lang-py prettyprint-override"><code>import sympy as sym sym.init_printing(use_latex=True) N_T = sym.Symbol(&quot;N_T&q...
<python><sympy><symbolic-math><differentiation>
2023-12-08 13:03:24
1
761
soap
77,626,464
2,071,807
Patch class property to return a modified version of the original value
<p>I would like to patch a class property to return a modified version of the original property.</p> <p>In this example, I would like to patch <code>Greeter.greeting</code> to prepend the value &quot;TEST&quot; to whatever the real <code>greeting</code> property returns:</p> <pre class="lang-py prettyprint-override"><c...
<python><python-unittest>
2023-12-08 12:14:48
1
79,775
LondonRob
77,626,342
11,857,974
How to transform an array using its spectral components
<p>I am trying to transform an array using its spectral components.</p> <p>Let's consider an 4x4 array arr<br /> It will have an adjacent matrix A, a degree matrix D and Laplacian matrix L = D-A</p> <pre><code>import numpy as np from numpy.linalg import eig </code></pre> <p>Compute its eigenvectors and eigenvalues, an...
<python><signal-processing><linear-algebra><spectral-python>
2023-12-08 11:48:20
2
707
Kyv
77,626,321
14,529,779
Summing Duplicates Across Sublists in a Nested List
<p>I hope my message finds you well. I am seeking your expertise and feedback on a specific issue I have encountered in the <code>repeat_sum</code> function within the codebase. The function is designed to compute the sum of integers that are present in two or more sublists within the input list</p> <p>Here is the curr...
<python><list><algorithm><for-loop><if-statement>
2023-12-08 11:45:10
1
9,636
TAHER El Mehdi
77,626,120
388,038
How to get Azure bindings to FastAPI endpoint
<p>How to pass a string <code>starter</code> from Azure http_trigger to the FastAPI endpoint?</p> <p>Currently I'm hacking this by setting <code>starter</code> in <code>context.trace_context.attributes</code></p> <p>Or alternative to get the Azure bindings into FastAPI?</p> <pre class="lang-py prettyprint-override"><co...
<python><azure-functions><fastapi><azure-durable-functions><fastapi-middleware>
2023-12-08 11:06:30
0
3,182
André Ricardo
77,625,676
5,462,398
pyInstaller: Pack binary executable inside project's executable to run
<p><strong>TLDR;</strong></p> <p>I would like to pack the <code>ffmpeg</code> executable inside my own executable. Currently I am getting</p> <pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg' Skipping ./testFile202312061352.mp4 due to FileNotFoundError: [Errno 2] No such file or directory: 'ff...
<python><ffmpeg><anaconda><pyinstaller><anaconda3>
2023-12-08 09:42:10
2
1,348
zur
77,625,508
3,650,477
How to activate verbosity in Langchain
<p>I'm using Langchain 0.0.345. I cannot get a verbose output of what's going on under the hood using the <a href="https://python.langchain.com/docs/expression_language/" rel="noreferrer">LCEL approach</a> to chain building.</p> <p>I have this code:</p> <pre class="lang-py prettyprint-override"><code>from langchain.cha...
<python><langchain><large-language-model>
2023-12-08 09:14:30
2
2,729
Pythonist
77,625,497
10,964,685
Join two geopandas df's using shortest point along line network - python
<p>I'm joining two geopandas dataframes using <code>gpd.sjoin_nearest</code>. This returns the nearest point but I'm trying to work out what unit of measurement the output is in? I've done the approximate calculations in km but I don't think the projection is working.</p> <p>I'm also aiming to incorporate a third geopa...
<python><geometry><geopandas>
2023-12-08 09:13:05
1
392
jonboy
77,625,479
1,654,143
No matching distribution found for python-colorspace
<p>I'm trying to install colourspace for python as it looks very useful for me. But am running into difficulty. Usually I'd use</p> <pre><code>py -3 -m pip install python-colorspace </code></pre> <p>but that results in:</p> <p>ERROR: Could not find a version that satisfies the requirement python-colorspace (from versio...
<python><pip><colors>
2023-12-08 09:09:17
1
7,007
Ghoul Fool
77,625,305
3,932,908
Can I take only certain keys from each config file?
<p>Let's say I have two config files in the &quot;base&quot; directory, &quot;base/v1.yaml&quot; and &quot;base/v2.yaml&quot;. Let's say each of these are structured something like:</p> <pre><code>model: embedding_size: 20 num_layers: 4 ... dataset: name: ... </code></pre> <p>If I have a new yaml and am trying...
<python><fb-hydra>
2023-12-08 08:34:40
2
399
Henry
77,624,990
10,722,752
Error while trying to install python packages
<p>I am trying to install various Python packages such as <code>pandas</code>, <code>numpy</code>, <code>mlforecast</code>, <code>xgboost</code> etc. The issue is I have two Python versions in my VM: 3.11.6 and 3.12.</p> <p>When I run the command <code>print(sys.version())</code> I get:</p> <pre><code>3.11.6 </code></p...
<python><pip>
2023-12-08 07:32:48
2
11,560
Karthik S
77,624,296
9,983,652
sort a list using a custom function with multiple parameters
<p>I am trying to sort a list using a custom function. If the function has only one parameter, it is fine. I don't know how to do if the function has 2 parameters.</p> <p>For example, when the function has only one parameter.</p> <pre><code>def sort_by_well_range(col): # col format is: avgDTS_1100_1200 a=col.sp...
<python>
2023-12-08 04:11:30
2
4,338
roudan
77,624,028
6,042,206
Python Help - ERROR: Failed building wheel for pyheif
<p>I cannot install pyheif even after I've tried everything that I know. I'm running on Windows 11 with Pycharm Community 2023. I've reinstalled all of the software and restarted the system. I've tried to run different environments and interpreters but still not having any success. Any help would be greatly appreciated...
<python><pyheif>
2023-12-08 02:28:48
1
861
Kamikaze_goldfish
77,623,799
1,609,514
How to make a table with PrettyTable that only has one horizontal line under the title?
<p>I want a very minimal table which I attempted as follows:</p> <pre><code>from prettytable import PrettyTable, HEADER, FRAME, ALL, NONE output = PrettyTable(align='l', header=False) output.title = 'My Table' output.border = False output.hrules = HEADER output.add_row([1, 2, 3]) output.add_row([4, 5, 6]) output.add_r...
<python><prettytable>
2023-12-08 00:59:56
1
11,755
Bill
77,623,734
4,220,282
How to alias a Python constructor?
<p>I read <a href="https://stackoverflow.com/questions/11264923/define-method-aliases-in-python">here</a> and <a href="https://stackoverflow.com/questions/21072711/what-is-the-best-way-to-alias-method-names-in-python">here</a> that Python methods can be aliased using <code>=</code>.</p> <p>However, when I try it on the...
<python><python-3.x><methods><alias>
2023-12-08 00:31:48
2
946
Harry
77,623,684
2,386,605
Strange warning for ValidationError in Pydantic V2
<p>I updated my FastAPI to <code>Pydantic 2.5.2</code> and I suddenly get the following warning in the logs.</p> <pre><code>/usr/local/lib/python3.12/site-packages/pydantic/_migration.py:283: UserWarning: `pydantic.error_wrappers:ValidationError` has been moved to `pydantic:ValidationError`. warnings.warn(f'`{import_pa...
<python><fastapi><pydantic>
2023-12-08 00:14:58
1
879
tobias
77,623,584
2,665,095
Why a long running request is freezing my FastAPI server?
<p>I'm seeking help to clarify how asynchronous requests work in FastAPI. I deployed my FastAPI+NGINX+Uvicorn app on a <em>t2.small</em> EC2 instance (1 vCPU / 2GiB RAM).</p> <p>It is a simple proxy server that returns the result for the provided <strong>?url=</strong></p> <pre class="lang-python prettyprint-override">...
<python><asynchronous><fastapi>
2023-12-07 23:38:51
1
339
Vlad
77,623,414
1,471,980
how do you merge two data frames based on common text on one data frame which is part of another data frame column value
<p>I have one huge data frame and one small data frame.</p> <p>big data frame called df1 something like this:</p> <pre><code>Hostname Region Model ServerABC101 US Cisco ServerABC102 US Cisco ServerDDC103 PAC Intel ServerDDC609 Emea Intel ServerDDC103 PAC Intel ServerDDC609 Emea Intel </co...
<python><pandas><dataframe><merge>
2023-12-07 22:32:54
3
10,714
user1471980
77,623,335
9,092,669
Why am I getting column ambigioutiy error in my pyspark query?
<p>I am trying to create a column that identifies which columns are updated as part of a change data feed (I followed this stackoverflow: <a href="https://stackoverflow.com/questions/60279160/compare-two-dataframes-pyspark">Compare two dataframes Pyspark</a>), but when I reference my own tables, I get this error:</p> <...
<python><apache-spark><pyspark><apache-spark-sql>
2023-12-07 22:08:35
1
395
buttermilk
77,623,320
9,078,185
Kivy 2.2.1 changed sizing of existing app
<p>I just upgraded <code>kivy</code> to version 2.2.1. It caused my existing applications to suddenly become about 1/4 the size they were before. I've looked at the config file and there's nothing obviously different, and the release notes also don't appear to mention anything about this. I.e., the image below is how o...
<python><kivy>
2023-12-07 22:05:41
1
1,063
Tom
77,623,271
2,274,226
How to install specific package from specific repo? (requirements.txt)
<p>I have say following packages in requirements.txt</p> <pre><code>abc def ghj </code></pre> <p>I would like to install only ghj from a specific repo. Is that possible?</p> <p>If I specify <code>--extra-index-url &lt;link&gt;</code> in requirements.txt, then it install ghj from that specific repo, but then it also ins...
<python><requirements.txt>
2023-12-07 21:54:58
1
422
sakura
77,623,153
12,114,641
Python3 ModuleNotFoundError: No module named 'dotenv'
<p>I'm getting <code>ModuleNotFoundError: No module named 'dotenv'</code> error. I did install <code>python-dotenv</code> as suggested in other posts but it still gives error. How to fix it?</p> <p><strong>My code</strong></p> <pre><code>import os import json import openai import pandas as pd from dotenv import load_...
<python><python-3.x><dotenv><python-dotenv>
2023-12-07 21:25:50
1
1,258
Raymond
77,623,089
3,732,793
pyvis.network shows html which is not 100 percent of the page
<p>with this simple code the output is as expected but only in a 30% of the browser window.</p> <pre><code>import networkx as nx from pyvis.network import Network G = nx.Graph() G.add_node(1) G.add_node(2) G.add_node(3) G.add_edge(1, 2) G.add_edge(1, 3) net = Network(height=&quot;100%&quot;, width=&quot;100%&quot;, ...
<python><graph><pyvis>
2023-12-07 21:11:10
1
1,990
user3732793
77,623,047
5,013,066
Why doesn't this boto3 python script type check?
<p>I'm using the <code>boto3-stubs</code> package to type check my boto3 calls. Specifically, I'm using <a href="https://youtype.github.io/boto3_stubs_docs/mypy_boto3_secretsmanager/client/#batch_get_secret_value" rel="nofollow noreferrer"><code>batch_get_secret_value</code></a> like so:</p> <pre class="lang-py prettyp...
<python><amazon-web-services><boto3><aws-secrets-manager>
2023-12-07 21:01:48
0
839
Eleanor Holley
77,622,879
2,494,795
Unable to Load Large Datasets to Azure Search Index
<p>I am trying to load around 30,000 records in an Azure Cognitive Search index. The source data comes from a Pandas dataframe, and I am attempting to upload it as follows:</p> <pre><code> file = df.to_dict(orient=&quot;records&quot;) # &quot;Use SearchIndexingBufferedSender to upload the documents in batches o...
<python><azure><azure-cognitive-search>
2023-12-07 20:18:28
0
1,636
Irina
77,622,829
1,052,628
Transferring large table into one big file from snowflake to S3
<p>I have a snowflake table which contains around 2 billion rows and imported the table in CSV format into a S3 bucket using spark which created ~110 part files and total of around 300GB of data.</p> <p>Now I want this data in single CSV file instead of those part files. I have tried to repartition/coalesce the pyspark...
<python><csv><amazon-s3><pyspark><databricks>
2023-12-07 20:05:11
0
636
Rafiul Sabbir
77,622,632
13,438,431
Telegram Bot: a set of characters break out of HTML escape
<p>I have a game telegram bot which uses first name - last name pairs to spell out a top chart of users in a chat by their score. Screenshot example below:</p> <p><a href="https://i.sstatic.net/eH5LV.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eH5LV.jpg" alt="normal markup" /></a></p> <p>So, every us...
<python><utf-8><escaping><python-telegram-bot><html-escape-characters>
2023-12-07 19:21:58
2
2,104
winwin
77,622,623
5,879,640
Python packaging with data directories - Clean uninstall
<p>I am writing a Python package that relies on some expensive to generate and large data file in order to properly work.</p> <p>This large file only needs to be generated once, so I have configured the package's <code>__init__.py</code> to generate this file upon import. This file could also be generated at any other ...
<python><installation><pip><uninstallation><python-packaging>
2023-12-07 19:20:01
0
471
Trantidon
77,622,607
2,444,251
How to run flask server + web socket server
<p>I have two pieces of blocking code, I need to run both, however running either will block the code. Both work perfectly on their own. If I could avoid using third party libraries that would be great.</p> <pre><code>import socket import logging import requests from threading import Thread from . import ARI_URL, ARI...
<python><rest><sockets>
2023-12-07 19:18:25
1
592
Bob Lozano
77,622,496
3,274,299
Pytorch unexpected behaviour after fork
<p>I have an application with PyTorch and Gunicorn. Firstly, I build models(torch Modules) in the Gunicorn Master Worker, and then Gunicorn forks the process, creates workers and serves requests. All the calculations are done on the <code>CPU</code>.</p> <p>The new feature is parallel computation per request, so I fork...
<python><pytorch><fork>
2023-12-07 18:55:16
0
695
Tipok
77,622,468
4,363,045
Is it possible to filter Django objects by a list of dictionaries?
<p>Let's say I have a queryset of django objects i.e. <code>Blog</code> with fields <code>id</code>, <code>hits</code>, <code>title</code> and also a list of dictionaries which represent those objects:</p> <pre><code>blog_list = [{'id': 1, 'hits': 30, 'title': 'cat'}, {'id': 2, 'hits': 50, 'title': 'dog'}, {'id': 3, 'h...
<python><django><orm>
2023-12-07 18:51:44
1
1,592
wasd
77,622,372
3,130,499
SQLAlchemy 2.0 query to get most recent (by date) visit for each subject
<p>I have the following models in my database:</p> <pre><code>class Subject(Base): __tablename__ = 'subjects' id: Mapped[int] = mapped_column(primary_key=True) first_name: Mapped[str] = mapped_column(String(60), nullable=False) last_name: Mapped[str] = mapped_column(String(60), nullable=False) visi...
<python><python-3.x><sqlite><sqlalchemy>
2023-12-07 18:34:56
2
692
derNincompoop
77,622,331
1,889,297
Anaconda Navigator won't launch (windows 11)
<p>I can't open Anaconda Navigator and Spyder from the drop down list (see image). No error appears.<br /> No issue when I open Spyder and Navigator from Anaconda Prompt (CLI). Digging into the code I see that the drop down shortcut is running <code>C:\ProgramData\anaconda3\pythonw.exe C:\ProgramData\anaconda3\cwp.py C...
<python><anaconda><conda>
2023-12-07 18:27:32
1
504
user1889297
77,621,991
859,141
Pyside6 QAbstractTableModel - Replace Boolean value with centre aligned icon
<p>I have a class <em>GenericTableModel(QAbstractTableModel):</em> in which I am trying to replace Boolean <em>&lt;class 'numpy.bool_'&gt;</em> with icons. I have had it working using the following:</p> <pre><code>if role == Qt.DecorationRole: value = self.dataframe.iloc[index.row(), index.column()] if hasattr...
<python><pyside><qabstracttablemodel>
2023-12-07 17:28:37
0
1,184
Byte Insight
77,621,912
15,547,292
Is there any library exporting APIs with different calling conventions?
<p>Is there any example of a library exporting functions with different calling conventions, e.g. <code>api_foo()</code> with <code>__cdecl</code> and <code>api_bar()</code> with <code>__stdcall</code>, both in the same public API namespace?</p> <p>My questions are ...</p> <ul> <li>if this is possible in principle</li>...
<python><c><ctypes><calling-convention>
2023-12-07 17:13:22
0
2,520
mara004
77,621,662
11,328,614
Google protobuf, match expected message size versus bytes received from network
<p>In order to test receiving and deserializing protobuf messages sent from a server I would like to check the received network bytes vs the expected size of a serialized fully populated message. There are some intermediate black-box steps and I want to check that the server sends the correct serialized message upon a ...
<python><deserialization><protocol-buffers><descriptor><nanopb>
2023-12-07 16:36:34
0
1,132
Wör Du Schnaffzig
77,621,639
7,563,454
Python: Get Vector 3 direction from a Vector 3 rotation, eg: `0 0 45` = '0.5 0.5 0'
<p>I'm working on a Python program where I define my own vector 3D type. At least the way I imagined it, vectors can store both a position and rotation... if implementing quaternion rotations with 4 values is better I can attempt a <code>vec4</code> but I strongly prefer avoiding those since I understand them even less...
<python><python-3.x><math><vector><rotation>
2023-12-07 16:32:35
2
1,161
MirceaKitsune
77,621,568
7,133,942
Plot barchart with matplotlib using different categories
<p>I have the following barchart in Matplotlib</p> <pre><code>import matplotlib.pyplot as plt import numpy as np # Categories and methods categories = ['25 kWh', '50 kWh', '80 kWh'] methods = ['Optimal Control', 'PSC', 'PSC-ANN'] #Input data improvement_25_kWh = [13.3, 4.1, 5.4] improvement_50_kWh = [13.8, 6.3, 4.4] ...
<python><matplotlib>
2023-12-07 16:20:55
1
902
PeterBe
77,621,536
16,988,223
Unable to install jax==0.4.5 from git repository
<p>I have python 3.9 in my device. When I run:</p> <pre><code>pip install jax and jaxlib </code></pre> <p>This is installing the version jax-0.4.21 jaxlib-0.4.21 However I need the version 0.4.5 for both jax and jaxlib.</p> <p>When I run:</p> <pre><code>pip install jax==0.4.5 jaxlib==0.4.5 </code></pre> <p>This is thr...
<python><jax>
2023-12-07 16:16:07
1
429
FreddicMatters
77,621,334
1,349,428
Pyside delay on process exit
<p>I have a Windows desktop (<a href="https://github.com/imubit/qt-data-extractor/" rel="nofollow noreferrer">open-source</a>) application developed in Pyside6. I am trying to remove a tooltip delay for a certain widget (a pretty innocent operation) and I am ending up with a huge delay when exiting the application (the...
<python><pyside6>
2023-12-07 15:44:40
1
2,048
Meir Tseitlin
77,621,319
848,811
How to type hint a Python module
<p>I have this Python module which is very handy:</p> <pre class="lang-py prettyprint-override"><code># src/payment_settings.py from utils.payment import get_current_payment_settings def __getattr__(name): settings = get_current_payment_settings() return getattr(settings, name) def __setattr__(name): ra...
<python><python-typing>
2023-12-07 15:42:29
1
1,731
SebCorbin
77,621,309
1,234,434
Regex for column not producing expected output
<p>I have this dataframe:</p> <pre><code>dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020'], 'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats'], 'Sales': ['1 table','3chairs','8 c...
<python><pandas><regex><dataframe>
2023-12-07 15:41:14
1
1,033
Dan
77,621,221
9,729,023
Is there any way to get the latest S3 file by GCP StorageTransfer?
<p>We're running Airflow/Composer on GCP and trying to get the latest S3 file by any python operator. Currently we're getting S3 file once a day, they can happen to export several files in the same day but we'd like to get only the latest one.</p> <p>Are there any options to achieve this?</p> <p>Here's current script:<...
<python><amazon-s3><google-cloud-platform><google-cloud-storage><google-cloud-composer>
2023-12-07 15:25:41
0
964
Sachiko
77,621,211
2,130,515
How to return all selenium elements that matches a whole words
<p>I am running selenium on python to return all elements that matches keywords.</p> <pre><code>url =... svc = webdriver.ChromeService(executable_path=&quot;driver_path&quot;) driver = webdriver.Chrome(service=svc) driver.get(url) key_words = ['word1', 'word2', 'word3'] # This will match if the text is equal to one of...
<python><selenium-webdriver>
2023-12-07 15:23:48
1
1,790
LearnToGrow
77,621,152
736,662
Removing "" in concatenated string
<p>In my Locust/Python script I have a function (<em>get_ts_ids</em>) like this:</p> <pre><code>def _get_ts_ids(): csv_file = os.path.join(&quot;C:&quot;, os.sep, &quot;PythonScripting&quot;, &quot;MyCode&quot;, &quot;pythonProject&quot;, &quot;TS_ID.csv&quot;) with open(csv_file) as csvfile: field_nam...
<python><locust>
2023-12-07 15:14:40
0
1,003
Magnus Jensen
77,621,135
1,008,588
How to parse nested information in JSON using jsonpath_ng
<p>I have the following JSON, which came from an API response:</p> <pre><code>{ &quot;expand&quot;: &quot;names,schema&quot;, &quot;startAt&quot;: 0, &quot;maxResults&quot;: 50, &quot;total&quot;: 3, &quot;issues&quot;: [ { &quot;expand&quot;: &quot;&quot;, &quot;id&q...
<python><json><python-3.x><jsonparser><jsonpath-ng>
2023-12-07 15:12:34
1
2,764
Nicolaesse
77,621,095
11,001,493
How to rename row string based on another row string?
<p>Imagine I have a dataframe like this:</p> <pre><code>import pandas as pd df = pd.DataFrame({&quot;a&quot;:[&quot;&quot;,&quot;DATE&quot;,&quot;01-01-2012&quot;], &quot;b&quot;:[&quot;&quot;,&quot;ID&quot;,18], &quot;c&quot;:[&quot;CLASS A&quot;,&quot;GOLF&quot;,3], ...
<python><pandas>
2023-12-07 15:06:33
1
702
user026
77,621,087
10,499,034
How to initialize the python engine in VB.net
<p>I am trying to execute a simple Python script from VB.net using PythonNet. When I use the following code I get the error &quot;System.TypeInitializationException: 'The type initializer for 'Delegates' threw an exception.'&quot; at the line of code showing &quot;PythonEngine.Initialize()&quot; I have tried forward ...
<python><.net><vb.net><python.net>
2023-12-07 15:06:03
1
792
Jamie
77,621,060
15,991,297
Add Annotations to Plotly Candlestick Chart
<p>I have been using plotly to create charts using OHLC data in a dataframe. The chart contains candlesticks on the top and volume bars at the bottom:</p> <p><a href="https://i.sstatic.net/d7gSF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/d7gSF.png" alt="enter image description here" /></a></p> <p>I ...
<python><plotly>
2023-12-07 15:02:45
1
500
James
77,621,013
1,403,470
setuptools not getting dynamic version when using pyproject.toml
<p>I am using <code>setuptools</code> with a <code>pyproject.toml</code> file, and want <code>setuptools</code> to get the package version dynamically from the package contents. Instead, it is always setting the package version in the name of the generated file to <code>0.0.0</code>, even though the package version <em...
<python><setuptools><python-packaging><pyproject.toml><version-numbering>
2023-12-07 14:56:34
1
1,403
Greg Wilson
77,620,921
1,234,434
pandas string replace is not replacing all selections
<p>I have this dataframe:</p> <pre><code>dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020'], 'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats'], 'Sales': ['1 table','3chairs','8 c...
<python><pandas><string><dataframe>
2023-12-07 14:44:41
3
1,033
Dan
77,620,744
2,664,376
Gurobi spend more time in presolve in small model
<p>I have small model to optimze in Gurobi. The problem that it takes a lot of time in presolving without removing any rows or variables. I tried to disable PreSolve paramter and reduce the number of Threads but the issue remains the same. Knowing that I working on solving CVRP. For 16 customers and 8 vehicles, it work...
<python><gurobi><vehicle-routing>
2023-12-07 14:19:35
2
1,335
MAYA
77,620,706
9,152,997
Querying list of nested models with FireO in Python
<p>I am using FireO to interact with Google Firestore in my Python application. I have a data model with nested lists, and I'm having trouble querying based on a condition within these nested lists.</p> <p>Here are my relevant data models:</p> <pre><code>from fireo.fields import TextField, ListField from fireo.models i...
<python><google-cloud-platform><google-cloud-firestore>
2023-12-07 14:13:18
1
922
Orestis Zekai
77,620,705
1,597,121
SQLAlchemy OperationalError appears depending upon syntax
<p>I am running a small Flask application and recently added SQLAlchemy as the ORM. We have been having issues with the application throwing 500 errors after being idle for some length of time. Once the error occurs, the query repeatedly fails until the application is restarted.</p> <pre><code>sqlalchemy.exc.Operationa...
<python><flask><sqlalchemy><flask-sqlalchemy><psycopg2>
2023-12-07 14:13:02
0
343
user1597121
77,620,520
9,479,925
How to explode a list column in python polars?
<p>I have a list column in polars dataframe as below.</p> <p><a href="https://i.sstatic.net/2K41Q.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2K41Q.png" alt="enter image description here" /></a></p> <p>I would like to do an explode on this column so that the all list elements will be in a single colu...
<python><python-polars>
2023-12-07 13:44:44
1
1,518
myamulla_ciencia
77,620,110
15,806,560
tkinter Button in main menu sometimes not working
<p>I got the problem when I click a button in my main screen. Sometimes when I click, it works and new window appear, sometime it does not (I can not click). I encounter this problem when trying to run other tkinter programs as well. I got no error when running this code.</p> <p>My laptop is Mac Pro M1. MyOS is MacOS S...
<python><tkinter>
2023-12-07 12:45:00
1
372
Minh Quang Nguyen
77,620,057
2,829,150
paramiko ssh_exception.AuthenticationException: Authentication failed
<p>I have code to connect using <em>sftp</em> with <em>private key</em>. From the same host where i run this code I am able to connect manually to <em>sftp</em> nevertheless getting error when running from code. What could be a problem here?</p> <pre><code>import pysftp def run(**kwargs): cnopts = pysftp.CnOpt...
<python><python-3.x><airflow><pysftp>
2023-12-07 12:36:51
0
3,611
Arie
77,619,774
3,932,908
SQLite how to persist custom data type into new table
<p>I am trying to write a database that includes numpy arrays (using sqlite3 with Python). However after creating an initial table, I want to perform some operations and save the result as a new table. This is all fine, except that once I create a new table the custom data type I register isn't properly carried over i...
<python><sqlite3-python>
2023-12-07 11:53:36
0
399
Henry
77,619,722
3,989,484
Cant get rid of FileNotFoundError in Django ImageField
<p>I have a django model Product which has an image field</p> <pre><code>class Product(BaseProduct): img_height = models.PositiveIntegerField(editable=False, null=True, blank=True) img_width = models.PositiveIntegerField(editable=False, null=True, blank=True) file = models.ImageField('Image', upload_to=prod...
<python><django><exception><django-models>
2023-12-07 11:44:18
1
1,428
Oluwatumbi
77,619,641
5,594,008
Wagtail PageChooserBlock custom ordering
<p>I'm using PageChooserBlock to display list of objects</p> <pre><code>class ActualSection(models.Model): content = StreamField( [ (&quot;article&quot;, PageChooserBlock(page_type=&quot;articles.Article&quot;)), ], min_num=1, ) </code></pre> <p>Is there any way to put some c...
<python><django><wagtail>
2023-12-07 11:27:12
1
2,352
Headmaster
77,619,517
12,052,180
How to align, with comma separator and specific decimal points in Python prints
<p>When printing a number in python I would like to</p> <ol> <li>Align right (using the align specifier <code>&gt;</code>)</li> <li>Align width (using the width specific)</li> <li>Specify the number of decimal places</li> <li>Set a separator between the thousands</li> </ol> <p>I know how do to each of these separately....
<python><printing>
2023-12-07 11:05:58
1
802
PeeteKeesel
77,619,500
10,695,613
RSA decryption of a column in PySpark
<p>I tried to use the <code>crpytography</code> module to peform RSA decryption on a column in my Spark dataframe:</p> <pre><code>from pyspark.sql.functions import udf from pyspark.sql.types import StringType from cryptography.hazmat.backends.openssl.rsa import _RSAPrivateKey def decrypt(encoded_ciphertext: str, key...
<python><pyspark><cryptography>
2023-12-07 11:03:23
0
405
BovineScatologist
77,619,442
12,468,539
Uploading large file to SharePoint from io.BytesIO instance results in `io.UnsupportedOperation: fileno` exception
<p>I am using the <a href="https://github.com/vgrem/Office365-REST-Python-Client" rel="nofollow noreferrer">Office365-REST-Python-Client library</a> to upload some relatively large CSV files to a SharePoint document library via an <code>io.BytesIO</code> instance. I do this by passing the byte array to the following me...
<python><sharepoint><bytesio><office365-rest-client>
2023-12-07 10:55:18
1
683
ChaddRobertson
77,619,436
1,346,690
How can I mock pydantic validators in unit tests?
<p>I&quot;m trying to mock a validator in a unit test, I just want to see if the validator was called, however my patch path does not seem to be correct, I tried many variation but the one used here should be ok, yet it is not.</p> <p>project structure :</p> <p><a href="https://i.sstatic.net/5Mo6H.jpg" rel="nofollow no...
<python><list><unit-testing><pytest><pydantic>
2023-12-07 10:54:45
1
6,281
Heetola
77,619,352
5,868,293
Voronoi diagram gives unexpected results in scipy
<p>I have the following pandas dataframe:</p> <pre><code>import pandas as pd pd.DataFrame({'cl': {0: 'A', 1: 'C', 2: 'H', 3: 'M', 4: 'S'}, 'd': {0: 245.059986986012, 1: 320.49044143557785, 2: 239.79023081978914, 3: 263.38325791238833, 4: 219.53334398353175}, 'p': {0: 10.971011721360075, 1: 10.97025836036675...
<python><scipy><spatial><voronoi>
2023-12-07 10:38:58
1
4,512
quant
77,619,201
3,494,774
Are SQLAlchemy MetaData objects serializable?
<p>In my application, I have multiple processes that run <code>MetaData.reflect</code> against some large DB, which takes a while. Is there a way to serialize and store the results of reflection so that I can simply load <code>MetaData</code> from a file instead of generating it each time?</p> <p>Tried to <code>pickle<...
<python><serialization><sqlalchemy>
2023-12-07 10:16:21
1
11,377
gog
77,619,112
15,275,530
Error while using async apscheduler in FastApi
<p>I am using AsyncIOScheduler and SQLAlchemyJobStore from apscheduler but Asynchronously in FastAPI. The problem here is I am getting an error. Full error below;</p> <pre><code> File &quot;D:\app\endpoints\admin\scheduler.py&quot;, line 23, in &lt;module&gt; Schedule.start() File &quot;D:\intergration-server\ven...
<python><python-3.x><asynchronous><backend><fastapi>
2023-12-07 10:02:00
0
404
Sarim Sikander
77,619,032
240,864
AWS Cognito masking data in lambda
<p>I have a very weird behavior in some feature I am building.</p> <p>I use aws Cognito for user management on a system I am building. On account creation cognito sends an email (via Custome Sender Lambda) to invite to the user with a one time user code. I want to encode this code with base64.</p> <p>here's a sample bl...
<python><amazon-web-services><aws-lambda><amazon-cognito>
2023-12-07 09:49:11
1
1,603
Tancho
77,618,829
6,907,424
cffi.VerificationError: CompileError: command '/usr/bin/gcc' failed with exit code 1
<p>While installing the package <code>pewanalytics</code> with the command: <code>pip install git+https://github.com/pewresearch/pewanalytics#egg=pewanalytics </code> I have got the following error:</p> <pre><code> × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─&gt; [130 lines of output] ...
<python><gcc><pip>
2023-12-07 09:14:41
1
2,916
hafiz031
77,618,429
4,796,942
PyPi package versions compatible with Cloud Composer's `apache-airflow-providers-microsoft-azure`
<p>I'm attempting to load a few packages into an instance of Google Cloud Composer 2. I constantly getting dependency or package issues and am unable to get the versions of the packages that function.</p> <p>The <code>requirements.txt</code> file that keeps failing looks like</p> <pre><code>apache-airflow-providers-mic...
<python><google-cloud-platform><dependencies><airflow><google-cloud-composer>
2023-12-07 07:54:02
1
1,587
user4933