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
76,012,644
508,907
FastAPI / uvicorn (or hypercorn): where is my root-path?
<p>Based on a few FastAPI tutorials, including this, I made a simple FastAPI app:</p> <pre><code>from fastapi import FastAPI, Request app = FastAPI() # also tried FastAPI(root_path=&quot;/api/v1&quot;) @app.get(&quot;/app&quot;) def read_main(request: Request): return {&quot;message&quot;: &quot;Hello World&quot;,...
<python><fastapi><uvicorn><hypercorn>
2023-04-14 07:38:20
1
14,360
ntg
76,012,505
11,712,575
Pytest Python SDK Positional Arguments
<p>I have a directory like this</p> <pre><code>Platform -test_1.py -test_2.py Another_folder -test_3.py Test -start_test.py </code></pre> <p>Inside start_test.py, I have this code to start pytest:</p> <pre><code>retcode = pytest.main([&quot;/Platform/test_*.py /Platform/Another_folder/test_*.py&quot;, &...
<python><python-3.x><pytest>
2023-04-14 07:18:43
0
389
Jason Chan
76,012,502
7,242,912
Can't reach RestAPI (FastAPI) from my Flutter web - Cross-Origin Request Blocked
<p>I have a Linux Server. On that I have two Docker Containers.In the first one I am deploying my Flutter Web and in the other one I am running my RestAPI with FastAPI().</p> <p>I set both the Docker containers in the same Network, so the communication should work. I also set origins with <code>origins = ['*']</code> (...
<python><flutter><docker><nginx><fastapi>
2023-04-14 07:17:48
1
1,234
MrOrhan
76,012,400
6,076,861
Using CONCAT in column alias
<p>I have a bunch of repeating queries in a Python accessed SQL notebook. I've tested the below</p> <pre class="lang-py prettyprint-override"><code>colum_to_agg = f'''data_col_1''' sql_aggregates_query=f''' avg({colum_to_agg}) as (concat({colum_to_agg},'_mean')), max({colum_to_agg}) as (concat({colum_to_agg},'_max')),...
<python><python-3.x><postgresql><ipython-magic><ipython-sql>
2023-04-14 07:03:50
1
2,045
mapping dom
76,012,360
7,624,196
pip: yanked release is somehow accessible as default
<p>When I try to install a python package from pypi, somehow the yanked version is installed by default.</p> <p>According to the history of the terminado package: <a href="https://pypi.org/project/terminado/#history" rel="nofollow noreferrer">https://pypi.org/project/terminado/#history</a> version 0.13.0 is yanked, but...
<python><pip><pypi>
2023-04-14 06:58:11
1
1,623
HiroIshida
76,012,237
262,875
How to type a class decorator adding additional methods to a class
<p>I have a class decorator that is adding additional methods to a class:</p> <pre><code>def add_method(cls): def new_method(self): pass setattr(cls, 'new_method', new_method) return cls @add_method class Klass(): pass k = Klass() k.new_method() # Typechecker complains about lack of new_method </code></...
<python><types>
2023-04-14 06:41:02
2
11,089
Daniel Baulig
76,012,206
16,383,578
How do I properly handle all possible exceptions by the requests module if a site is not reachable?
<p>I live in China, behind the infamous Great Firewall of China, and I use VPNs.</p> <p>A simple observation is that while the VPN is connected, I can access <a href="http://www.google.com" rel="nofollow noreferrer">www.google.com</a>. And if the VPN isn't connected, then I cannot access Google. So I can check if I hav...
<python><python-3.x><network-programming><python-requests>
2023-04-14 06:36:15
1
3,930
Ξένη Γήινος
76,012,189
10,544,599
How to config credential to login a website successfully using requests in python3?
<p>I am trying to bypass login to following site using python3 requests module. I have tried with maintaining cookies, also using with &amp; without session. But I am not getting the page appears after login.</p> <p>Visit the below source, then right-click and select Translate to English option. Then enter below creden...
<python><html><python-3.x><web-scraping><python-requests>
2023-04-14 06:34:36
0
379
David
76,012,178
5,631,598
ruamel.yaml: insert a value given dynamic index and unknown depth
<p>Using ruamel, I need to add new values to a yaml file where the index (and depth) is not known until runtime. Is there a way to insert a value if I'm given the entire path for the index? (I can decide the format for the index)</p> <p>i.e. Given the following yaml:</p> <pre><code>app: datasource: url:example.or...
<python><ruamel.yaml>
2023-04-14 06:32:52
1
381
Calseon
76,012,070
2,848,049
paypal personal account payment integration with flask
<p>I am developping a website using flask and I want to get user payments with Paypal.</p> <p>For testing purpose, I want to let users pay a small amount using paypal, which will be converted into credits of website. <strong>I don't have a PayPal business account.</strong></p> <p>However, I failed to find a detailed an...
<python><flask><paypal>
2023-04-14 06:15:11
1
574
wildcolor
76,012,038
843,075
ImportError while importing test module
<p>When I run my Playwright test, I get the following error:</p> <pre><code>ImportError while importing test module 'C:\Users\fsdam\OneDrive\Documents\python_work\playwright-python-tutorial\tests\test_search.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: C:\Users\fsdam\AppData\Local...
<python><playwright>
2023-04-14 06:10:48
1
304
fdama
76,011,925
6,846,071
How to make python pandas less redundant?
<p>I have a few lines of code that are basically categorizing the video length into different video length brackets, they look like this - but I don't know if I can make them less redundant. It seems very repetitive and maybe it's slower in run time? I'm not sure how this could be improved. Any advice is appreciated. t...
<python><pandas>
2023-04-14 05:45:28
0
395
PiCubed
76,011,899
11,926,527
Python code to remove line breaks in documents is not working
<p>I have multiple Word documents in a directory. I am using python-docx to clean them up. It's a long code, but one small part of it that you'd think would be the easiest is not working. After making some edits, I need to remove all line breaks and carriage returns. However, the following code doesn't do the job. I've...
<python><ms-word><data-cleaning>
2023-04-14 05:41:07
2
392
Leila
76,011,891
16,935,119
Read only specific columns from text file in Python
<p>Hi all I have few values in my text file as shown below</p> <p><a href="https://i.sstatic.net/6LyUN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6LyUN.png" alt="enter image description here" /></a></p> <p>I Need to extract only first column that is &quot;ColA&quot;. Is there a way to extract it. Be...
<python>
2023-04-14 05:38:37
1
1,005
manu p
76,011,794
924,677
How to decode a COCO RLE binary mask to an image in javascript?
<p>This is an example of a COCO RLE mask - <a href="https://pastebin.com/ZhE2en4C" rel="nofollow noreferrer">https://pastebin.com/ZhE2en4C</a></p> <p>It's an output from a YOLOv8 validation run, taken from the generated predictions.json file.</p> <p>I'm trying to decode this string in JavaScript and render it on a canv...
<javascript><python><yolo><pycocotools>
2023-04-14 05:16:10
1
7,347
Nikolay Dyankov
76,011,734
16,156,882
OR Tools taking infinite time for MVRP
<p>I am trying to solve MVRP problem using Google OR-Tools where I have 1000 points and 30 fleets(Vehicles). This seems to take indefinite amount of time but when I am reducing the fleets(vehicles) to 1 it is giving me solution.</p> <p>The above situation gives me a fair Idea that TSP works well for google OR -Tools bu...
<python><or-tools><traveling-salesman><vehicle-routing>
2023-04-14 05:01:51
0
519
Varun Singh
76,011,623
10,035,190
how to make dataframe from indexed dictionary?
<p>how to create Dataframe for indexed dictionary like shown in the code below?</p> <pre><code>import pandas as pd details = { 0:{'name':'Ankit','age':'23','college':'bhu'}, 1:{'name':'Aishwarya','age':'24','college':'jnu'} } df = pd.DataFrame(details) df </code></pre> <p>I want table like this but it not</p> <div...
<python><python-3.x><pandas><dataframe><dictionary>
2023-04-14 04:34:12
3
930
zircon
76,011,595
3,595,843
Ray Cluster Launch - Cannot switch off rsync during Cluster Launch with ray up
<h3>What happened</h3> <p>I’m trying to launch a single-node ray cluster using ray up.</p> <p>I have two nodes. One is the node I run ray up from, and the other is to be the head node of the ray cluster. I’ve confirmed that the first node can SSH into the second one.</p> <p>I’m using exactly the same config.yaml as the...
<python><cluster-computing><ray>
2023-04-14 04:26:59
1
861
shinvu
76,011,502
14,679,834
pip list not showing packages installed in dockerfile in dev container
<p>I'm currently trying to develop a Python application inside a container and am using Docker. I'm under the impression that the packages installed through the <code>dockerfile</code> should be available in the container but when running <code>pip list</code> it doesn't show any of the packages mentioned in the <code>...
<python><docker><pip><dockerfile><vscode-devcontainer>
2023-04-14 04:02:41
1
526
neil_ruaro
76,011,471
21,295,456
Cannot install Ultralytics using pip in PythonAnywhere
<p>I was trying to install the module <code>ultralytics</code> (for YOLOv8) in the bash of hosting service PythonAnywhere</p> <p>I tried:</p> <p><code>pip install ultralytics</code></p> <p>But get:</p> <blockquote> <p>ERROR: Could not find a version that satisfies the requirement ultralytics (from versions: none) ERRO...
<python><pip><pythonanywhere>
2023-04-14 03:52:19
1
339
akashKP
76,011,372
5,455,532
Errors trying to flatten a response object from Google's Entity Sentiment Analysis in Python
<p><strong>Goal</strong></p> <p>I'm trying to flatten a response object from google's entity sentiment analysis that's in a field named <code>entitysentiment</code> in a pandas dataframe (<code>df</code>) in a python notebook. A sample of one of the response object entries for a single row's <code>entitysentiment</code...
<python><pandas><flatten>
2023-04-14 03:20:40
1
301
dsx
76,011,304
2,095,858
Tkinter/Matplotlib inconsistent behaviour between debugging and 'release'
<h1>Preliminaries</h1> <ul> <li>Python: 3.11.1 x64</li> <li>tkinter: 8.6</li> <li>matplotlib: 3.6.2</li> <li>VsCode 1.77.2 on Windows 10 21H2</li> </ul> <h1>Summary</h1> <p>I have a simple app that plots a graph on a tkinter canvas, records the image and then restores said image using copy_from_bbox and restore region ...
<python><matplotlib><tkinter><tkinter-canvas><matplotlib-animation>
2023-04-14 03:03:38
0
421
craigB
76,011,221
4,503,546
How to round down in a forloop when using .loc in Python
<p>I am trying to turn a float into an integer by rounding down to the nearest whole number. Normally, I use numpy's .apply(np.floor) on data in a dataframe and it works. However in this instance I am iterating in a forloop with this code:</p> <pre><code>f1.loc[today,'QuantityRounded'] = f1.loc[today,'QuantityNotRounde...
<python><dataframe><numpy><for-loop><numpy-slicing>
2023-04-14 02:42:07
1
407
GC123
76,011,210
6,534,818
Pandas: Aggregate to longest set
<p>How can I get the unique entries from a dataframe such as the following; in the first case realizing that many are overlapping and thus do not need to be counted in the final output. I feel like this is perhaps a substring search problem but I am unclear as to what might be a good approach.</p> <pre><code>df = pd.Da...
<python><pandas>
2023-04-14 02:39:57
2
1,859
John Stud
76,010,709
3,380,902
How to obtain underlying data from pydeck HexagonLayer?
<p>Is there a method or any other way to obtain the underlying binned data from HexagonLayer ? I'd like to get the aggregate counts, hexagon centers (long and lat) or geometry. I am using pydeck to produce the visualization.</p> <pre><code>import pydeck as pdk # Create the HexagonLayer layer = pdk.Layer( 'HexagonL...
<python><geospatial><deck.gl><pydeck>
2023-04-14 00:14:35
1
2,022
kms
76,010,660
11,331,843
Click a link based on value in another column of a table - webscrapping python
<p>I am trying to scrape a website for a test case and the <a href="https://cdicloud.insurance.ca.gov/cal/LicenseNumberSearch" rel="nofollow noreferrer">link</a>. When I enter a certain value in the search box it return multiple values in the table and I would want to click on the link in the column ('License Number') ...
<python><selenium-webdriver><web-scraping><beautifulsoup>
2023-04-14 00:01:11
2
631
anonymous13
76,010,410
16,655,290
Edge modal blocking login automation using Selenium
<p>I am writing a python script that logs into edge using msedge-selenium-tools. When I run the script, a modal appears, and I can't seem to get any css selectors to use in Selenium. Here is my current code</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdr...
<python><selenium-webdriver><modal-dialog><microsoft-edge>
2023-04-13 22:55:31
1
351
Daikyu
76,010,335
417,896
Setting julia project when using pyjulia
<p>I am using pyjulia to call a julia project from python. I want to use all the packages that are part of my julia package so I want to init the julia runtime from my project directory. Using <code>jl_init_path</code> doesn't seem to work for this. Is there a pyjulia option or should I use Pkg.activate().</p> <pre>...
<python><julia>
2023-04-13 22:38:09
1
17,480
BAR
76,010,331
21,787,377
Django: how to generate random number inside a slug field
<p>I have a model called <code>Product</code>, when the user create an objects inside a <code>Product</code> model, I want to generate some random number inside a <code>Product</code> model field <code>Slug</code> like this:</p> <pre><code>https://stackoverflow.com/questions/76010275/cryptography-python-installation-er...
<python><django>
2023-04-13 22:37:42
1
305
Adamu Abdulkarim Dee
76,010,127
3,259,258
Slack Bot Actions (update form data on dropdown)
<p>I am working on fixing a python bot that another developer wrote. The code is a <code>python-bolt</code> slack bot that creates a <code>shortcut</code> on <code>messages</code>. When clicked it will pop up a Modal Form that allows you to create a Redmine Issue via the redminelib api. The initial developer grabbed...
<python><slack-api>
2023-04-13 21:54:02
1
823
CaffeineAddiction
76,010,100
5,240,473
XGBoost callback
<p>I'm following <a href="https://xgboost.readthedocs.io/en/stable/python/examples/callbacks.html" rel="nofollow noreferrer">this</a> example to understand how callbacks work with xgboost.</p> <p>I modified the code to run without gpu_hist and use hist only (otherwise I get an error):</p> <p><code>'tree_method': 'hist'...
<python><python-3.x><xgboost>
2023-04-13 21:50:07
1
374
Ricardo
76,010,038
1,509,264
Type checking calling identical overloaded signatures in base class from derived class
<p>I am using MyPy 1.2.0 with the settings:</p> <pre class="lang-toml prettyprint-override"><code>[tool.mypy] show_column_numbers = true disallow_any_expr = true disallow_untyped_defs = true </code></pre> <p>The code has attributes where the type of one class attribute is correlated to the value of another attrib...
<python><overloading><mypy><python-typing>
2023-04-13 21:40:37
0
172,539
MT0
76,010,030
12,361,700
tf Dataset does not seem to apply map
<p>I might be missing something very fundamental, but I have the following code:</p> <pre><code>train_dataset = (tf.data.Dataset.from_tensor_slices((data_train[0:1], labels_train[0:1])) .shuffle(500) .batch(64) .map(lambda x,y: (tf.cast(x, tf.float32), y)) ...
<python><tensorflow><dataset>
2023-04-13 21:39:39
0
13,109
Alberto
76,009,885
2,093,802
Flask Redirect From Jinja HTML Template
<p>I can call the redirect method from .py file like this</p> <pre><code>@app.route('/logout', methods=['POST', 'GET']) def logout_page(): logout_user() flash('Anda telah logout', category='success') return redirect(url_for('login_page')) </code></pre> <p>How to call that redirect method from the Jinja HTML...
<python><flask><jinja2>
2023-04-13 21:15:31
1
346
Herahadi An
76,009,612
17,638,323
Numpy `matmul` performs ~100 times worse than `dot` on array views
<p>It was brought to my attention that the <code>matmul</code> function in numpy is performing significantly worse than the <code>dot</code> function when multiplying array views. In this case my array view is the real part of a complex array. Here is some code which reproduces the issue:</p> <pre><code>import numpy as...
<python><numpy><performance>
2023-04-13 20:32:08
1
324
Simon Tartakovksy
76,009,595
25,197
Why does this Python docstring not have newlines in the VS Code hover info?
<p>I have this docstring:</p> <pre class="lang-py prettyprint-override"><code>def get_crypto_price(crypto: str, currency: str, max_attempts: int = 3) -&gt; float | None: &quot;&quot;&quot; Retrieves the price of a cryptocurrency in a specified currency using the CoinGecko API. Args: crypto (str): The cr...
<python><visual-studio-code>
2023-04-13 20:29:39
3
27,200
GollyJer
76,009,540
19,980,284
Pandas to_csv but remove NaNs on individual cell level without dropping full row or column
<p>I have a dataframe of comments from a survey. I want to export the dataframe as a csv file and remove the NaNs without dropping any rows or columns (unless an entire row is NaN, for instance). Here is a sample of the dataframe:</p> <p><a href="https://i.sstatic.net/e1HCc.png" rel="nofollow noreferrer"><img src="http...
<python><pandas><dataframe><export-to-csv><missing-data>
2023-04-13 20:22:19
1
671
hulio_entredas
76,009,381
395,857
How can I convert a dictionary containing key and value as list into a panda dataframe with one column for keys and one column for values?
<p>I have this dictionary:</p> <pre><code>data = {'key1': [2, 6, 7], 'key2': [9, 5, 3]} </code></pre> <p>How can I convert it into this pandas dataframe</p> <pre><code> key value 0 key1 2 1 key1 6 2 key1 7 3 key2 9 4 key2 5 5 key2 3 </code></pre> <p>?</p> <hr /> <p>I tried:</p> <pre><code>impor...
<python><pandas><dataframe><dictionary>
2023-04-13 20:00:06
3
84,585
Franck Dernoncourt
76,009,262
5,032,387
Incorrect prediction using LSTM many-to-one architecture
<p>I'm predicting 12 months of data based on a sequence of 12 months. The architecture I'm using is a many-to-one LSTM, where the ouput is a vector of 12 values. The problem is that the predictions of the model are way out-of-line with the expected - the values in the time series are around 0.96, whereas the predicti...
<python><keras><lstm>
2023-04-13 19:42:02
0
3,080
matsuo_basho
76,008,794
11,712,575
Python Boto3 not connecting to localstack
<p>I am trying to simulate a dynamoDB on localstack, and I have my python running in a docker container and localstack running with environmental variables SERVICES=dynamodb,sqs</p> <p>I also have another docker container running python and it is running all in the same network.</p> <p>Here is a general overview:</p> <...
<python><amazon-web-services><docker><boto3><localstack>
2023-04-13 18:40:09
0
389
Jason Chan
76,008,753
8,372,455
How is Pandas rolling average calculated?
<p>I have a project that logs data every approximately every second into a Pandas df for a few columns of numeric sensor values and also a time stamp column. A project requirement is taking in data on a 5 minute rolling average, running some fault checks, and then clearing the data frame.</p> <p>If I am clearing the da...
<python><pandas>
2023-04-13 18:34:16
1
3,564
bbartling
76,008,731
12,300,981
How to generate numpy arrays of different sizes (e.g. objects) but then apply mathematical operations on them
<p>I am attempting to do a minimization via sum of squares, but my global minimization I am doing has arrays of different sizes. I am trying to minimize using all data sets, even though they are different sizes.</p> <p>I.E.</p> <pre><code>data_1=[[1,2],[2,3]] data_2=[[3,4],[5,6],[6,7]] model_1=[[1,1],[2,2]] model_2=[[3...
<python><numpy>
2023-04-13 18:31:28
2
623
samman
76,008,688
1,966,871
In python 3, how can one add an assertion about the value of particular class attributes at testing time via mocking?
<p>I have a value that is set early on in processing a fairly complex HTTP request, and I need my unit test to assert that this value is set properly in a private attribute of a class deep in the bowels of implementation.</p> <p>It seems to me that the easiest way to do this is to mock out a function in that class that...
<python><python-3.x><unit-testing>
2023-04-13 18:24:14
0
306
enkiv2
76,008,649
8,228,382
Python cronjob won't run in Docker container
<p>I am trying to install Python dependencies using <code>Poetry</code> and then run a Python script in a <code>Docker</code> container using a <code>cronjob</code>. However, the python script doesn't execute as expected, and I can't figure out what tweaks to my Docker/crontab setup is causing problems. I have followed...
<python><docker><cron><python-poetry>
2023-04-13 18:19:07
1
675
ColinB
76,008,563
4,764,787
How to complete FastAPI Google OAuth flow
<p>I followed the <a href="https://fastapi.tiangolo.com/tutorial/security/" rel="nofollow noreferrer">official tutorial</a> and was able to set up the security system for a username and password. But instead of (or in addition to) username and password, I want to set up a Google OAuth flow. For that I've followed this ...
<python><security><google-oauth><fastapi>
2023-04-13 18:06:11
0
381
Jaime Salazar
76,008,561
1,691,186
Why is Mace4 valuation not working in my Python program?
<p>Here is a very simple example of the use of Mace4, taken directly from the NLTK Web site:</p> <pre><code>from nltk.sem import Expression from nltk.inference import MaceCommand read_expr = Expression.fromstring a = read_expr('(see(mary,john) &amp; -(mary = john))') mb = MaceCommand(assumptions=[a]) mb.build_model() ...
<python><nltk><inference>
2023-04-13 18:06:04
1
938
yannis
76,008,523
16,935,119
Merge based on common values
<p>Is there a way to merge column based on common values and return NAN if there is no match. I tried below code but the output is wierd. Even though there is no match, the values are returning</p> <pre><code>import pandas as pd data2 = {'Name' : ['Tom', 'Nick', 'f']} d2 = pd.DataFrame(data2) data1 = {'Name' : ['Tom'...
<python><pandas>
2023-04-13 18:00:33
3
1,005
manu p
76,008,514
3,482,266
Comparing two lists of instances of the same class, by a specific instance attribute only
<p>I have two lists of instances of the class below. I want to compare whether the two lists contain the same data (order is unimportante) in the doc_data attribute.</p> <pre><code>class Class_Test: type: str def __init__(self, doc_data: Dict, meta_data: Dict): self.doc_data = doc_data self.meta...
<python>
2023-04-13 17:59:20
1
1,608
An old man in the sea.
76,008,438
17,596,237
Firebase realtime database permission error even though rules playground simulation succeeds
<p>My database has a <code>users</code> child with fields <code>email</code> and <code>name</code>, with the key being the users uid. Here are the database rules:</p> <pre><code>{ &quot;rules&quot;: { &quot;users&quot;: { &quot;$uid&quot;: { &quot;email&quot;: { &quot;.read&quot;: &qu...
<python><database><firebase><firebase-realtime-database><pyrebase>
2023-04-13 17:51:01
2
678
Jacob
76,008,308
9,018,649
What does "func.QueueMessage) -> None:" do in python?
<p>In an python azure function i need to upgrade i got:</p> <pre><code>def main(msg: func.QueueMessage) -&gt; None: </code></pre> <p>def main - is the entry point of the program , and main is a function name. But other then that i'm blank.</p> <p>What does the rest of the code actually mean/do?</p>
<python><azure>
2023-04-13 17:31:18
0
411
otk
76,008,125
2,893,712
SQL INSERT but increment ID if exist without having to do separate SELECT query
<p>I have a table with Primary Key on two columns: <code>ID</code> (Users ID) and <code>SQ</code> (Sequence, this starts at 1 and increments +1 for each <code>ID</code>). A user should not have multiple instances of the same sequence #. Here is how the table looks:</p> <pre><code>ID SQ Code ------ -- ---- 1...
<python><sql><sql-server><sql-insert>
2023-04-13 17:08:00
2
8,806
Bijan
76,008,084
11,720,193
SOAP Response XML Error in AWS Glue job (Python)
<p>I am very new to AWS Glue. I have coded the following script in Glue which sends a SOAP request to a website and it's response is stored in S3. Even though the job is running successfully, the xml response which is being received (and saved on s3 object) is throwing error. However, the same program is running perfec...
<python><soap><aws-glue>
2023-04-13 17:03:22
1
895
marie20
76,007,953
12,990,915
Read HDF - Dealing with Hierarchy via Pandas
<p>I would like to read an hdf5 file <code>2D_rdb_NA_NA.h5</code>. The file has parent groups: <code>0000</code> <code>0001</code> <code>0002</code> etc. Each parent group has child groups <code>data</code> and <code>grid</code>.</p> <p>Here is what I have attempted so far:</p> <pre><code>import h5py import pandas as p...
<python><pandas><h5py>
2023-04-13 16:47:55
2
383
user572780
76,007,874
735,926
How to test a FastAPI route that retries a SQLAlchemy insert after a rollback?
<p>I have a route where I want to retry an insert if it failed due to an <code>IntegrityError</code>. I’m trying to test it using pytest and httpx but I get an error when I reuse the session to retry the insert after the rollback of the previous one. It works fine if I test with <code>curl</code>.</p> <p>I use Python 3...
<python><sqlalchemy><fastapi><httpx><pytest-asyncio>
2023-04-13 16:38:21
1
21,226
bfontaine
76,007,760
6,087,667
Inserting values into multiindexed dataframe with sline(None)
<p>I am trying to insert entries on each first level but it fails:</p> <pre><code>import string alph = string.ascii_lowercase n=5 inds = pd.MultiIndex.from_tuples([(i,j) for i in alph[:n] for j in range(1,n)]) t = pd.DataFrame(data=np.random.randint(0,10, len(inds)), index=inds).sort_index() # inserting value np.nan ...
<python><pandas><dataframe>
2023-04-13 16:26:03
1
571
guyguyguy12345
76,007,636
3,210,927
How can I (and should I?) acceptance test a simple Flask app without importing unnecessary libraries?
<p>I'm relatively new to Python and entirely new to Flask. I'm trying to create a Flask app that at least initially consists of little more than a couple of forms, some number crunching based on the values you submit and then a page displaying the outcome. It will probably never have a database.</p> <p>The in-progress ...
<python><flask><pytest>
2023-04-13 16:12:23
1
889
Arepo
76,007,606
7,479,376
Bigquery: cannot keep field description
<p>I've created an empty table in Bigquery:</p> <pre><code>import bigquery schema = [ bigquery.SchemaField(name=&quot;id&quot;, field_type=&quot;INTEGER&quot;, description='user ID', mode=&quot;REQUIRED&quot;), bigquery.SchemaField(n...
<python><google-cloud-platform><google-bigquery>
2023-04-13 16:09:17
1
3,353
Galuoises
76,007,394
18,018,869
Repeat given array to more complex shape
<p>I want to create an array of shape <code>(3, 3, 4)</code>. The data to populate the array with is given.</p> <p>My solution right now works perfectly fine but feels like I am missing a numpy lesson here. I do not want to do multiple <code>.repeat()</code>s over and over.</p> <pre class="lang-py prettyprint-override"...
<python><numpy><multidimensional-array>
2023-04-13 15:45:26
3
1,976
Tarquinius
76,007,383
4,422,095
How to use `@task` decorator in Airflow to return outputs from wrapped function
<p>I'm confused how the <code>@task</code> decorator is supposed to be used in Airflow when working with large amounts of data.</p> <p>For most situations where I work with data, I am typically dealing with several transformations of that data. I use various assorted methods for this and the methods I use typically hav...
<python><airflow>
2023-04-13 15:44:41
2
2,244
Stan Shunpike
76,007,323
19,198,552
Why is the generated tkinter button-1 event not recognized?
<p>I have 2 canvas rectangles, which have a binding for Button-1. Sometimes I want that when one rectangle gets this event, then the other rectangle should also get this event. So I have to duplicate the Button-1 event by the widget method &quot;event_generate&quot;.</p> <p>My example code is kind of minimal, so you ca...
<python><tkinter><events><canvas>
2023-04-13 15:36:59
2
729
Matthias Schweikart
76,007,313
11,926,527
Python code to remove the end of document is not working
<p>I am using python-docx to clean up multiple Word documents.</p> <p>The following code is supposed to find paragraphs which contain only one word and the word is among the list provided, case-insensitive, and then remove the remaining text from the document. However, it is not working. I can't figure out the reason!<...
<python><ms-word>
2023-04-13 15:36:06
1
392
Leila
76,007,296
9,314,961
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'angry'
<p>I am new to python and I was trying the SER solution at '<a href="https://github.com/mldmxm/CTL-MTNet" rel="nofollow noreferrer">https://github.com/mldmxm/CTL-MTNet</a>'. I downloaded the publicly available 'SAVEE' and 'EMODB' speech emotion datasets from the internet and added them to the 'CAAM_Code' folder as show...
<python><speech-recognition>
2023-04-13 15:34:47
0
311
RMD
76,007,288
2,478,485
How to check if system is installed with latest python version (python3.10)?
<p>I am using following <code>shell</code> command to find the latest <code>python</code> is installed</p> <pre><code>$ python3 -c 'import sys; print(sys.version_info)' sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0) </code></pre> <p>But this command is returning the default python version...
<python><python-3.x><bash><shell>
2023-04-13 15:34:02
2
3,355
Lava Sangeetham
76,007,269
1,668,622
How to avoid mypy complaints when inheriting from a built-in collection type?
<p>Running <code>mypy</code> on code like this</p> <pre class="lang-py prettyprint-override"><code>class MySpecialList(list): # funky extra functionality </code></pre> <p>gives me</p> <pre><code>my_file.py:42: error: Missing type parameters for generic type &quot;list&quot; [type-arg] </code></pre> <p>I can avoid t...
<python><python-3.x><mypy>
2023-04-13 15:30:58
1
9,958
frans
76,007,259
8,602,367
Question and answer over multiple csv files in langchain
<p>I've a folder with multiple csv files, I'm trying to figure out a way to load them all into langchain and ask questions over all of them.</p> <p>Here's what I have so far.</p> <pre><code>from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma from langchain.text_splitter im...
<python><python-3.x><langchain>
2023-04-13 15:29:23
3
1,605
Dave Kalu
76,007,256
8,849,755
Importing Python module in C++ not in main
<p>I want to use a Python module within C++. In all examples I find (<a href="https://docs.python.org/3/extending/embedding.html" rel="nofollow noreferrer">doc</a>, <a href="https://stackoverflow.com/a/24687260/8849755">SO1</a>, <a href="https://stackoverflow.com/a/39840385/8849755">SO2</a>) they do things like <code>P...
<python><c++>
2023-04-13 15:29:02
1
3,245
user171780
76,007,207
889,742
Python3 and VSCode ModuleNotFoundError: No module named '_ctypes'
<p>I'm working with Visual Code and Python 3 and am getting a</p> <blockquote> <p>ModuleNotFoundError: No module named '_ctypes' error.</p> </blockquote> <p>error on my laptop. ( A similar setup works on my desktop )</p> <p>It turns out that VS code is pointing to a python version installed by chocolatey.</p> <p>I was ...
<python><visual-studio-code><modulenotfounderror>
2023-04-13 15:21:59
2
6,187
Gonen I
76,007,165
12,292,254
Speeding up the process of list-appending via if else statements
<p>I have a list that contains strings that are a combination of &quot;A&quot;, &quot;B&quot; and &quot;C&quot;.</p> <p>For example:</p> <pre><code>abc_list = [&quot;AB&quot;, &quot;AC&quot;, &quot;AB&quot;, &quot;BC&quot;, &quot;BB&quot;, ...] </code></pre> <p>I now want to create a new list that translates every elem...
<python><numpy>
2023-04-13 15:18:56
1
460
Steven01123581321
76,007,123
807,149
Error b'' trying to install psycopg2 on AIX 7.2
<p>I am trying to install psycopg2==2.9.6 on AIX 7.2. The first thing I did was install postgresql 13.10 from source in order to get pg_config.</p> <p>Now when I try to run <code>setup.py build</code> I get this blank error message:</p> <pre><code>python -v setup.py build ... running build_ext # /opt/freeware/lib64/py...
<python><psycopg2><aix>
2023-04-13 15:15:29
1
958
Nolan
76,007,112
14,269,252
Finding the words or sentence that is followed by a search word and put them into a dictionary python
<p>I have to find the words or sentence that follow a search word and put them into a dictionary. My data is in the pdf which I already extract it to a text using PyPDF2 library. I am new to NLP and I don't know how to implement this part of code. I know how to find 1 word that follows the search word, but sometimes it...
<python><nlp>
2023-04-13 15:14:37
2
450
user14269252
76,007,004
2,015,669
How to calculate individual documents score BM25F score for each document?
<p>I a trying to implement BM25F from scratch in Python. Here is the simplified folumation of the BM25F:</p> <p><a href="https://i.sstatic.net/pXLnf.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pXLnf.jpg" alt="enter image description here" /></a></p> <p>However, after implementing it, I am getting the...
<python><ranking><information-retrieval><ranking-functions>
2023-04-13 15:04:18
0
640
HQuser
76,007,000
19,392,385
Captions of slider not visible (VPython)
<p>I have create a little 3d simulation with VPython. And with it sliders to control positions and colors or objects. However, I can't find a way to display a caption to indicate what is the slider about.</p> <p>I have added an argument when defining the slider <code>wtitle</code>. I don't get any error message so I as...
<python><3d><slider><vpython>
2023-04-13 15:04:03
2
359
Chris Ze Third
76,006,978
21,420,742
How to find past values by ID in Python
<p>I have a dataset that looks at all employees' history. The goal I am trying to get to is see an employees current manager and previous manager only if that previous manager has left without being replaced. To identify if a manager has left you look at the <strong>ManagerPositionNum</strong> this column is unique to ...
<python><python-3.x><pandas><dataframe><numpy>
2023-04-13 15:01:43
1
473
Coding_Nubie
76,006,901
12,362,355
How to use local Apple M1 GPU in a Colab note in a local run time
<p>Hi I'm new to Colab and deep learning. I'm practising a piece of Colab code (from the web) in which it imports a bunch packages and checks for GPU access.</p> <pre><code>!nvcc --version !nvidia-smi import os, shutil import numpy as np import matplotlib.pyplot as plt from cellpose import core, utils, io, models, me...
<python><deep-learning><gpu><google-colaboratory><apple-m1>
2023-04-13 14:53:37
0
415
ML33M
76,006,794
2,758,414
Is someone trying to hack into my Django app?
<p>I have a Django app (personal project) running live in production on Azure VM.</p> <p>I have looked in <code>/var/log/django.log</code> and I can see a long list of warnings. These look like someone is trying to scan my VM/app in order to find <code>.env</code> file, login credentials, etc.</p> <pre><code>2023-04-13...
<python><django><azure><security><.env>
2023-04-13 14:43:50
2
2,747
LLaP
76,006,789
11,462,274
How to adjust the image to meet the minimum requirements and avoid receiving the Telegram API Bad Request error: PHOTO_INVALID_DIMENSIONS?
<p>Summary: Telegram has requirements for images that are sent, and to avoid failures, I add huge white borders far above what would be the minimum necessary. I would like to know how I could create a method so that the image is adjusted at once but with the minimum borders required.</p> <p>According to the documentati...
<python><python-imaging-library><telegram><telegram-bot>
2023-04-13 14:43:18
1
2,222
Digital Farmer
76,006,716
1,897,722
Performance of Scipy lsim/lsim2
<p>In a python script of mine, I currently use the <a href="https://scipy.github.io/devdocs/reference/generated/scipy.signal.lsim.html#scipy.signal.lsim" rel="nofollow noreferrer">lsim</a> function to simulate a system model. An issue I encountered recently is that lsim spawns a lot of subprocesses on multiple cores, a...
<python><performance><scipy>
2023-04-13 14:36:31
1
377
Daiz
76,006,687
601,862
Python updating 1 single element cause the entire column updated in a 2 dimentional array
<p>I have a 10 by 10 matrix which has dic as element. When I only want to update a single value, it ends up updating all values in that column. Why? and How to fix it?</p> <pre><code>m = [[{}] * 10]*10 m[0][0] = {&quot;a&quot;:1} </code></pre> <p><a href="https://i.sstatic.net/VACCj.png" rel="nofollow noreferrer"><img...
<python>
2023-04-13 14:33:44
0
7,147
Franva
76,006,681
10,638,529
AssertionError: 400 != 201 Unit Test Django REST Framework with drf-yasg
<p>i am creating an unittest for a endpoint POST that i created:</p> <p>Endpoint:</p> <pre><code>class AddJokeAPI(generics.ListAPIView): serializer_class = JokeSerializer queryset = Joke.objects.all() query_param = openapi.Parameter('text', openapi.IN_QUERY, description=&quot;Nu...
<python><django><unit-testing><django-rest-framework><drf-yasg>
2023-04-13 14:33:23
1
664
Luis Bermúdez
76,006,674
4,036,532
Get from Pandas dataframe column to features for scikit-learn model
<p>Let's say I have a dataframe that looks like this:</p> <pre><code>import pandas as pd import numpy as np vectors = pd.Series([[1.0, 2.0, 3.0], [0.5, 1.5, 2.5], [0.1, 1.1, 2.1]], name='vector') output = pd.Series([True, False, True], name='target') data = pd.concat((vectors, output), axis=1) </code></pre> <p><code...
<python><pandas><numpy><scikit-learn>
2023-04-13 14:32:58
2
2,202
Katya Willard
76,006,647
4,253,946
Payload clarification for Langchain Embeddings with OpenAI and Chroma
<p>I have created the following piece of code using <a href="https://en.wikipedia.org/wiki/IPython#Project_Jupyter" rel="nofollow noreferrer">Jupyter Notebook</a> and <code>langchain==0.0.134</code> (which in my case comes with <code>openai==0.27.2</code>). The code takes a CSV file and loads it in <a href="https://pyt...
<python><wireshark><openai-api><chatgpt-api><langchain>
2023-04-13 14:29:59
0
376
Edu
76,006,453
3,447,369
How do I make the calculation for this distance matrix faster?
<p>I am working on a clustering task with geospatial data. I want to compute my own distance matrix that combines both geographical and temporal distance. My data (<code>np.array</code>) contains latitude, longitude, and timestamp. A sample of my DataFrame <code>df</code> (<a href="https://justpaste.it/bc1fr" rel="nofo...
<python><scikit-learn><cluster-analysis><distance>
2023-04-13 14:11:42
1
1,490
sander
76,006,442
7,741,772
to get iteration count and total count over the rows from a column in table
<p>We have a database table(source) with some million records in a table : Sample data like (extracted to a text file for sample)</p> <pre><code> denied the payment the payment successfull and incident reported successfull Incident is been reported </code></pre> <p>while trying to get the distint words count on these...
<python><sql><bash>
2023-04-13 14:09:51
1
873
Ravi
76,006,381
1,913,115
How to add a shortcut to a custom script in pyproject.toml (using poetry)
<p>I recently switched to Poetry from Pipenv. I'm used to having this section in my Pipfile:</p> <pre><code>[scripts] test=&quot;pytest -s&quot; test:watch=&quot;ptw --runner 'pytest -s'&quot; </code></pre> <p>so I can easily run my tests without typing out the full command or entering the shell, e.g.:</p> <pre class="...
<python><python-poetry><pyproject.toml>
2023-04-13 14:03:48
2
6,363
ierdna
76,006,319
4,837,637
Python change dinamically json key
<p>I have a specific JSON file that I read and change dynamically the value of key. I'm using this code to do this:</p> <pre class="lang-py prettyprint-override"><code>with open('payload/run_job.json', 'r+') as f: data = json.load(f) data['name'] = 'test' result = json.dumps(data, sort_keys=True) pprint...
<python><arrays><json>
2023-04-13 13:57:40
1
415
dev_
76,006,315
4,019,495
Is there a Pydantic convention for a Model attribute that will default to a function of another attribute?
<p>I want to define a Pydantic <code>BaseModel</code> with the following properties:</p> <ul> <li>Two <code>int</code> attributes <code>a</code> and <code>b</code>.</li> <li><code>a</code> is a required attribute</li> <li><code>b</code> is optional, and will default to <code>a+1</code> if not set.</li> </ul> <p>Is ther...
<python><python-typing><pydantic>
2023-04-13 13:57:15
1
835
extremeaxe5
76,006,275
14,022,582
How to drop duplicate rows using value_counts and also using a condition that uses the actual value in a column using pandas?
<p>I have the following dataframe. I want to group by <code>a</code> first. Within each group, I need to do a value count based on <code>c</code> and only pick the one with most counts if the value in <code>c</code> is not <code>EMP</code>. If the value in <code>c</code> is <code>EMP</code>, then I want to pick the one...
<python><sql><pandas>
2023-04-13 13:53:17
3
969
user42
76,006,269
19,500,571
Python Dash: Fitting a table and a graph in one row of a grid
<p>I am trying to fit a table and a graph in one single row of a grid. I have tried to resize both of them to fit by setting the <code>style</code>, but for some odd reason the table is placed beneath the graph.</p> <p>Here is the code. What is it caused by?</p> <pre><code>from dash import Dash, dcc, html, Input, Outpu...
<python><html><plotly><plotly-dash><dashboard>
2023-04-13 13:52:22
1
469
TylerD
76,006,099
1,884,953
in Python, how to overwrite the str for a module?
<p>When one types the name of a module and then hits return, one gets a string like below</p> <pre><code>import pandas as pd pd &lt;module 'pandas' from '....'&gt; </code></pre> <p>How can I overwrite this string for my own module ? (Please note that I am referring to a module, not to a class) For example adding a tex...
<python><string><overwrite>
2023-04-13 13:36:15
2
303
minivip
76,006,042
2,302,262
Dictionary unpacking in python
<p>For a list, I can split it with one compact line of code:</p> <pre class="lang-py prettyprint-override"><code>i_ate = ['apple', 'beetroot', 'cinnamon', 'donut'] # Elaborate first = i_ate[0] rest = [item for j, item in enumerate(i_ate) if j != 0] # Shortcut first, *rest = i_ate # Result in both cases: first # 'app...
<python><dictionary>
2023-04-13 13:30:30
1
2,294
ElRudi
76,006,023
8,510,613
How to export c++ class adopted template method pattern with virtual interface to python world by pybind11?
<p>We have a class hierarchy which follow the template method pattern. The <code>Interface</code> class has a pure virtual method <code>process()</code>. class <code>AbstractImpl</code> inherit it and fill the <code>process</code> body with some pure virtual <code>stepX</code> method. Finally, derived class <code>Concr...
<python><c++><pybind11>
2023-04-13 13:28:24
1
1,282
user8510613
76,006,019
9,601,748
How can I get the index number of a row in a pivoted table with python/pandas?
<p>So I have this pivot table, 'movieUser_df':</p> <p><a href="https://i.sstatic.net/1r4uc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1r4uc.png" alt="enter image description here" /></a></p> <p>And I need to be able to get the index number of any row based on userID.</p> <p>I can locate the row easi...
<python><pandas>
2023-04-13 13:28:18
1
311
Marcus
76,005,968
5,091,467
OneHotEncoder -- keep feature names after encoding categorical variables
<h3>Question</h3> <p>After encoding categorical columns as numbers and pivoting LONG to WIDE into a sparse matrix, I am trying to retrieve the category labels for column names. I need this information to interpret the model in a latter step.</p> <h3>Solution</h3> <p>Below is my solution, which is really convoluted, ple...
<python><pandas><one-hot-encoding>
2023-04-13 13:23:47
1
714
Dudelstein
76,005,807
6,658,422
Tornado plot using seaborn objects
<p>I would like to create a tornado plot using seaborn objects and was wondering if there was an efficient way to do this.</p> <pre><code>import numpy as np import pandas as pd import seaborn.objects as so # create a dataframe with the columns id, gender, and age with random values df = pd.DataFrame({'id':np.random.ra...
<python><seaborn><seaborn-objects>
2023-04-13 13:06:51
0
2,350
divingTobi
76,005,798
37,213
NumPy SVD Does Not Agree With R Implementation
<p>I saw a <a href="https://stackoverflow.com/questions/75998775/python-vs-matlab-why-my-matrix-is-singular-in-python">question about inverting a singular matrix</a> on Stack Overflow using NumPy. I wanted to see if NumPy SVD could provide an acceptable answer.</p> <p>I've demonstrated using <a href="https://stackover...
<python><numpy><svd>
2023-04-13 13:06:21
1
309,526
duffymo
76,005,681
3,595,907
Want to save image using OpenCV but Matplotlib insists I save a figure instead
<p>OpenCV 4.7, Matplotlib 3.7.1, Spinnaker-Python 3.0.0.118, Python 3.10, Win 10 x64</p> <p>I'm acquiring images from a FLIR thermal camera via their <a href="https://www.flir.co.uk/products/spinnaker-sdk/" rel="nofollow noreferrer">Spinnaker API</a>.</p> <p>I am displaying the images using OpenCV &amp; concurrently di...
<python><opencv><matplotlib><flir>
2023-04-13 12:53:43
1
3,687
DrBwts
76,005,506
8,182,504
pyqtgraph's GraphicsWidgetAnchor class incomplatible with PySide6
<p>I've written an application that uses <strong>PySide6</strong> and <strong>pyqtgraph</strong>. Now, I upgraded all my Python packages (<em>PySide 6.5.0</em> and <em>pyqtgraph 0.13.2</em>, <em>Python 3.10</em>) and that code crashes. I was wondering what changed since that and apparently, the following line seems to ...
<python><pyqtgraph><pyside6>
2023-04-13 12:35:39
0
1,324
agentsmith
76,005,401
8,248,194
Can't install xmlsec via pip
<p>I'm getting the following when running <code>pip install xmlsec</code> in macOS Big Sur 11.3.1:</p> <pre><code>Building wheels for collected packages: xmlsec Building wheel for xmlsec (PEP 517) ... error ERROR: Command errored out with exit status 1: command: /Users/davidmasip/.pyenv/versions/3.9.9/bin/python...
<python><macos><pip><homebrew><xmlsec>
2023-04-13 12:24:18
4
2,581
David Masip
76,005,396
15,845,509
How to understand print result of byte data read from a pickle file?
<p>I am trying to get data from pickle file. As I know, when we do serialization, the data is converted into byte stream. When I read the data as binary using this code:</p> <pre><code>f = open(&quot;alexnet.pth&quot;, &quot;rb&quot;) data = f.read() </code></pre> <p>I got this result</p> <blockquote> <p>b'PK\x03\x04\x...
<python><hex><pickle>
2023-04-13 12:24:08
1
369
ryan chandra
76,005,347
10,282,088
Ace linters - All annotations are of type error
<p>I m using ace-linters for ace editor to perform linting for languages like python, sql, json etc</p> <p>The linting works pretty good with the help of web workers. It returns the proper annotations. But all the annotations are marked as error type even if some of them, according to me, should be warning annotations....
<python><angular><ace-editor>
2023-04-13 12:18:41
1
538
Abdul K Shahid