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
βŒ€
75,893,753
10,565,820
How to write decorator without syntactic sugar in python?
<p>This question is rather specific, and I believe there are many similar questions but not exactly like this.</p> <p>I am trying to understand syntactic sugar. My understanding of it is that by definition the code always can be written in a more verbose form, but the sugar exists to make it easier for humans to handle...
<python><properties><decorator><syntactic-sugar>
2023-03-30 23:41:29
2
644
geckels1
75,893,730
4,635,580
Can multiple processes creating the same intermediate directories get into a race condition in UNIX?
<p>Given this piece of Python code</p> <pre class="lang-py prettyprint-override"><code>from pathlib import Path def create_dir(last_component: str): path = Path(&quot;l1/l2&quot;) / last_component path.mkdir(parents=True, exist_ok=True) </code></pre> <p>If there two concurrent processes, not threads, that at ...
<python><linux><unix><concurrency>
2023-03-30 23:35:48
0
739
Isaac To
75,893,723
12,561,168
Sum of numbers "around" a number with NumPy
<p>Say I have a NumPy array like this:</p> <pre><code>[[100. 100. 100. 100. 100.] [100. 0. 0. 0. 100.] [100. 0. 0. 0. 100.] [100. 0. 0. 0. 100.] [100. 100. 100. 100. 100.]] </code></pre> <p>I'd like to take the middle values:</p> <pre><code>0. 0. 0. 0. 0. 0. 0. 0. 0. </code></pre> <p>...
<python><numpy><vectorization>
2023-03-30 23:33:47
3
603
jianmin-chen
75,893,685
1,185,242
Why is this shapely polygon invalid?
<pre><code>from shapely.wkt import loads polygon = loads(&quot;POLYGON Z ((11.2704142515539 8.935877943566396 -16.74699224693797, 9.552838743503662 9.966533722939751 -16.77349242463657, 7.038910673892143 11.41232301137523 -16.7241410803892, 5.216749880203796 12.46026879775946 -16.68836982474948, 8.001220401932684 17.16...
<python><shapely>
2023-03-30 23:22:18
1
26,004
nickponline
75,893,669
3,894,471
Creating a list of outputs from a function with unknown number of variables and possible variable values
<p>Let me start with a quick example:</p> <pre><code>def my_fun(dict): # do stuff return dict_1 = { &quot;A&quot;: np.arange(0,4,1), &quot;B&quot;: np.arange(10, 20, 1), &quot;C&quot;: np.arange(3,13,2) } for a in dict_1[&quot;A&quot;]: for b in dict_1[&quot;B&quot;]: for c in dict_1[&quot;C&quot;]: t...
<python><python-3.x><loops>
2023-03-30 23:19:09
1
537
John
75,893,577
10,998,672
How to add folders in sharepoint using office365-rest-python-api
<p>I have registered an application in sharepoint with read and write access to the site. I want to create folders with subfolders and I found solution in official documentation:</p> <pre><code>def create_folder(dir_path): ctx = auth() target_folder_url = dir_path target_folder = ctx.web.ensure_folder_path(...
<python><azure><sharepoint><office365api>
2023-03-30 22:55:44
1
1,185
martin
75,893,562
417,678
Flask-SocketIO in Webpack, can't get messages from server back to client
<p>When I'm using just plain Flask <code>FLASK_APP=web_server.py flask run --host=0.0.0.0</code> for development purposes, I can receive messages from the client (http and websocket). When I want to send messages back after an event, they don't seem to be received by the browser. I'm not sure where they're going. I hav...
<python><flask><webpack><websocket><webpack-dev-server>
2023-03-30 22:53:13
1
6,469
mj_
75,893,532
10,530,575
Convert dataframe to list of record WITHOUT brackets
<p>I have a dataframe</p> <pre><code>import pandas as pd d = { &quot;letter&quot;: [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]} df = pd.DataFrame(d) </code></pre> <p><a href="https://i.sstatic.net/U9kPD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/U9kPD.png" alt="enter image description here" /></a>...
<python><pandas><dataframe>
2023-03-30 22:45:40
3
631
PyBoss
75,893,429
4,061,339
A widget disappers when a button is clicked twice in streamlit in Python
<h1>What I want to achieve</h1> <p>To show a widget only when a button is clicked in streamlit. The return value of a time-consuming operation will be loaded to the widget. While the operation is being done, the button is disabled. Every time the button is clicked, the new value of the operation will be loaded to it.</...
<python><html><button><widget><streamlit>
2023-03-30 22:24:05
1
3,094
dixhom
75,893,268
2,801,404
Is it possible to modify YOLOv8 to use it as a feature extractor for other tasks?
<p>I'm reading through the documentation of YOLOv8 <a href="https://docs.ultralytics.com/#where-to-start" rel="nofollow noreferrer">here</a>, but I fail to see an easy way to do what I suggest in the title. What I want to do is to load a pretrained YOLOv8 model, create a bigger model that will contain YOLOv8 as a submo...
<python><deep-learning><pytorch><computer-vision><yolo>
2023-03-30 21:48:50
1
451
Pablo Messina
75,893,026
3,788,557
uploading a png/plot to s3 bucket?
<p>I can't figure out how to write images to my s3 bucket. I use matplotlib and</p> <pre><code>import pandas as pd import boto3 import ploty.express as px path = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/monthly-car-sales.csv' data = pd.read_csv(path) data.rename(columns = {'Month':'ds', 'Sales...
<python><amazon-web-services><amazon-s3><plot><plotly>
2023-03-30 21:09:50
3
6,665
runningbirds
75,892,988
5,495,134
Imputation of mixed data types with pandas and Scikit-Learn
<p>I have to create a pre-processing pipeline dynamically to impute missing values, this is, I want to go through all the columns in a pandas data frame (which I don't know before-hand), and impute their missing values. To impute the missing values I use <code>sklearn.preprocessing.SimpleImputer</code></p> <p>I use a d...
<python><pandas><scikit-learn><scikit-learn-pipeline>
2023-03-30 21:06:03
0
787
Rodrigo A
75,892,941
2,809,512
How to use IPython.notebook.kernel.execute in Azure databricks?
<p>I have built an HTML JS based UI within azure databricks notebook <br> While trying to call a python function using kernel i keep getting IPython isnt available.</p> <pre><code>%%javascript function call_python_fn(cmdstr){ return new Promise((resolve,reject) =&gt; { var callbacks = { iopub: { ...
<python><azure><jupyter-notebook><databricks><azure-databricks>
2023-03-30 20:58:50
1
1,384
Hari Prasad
75,892,892
731,351
python polars: df partition with pivot and concat
<p>my goal was to groupby/partition by one column (a below), create a string identifier (b and c columns) then use this b_c identifier as a name for a column in a pivoted data frame. Code below works OK as far as I can tell, but the path to get the result is a bit twisted. So my question is: can this be done in a simp...
<python><python-polars>
2023-03-30 20:51:10
1
529
darked89
75,892,874
5,212,614
How can we melt a dataframe and list words under columns?
<p>I have a dataframe that looks like this.</p> <pre><code>import pandas as pd data = {'clean_words':['good','evening','how','are','you','how','can','i','help'], 'start_time':[1900,2100,2500,2750,2900,1500,1650,1770,1800], 'end_time':[2100,2500,2750,2900,3000,1650,1770,1800,1950], 'transaction'...
<python><python-3.x><dataframe><pandas-melt>
2023-03-30 20:48:02
2
20,492
ASH
75,892,836
2,897,989
Huggingface Windows SYMLINK(?)/OSError - file that exists shows as missing
<p>Trying to <code>train.py</code> a new language on <a href="https://github.com/clovaai/donut" rel="nofollow noreferrer">donut</a> based on a corpora I generated with their synthDOG tool, running the command <code>python train.py --config config/base.yaml --exp_version &quot;base&quot;</code> on up-to-date Windows 11 ...
<python><huggingface-transformers>
2023-03-30 20:42:05
0
7,601
lte__
75,892,786
875,737
Process() fails macOS swift
<p>I am trying to run python script from my macOS app. So I added the following code:</p> <pre><code>public class func run(name: String, arguments: [String] = [], environment: [String: String] = [:]) -&gt; ScriptResponse { let result = self.runResolved(path: &quot;/usr/bin/which&quot;, arguments: [&quot;python...
<python><swift><macos><process>
2023-03-30 20:36:10
0
1,065
PiotrDomo
75,892,777
14,328,019
Plot error bars on a horizontal bar plot in seaborn
<p>How do you plot error bars, corresponding to 95% confidence intervals, on a horizontal bar plot in seaborn (i.e. bars from left to right, rather than bottom to top)?</p> <p>Adding the <code>errorbar=&quot;ci&quot;</code> argument does not work for me.</p>
<python><seaborn><bar-chart><confidence-interval><errorbar>
2023-03-30 20:34:20
1
349
RossB
75,892,537
8,537,770
How to put a string of json string representation into a json string: AWS eventbridge
<p>I hope the title makes sense. What I am trying to do is create the AWS cdk code to have an AWS eventbridge rule trigger a lambda function with static input. What the input needs to look like is this</p> <pre><code>&quot;&quot;&quot;{ &quot;resource&quot;: &quot;/{proxy+}&quot;, &quot;path&quot;: &quot;/jobs/send...
<python><amazon-web-services><aws-event-bridge>
2023-03-30 20:03:03
1
663
A Simple Programmer
75,892,498
20,102,061
Output to Tkinter textbox does not appear
<p>I am trying to log some output instead to output it to the console, I want it to write it inside a textbox that I have defined.</p> <p>The output should be in the <code>match-case</code> of the <code>proccess_input</code> function.</p> <p>Problem is, I don't know why but nothing appears anywhere... It does not appea...
<python><python-3.x><tkinter>
2023-03-30 20:00:59
1
402
David
75,892,493
6,654,451
Weird python sys.path module resolution behavior
<p>I produced a minimal example of behavior that I thought was weird.</p> <pre><code>β”œβ”€β”€ a β”‚Β Β  └── com β”‚Β Β  β”œβ”€β”€ __init__.py β”‚Β Β  └── x β”‚Β Β  β”œβ”€β”€ __init__.py β”‚Β Β  └── test1.py └── b └── com β”œβ”€β”€ __init__.py └── x β”œβ”€β”€ __init__.py └── test2.py </code></pre> <p>...
<python><sys.path>
2023-03-30 20:00:15
0
331
Alex Kyriazis
75,892,442
1,872,400
Connecting and Authenticating to Delta Lake on Azure Data Lake Storage Gen 2 using delta-rs Python API
<p>I am trying to connect and authenticate to an existing Delta Table in Azure Data Lake Storage Gen 2 using the Delta-rs Python API. I found the Delta-rs library from this StackOverflow question: <a href="https://stackoverflow.com/questions/67181870/delta-lake-independent-of-apache-spark">Delta Lake independent of Apa...
<python><authentication><azure-storage><azure-data-lake><delta-lake>
2023-03-30 19:54:36
5
573
user__42
75,892,343
9,536,233
eBay webscraping from different geographical locations is returning inconsistent number of results
<p>I have a small eBay webscraping project, in which I am collecting data on Pokemon Trading Card Games (TCG). I have a friendly scraper which only puts forth a request every 20 seconds or more. I was wondering if eBay shows me all items available, or a subset thereof, and unfortunately the latter is the case. I review...
<python><web-scraping><proxy><request><get>
2023-03-30 19:41:08
0
799
Rivered
75,892,309
15,474,270
How can i script entering as administrator to cmd?
<p>I'm writing this script in python, which needs to access to administrator privileges so it can start and stop services in Windows. I've found this line</p> <pre><code>runas /user:Administrator cmd </code></pre> <p>But it opens a prompt, which i can't fill with print, and even if i could, it opens cmd as administrato...
<python><windows><service><command-line-interface><elevated-privileges>
2023-03-30 19:36:22
1
493
Claudio Torres
75,892,172
19,253,406
What is the difference between exhausting a generator using "for i in generator" and next(generator)
<p>I want to learn how to use the return value of a generator (but this not what I'm concerned with now).</p> <p>After searching, they said that I can get the return value from <code>StopIteration</code> when the generator is exhausted, so I tested it with the following code:</p> <pre><code>def my_generator(): yiel...
<python><generator>
2023-03-30 19:19:30
2
338
Chicky
75,892,092
1,045,755
Replace rows in one data frame with rows from another
<p>I have a data frame that looks something like:</p> <pre><code>df1 = name code country type --------------------------------- ben 100 de l mic 200 nl s dan NaN NaN NaN bro NaN NaN NaN </code></pre> <p>I then have another data fr...
<python><pandas>
2023-03-30 19:09:13
2
2,615
Denver Dang
75,892,091
6,400,443
Polars - Glob read Parquet from S3 only read first file
<p>I try to read some Parquet files from S3 using Polars.</p> <p>Those files are generated by Redshift using UNLOAD with PARALLEL ON.</p> <p>The 4 files are : <code>0000_part_00.parquet</code>, <code>0001_part_00.parquet</code>, <code>0002_part_00.parquet</code>, <code>0003_part_00.parquet</code></p> <p>When I use : <c...
<python><amazon-s3><python-polars>
2023-03-30 19:09:09
2
737
FairPluto
75,891,977
2,270,422
Type hint pytz timezone
<p>I have a function that returns a <code>pytz.timezone('...')</code> object. For example for the function below, what should be the type hint for the return?</p> <pre><code>def myfunc(tz_str: str) -&gt; ????: return pytz.timezone(tz_str) </code></pre> <p>And in general, how should we type hint objects from installed...
<python><python-typing><pytz>
2023-03-30 18:53:43
4
685
masec
75,891,862
5,403,987
How to get pytest to not delete successful test directories
<p>I'm using pytest and it's been great. My tests use the <code>tmp_path</code> fixture to hold a bunch of outputs (log files, plots, etc.). I want to keep these so I have a record of what the performance of all tests are, not just pass/fail. That way as I make changes I can see whether things are faster or slower, dif...
<python><pytest>
2023-03-30 18:39:43
1
2,224
Tom Johnson
75,891,839
10,620,003
Define main file without defining the parameters in the main file
<p>I have two .py files, one is Setting.py and one is main.py.</p> <p>In the Setting.py file I have the following code:</p> <pre><code>a= 2 def foo(a): return a+2 </code></pre> <p>In the main file I have this:</p> <pre><code>import Setting if __name__ == '__main__': X = foo(a) </code></pre> <p>So, when I run t...
<python>
2023-03-30 18:37:04
1
730
Sadcow
75,891,657
1,586,200
Maximum of an array at indices provided in another array in Numpy
<p>Given an array <code>a = [0.51, 0.6, 0.8, 0.65, 0.7, 0.75, 0.9]</code> and an indices array <code>ind = [0, 1, 3, 1, 2, 2, 3]</code>. Find the maximum value for each value in index and replace that in the corresponding place in the array a. So here the output should be <code>out = [0.51, 0.65, 0.9, 0.65, 0.75, 0.75,...
<python><numpy><vectorization>
2023-03-30 18:15:47
0
9,075
Autonomous
75,891,653
4,162,689
How do you transform a Pandas data frame into category and list of items?
<p>I am trying to output a task list as PDF. The output should be</p> <ul> <li>Hallway <ul> <li>Task</li> <li>Task</li> <li>Task</li> </ul> </li> <li>Front Room <ul> <li>Task</li> <li>Task</li> <li>Task</li> </ul> </li> <li>[Room name] <ul> <li>Task</li> <li>...</li> </ul> </li> </ul> <p>I have the following Pandas dat...
<python><pandas><dataframe>
2023-03-30 18:15:26
1
972
James Geddes
75,891,632
1,562,489
Issues with running Elastic in Bitbucket piplines
<p>Hi can anyone help me debug an issue with Elastic in my CI/CD environment?</p> <p>Elastic is running locally (for development) and on their managed SaaS platform for staging and production.</p> <p>I have the following step in bitbucket pipelines</p> <pre><code> - step: &amp;unit_tests image: python:3.9 na...
<python><elasticsearch><cicd><bitbucket-pipelines>
2023-03-30 18:12:43
1
1,198
David Sigley
75,891,327
5,069,105
DataFrame downsampling
<p>In a DataFrame with too much resolution in column <code>H</code>, the goal is to downsample that column, and sum the values of the other columns.</p> <p>My column <code>H</code> is a float and does not represent time. The other columns are counters of events. So when downsampling H, the values from other columns mus...
<python><pandas><dataframe>
2023-03-30 17:34:08
2
1,789
Raf
75,891,269
4,623,227
How can I use Pytest with a local module not installed, without import errors
<p>I've tried other solutions with no luck (<code>pytest.ini</code>, <code>__init__.py</code> inside <code>test\</code>, <code>conftest.py</code>...)</p> <p>I have the following project structure:</p> <pre><code>. β”œβ”€β”€ module β”‚ β”œβ”€β”€ bar.py β”‚ β”œβ”€β”€ foo.py β”‚ β”œβ”€β”€ __init__.py β”‚ └── __main__.py └── tests β”œβ”€β”€ __init_...
<python><import><pytest>
2023-03-30 17:26:41
1
870
Susensio
75,891,080
9,157,212
Python: Optimization with Exponential Objective Function
<p>I am working on assignment problems. So far, I have been using <code>Gurobi</code> via gurobipy. In my current problem, I have an objective function with an exponential term. In gurobipy this would be</p> <pre><code>m.setObjective(ratings.prod(assign) ** 0.5, sense=GRB.MAXIMIZE) </code></pre> <p>but <code>**</code> ...
<python><optimization><gurobi>
2023-03-30 17:05:10
1
631
jkortner
75,891,046
18,769,241
combinations accross columns not yielding all possible values
<p>I have this dataframe:</p> <pre><code>12 2 17 16 4 16 2 19 11 </code></pre> <p>I want to get, accross its columns, the following output</p> <pre><code>[ [12,16,2],[2,4,19],[17,16,11],[[12,16,2],[2,4,19]],[[2,4,19],[17,16,11]],[[12,16,2],[2,4,19],[17,16,11]] ] </code></pre> <p>I have this code which yield t...
<python><pandas>
2023-03-30 17:00:04
2
571
Sam
75,890,891
4,151,075
How to make a compound generic type
<p>I'd like to make a generic compound type that will set different type hints (but related to each other) for different attributes of the class.</p> <p>I got this:</p> <pre><code>from typing import Generic, Literal, NewType, TypeVar AccessTokenType = TypeVar(&quot;AccessTokenType&quot;, bound=str) RefreshTokenType =...
<python><python-typing>
2023-03-30 16:42:33
0
1,269
Marek
75,890,876
8,713,442
How to maintain hash value even if order of column changes while calculating hash
<p>When we change the order of columns while finding hash its result is changing .Is there a way we can maintain this value even when order of column changes. We are using CDC in pysaprk using hash value . This is just an example with 2 columns. In actual we have 50-60 columns on which we need to check if any changed h...
<python><python-3.x><pyspark><hash>
2023-03-30 16:40:41
0
464
pbh
75,890,758
12,657,753
Access denied when uninstalling matplotlib with pip
<p>I want to uninstall matplotlib library with pip</p> <pre><code>$pip uninstall matplotlib </code></pre> <p>But I receive the following error:</p> <pre><code>ERROR: Exception: Traceback (most recent call last): File &quot;C:\Users\user\anaconda3\envs\work\lib\shutil.py&quot;, line 791, in move os.rename(src, rea...
<python><matplotlib><pip>
2023-03-30 16:29:05
1
663
TheGainadl
75,890,681
9,773,920
How to list all csv files from an s3 bucket using Pandas?
<p>I have the below code that pulls in all the folder names as well as file names from specific S3 bucket. How to modify this so it can read only files that ends with &quot;.csv&quot; and not all the folder names?</p> <pre><code>def lambda_handler(event, context): s3_client = boto3.client(&quot;s3&quot;) bucke...
<python><pandas><amazon-web-services><amazon-s3>
2023-03-30 16:19:23
1
1,619
Rick
75,890,628
4,436,572
dask_cudf/dask read_parquet failed with NotImplementedError: large_string
<p>I am a new user of <code>dask</code>/<code>dask_cudf</code>. I have a parquet files of various sizes (11GB, 2.5GB, 1.1GB), all of which failed with <code>NotImplementedError: large_string</code>. My <code>dask.dataframe</code> backend is <code>cudf</code>. When the backend is <code>pandas</code>, <code>read.parquet<...
<python><dask-dataframe><rapids><cudf>
2023-03-30 16:12:41
0
1,288
stucash
75,890,606
13,325,186
Resample pandas df with multiple groupbys so each condition has the same number of total days of data
<p>I have been going round in circles with this and haven't been able to figure it out.</p> <p>Suppose I have the following dataframe:</p> <pre><code>df = pd.DataFrame({ &quot;person_id&quot;: [&quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;, &quot;2&quot;, &q...
<python><pandas><datetime><resample>
2023-03-30 16:10:00
1
473
Dr Wampa
75,890,601
19,051,091
Error at custom image classification with PyTorch weight of size?
<p>Edit Question:</p> <p>I'm using my own black and white tiff images dataset and I created the model_0 as the videos I will put my code That's the error I got</p> <blockquote> <p>Given groups=1, weight of size [10, 1, 3, 3], expected input[32, 3, 128, 128] to have 1 channels, but got 3 channels instead</p> </blockquot...
<python><pytorch><pytorch-dataloader>
2023-03-30 16:08:39
1
307
Emad Younan
75,890,548
5,056,011
Getting an error when I run Python and scripts in LibreOffice\program directory from C# using IronPython
<p>I want to run the python version and scripts that are in the libreoffice\program directory on Windows from C# in Visual Studio 2022 using the latest version of IronPython. The .py script runs fine at the command line. When I use the following code it wants to use the default version, 3.9, installed by Visual Studio...
<python><c#><ironpython><libreoffice>
2023-03-30 16:02:59
1
1,474
Velocedge
75,890,540
3,595,907
OpenCV Python PIP install broken?
<p>Win 10 x64 Python 3.6</p> <p>I'm trying to install the latest version of <a href="https://pypi.org/project/opencv-contrib-python/" rel="nofollow noreferrer"><code>opencv-contrib-python</code></a> from PyPi into a <code>conda</code> environment. I did this very thing yesterday with no issues but today its broken.</p>...
<python><opencv><pip>
2023-03-30 16:02:14
1
3,687
DrBwts
75,890,415
11,261,546
How to set just one default argument pybind11
<p>I have a function :</p> <pre><code>void my_functions(int a, int b = 42); </code></pre> <p>And I want to bind it using only the default argument for <code>b</code>:</p> <pre><code> m.def(&quot;my_functions&quot;, &amp;my_functions, pb::arg(&quot;b&quot;) = 42); // just default for b </code></pre> <p>This doesn't wor...
<python><c++><pybind11>
2023-03-30 15:49:58
3
1,551
Ivan
75,890,407
11,901,834
Python regex to remove string which may contain additional character
<p>I've got a string in python that sometimes starts with either <code>{txt -</code> or <code>{txt</code>.</p> <p>These do not always appear at the start of the string, but if they do, I want to remove them.</p> <p>I know I can do it like this:</p> <pre><code>string = string.strip('{txt -').strip('{txt') </code></pre> ...
<python><string><replace>
2023-03-30 15:49:11
2
1,579
nimgwfc
75,890,327
681,548
Create an alembic upgrade process from configuration taken by another package
<p>I'm extending a 3rd party application which internally uses SQLAlchemy and Alembic. This is good, because I need to extend the database model of this application but I don't want to fork the project.</p> <p>So, I'm trying to use alembic in my extension package.</p> <ol> <li><p>alembic recognize that the database is ...
<python><sqlalchemy><alembic>
2023-03-30 15:41:13
0
7,839
keul
75,890,304
16,389,095
Kivy: How to switch between interfaces defined in different classes
<p>I'm developing an app in Kivy/KivyMD - Python. I defined three different UI in three different classes. Each interface contains a button to switch between them. When the app starts, the first interface is displayed. Here is the code:</p> <pre><code>from kivy.lang import Builder from kivymd.app import MDApp from kivy...
<python><kivy><kivy-language><kivymd>
2023-03-30 15:38:42
1
421
eljamba
75,890,022
325,809
pylsp can't find installed editable packages
<p>The problem is fairly straightforward: <code>pylsp</code> can't deal with editable packages. To create an environment that reproduces my problem:</p> <pre><code>$ mkdir /tmp/pyslp_test $ cd /tmp/pylsp_test $ echo &quot;import jaxtyping&quot; &gt; script.py $ mkdir editable_packages $ git clone https://github.com/goo...
<python><module><language-server-protocol><python-jedi><python-lsp-server>
2023-03-30 15:15:20
0
6,926
fakedrake
75,889,941
2,292,490
Give GPT (with own knowledge base) an instruction on how to behave before user prompt
<p>I have given GPT some information in CSV format to learn and now I would like to transmit an instruction on how to behave before the user prompt.</p> <pre><code>def chatbot(input_text): index = GPTSimpleVectorIndex.load_from_disk('index.json') message_history.append({&quot;role&quot;: &quot;user&quot;, &quot...
<python><prompt><openai-api><gpt-3><chatgpt-api>
2023-03-30 15:09:19
0
571
Bill Bronson
75,889,805
7,746,166
Elasticsearch python api time range with specific field values
<p>Im trying to write a query for elasticsearch where im searching in a specific time range for the specific names of a field called &quot;name&quot;.</p> <p>I came up with:</p> <pre><code>body = { &quot;query&quot;: { &quot;range&quot;: { 'timeObject': { &quot;from&quot;...
<python><elasticsearch>
2023-03-30 14:55:34
1
1,491
Varlor
75,889,803
4,436,572
dask_cudf dataframe convert column of datetime string to column of datetime object
<p>I am a new user of Dask and RapidsAI. An exerpt of my data (in <code>csv</code> format):</p> <pre><code>Symbol,Date,Open,High,Low,Close,Volume AADR,17-Oct-2017 09:00,57.47,58.3844,57.3645,58.3844,2094 AADR,17-Oct-2017 10:00,57.27,57.2856,57.25,57.27,627 AADR,17-Oct-2017 11:00,56.99,56.99,56.99,56.99,100 AADR,17-Oct-...
<python><dataframe><dask><rapids><cudf>
2023-03-30 14:55:30
0
1,288
stucash
75,889,725
15,283,859
Ipywidgets interactive - take a dictionary as an argument
<p>I have a function that looks like this that takes a dictionary as an argument. The dictionary looks like this:</p> <pre><code>d = {'skill_1':3, 'skill_2':2, 'skill_5':5, 'skill_7':3} </code></pre> <p>The function i have is a function that takes this dictionary, and then looks into a dataframe for the people that hav...
<python><python-3.x><dictionary><jupyter-notebook><ipython>
2023-03-30 14:49:04
1
895
Yolao_21
75,889,612
1,901,071
Outlook COM object - Marking an Email as Read
<p>Using w32 python library, I am taking an email and saving the attachment from Outlook. I have seen several questions dealing with this topic with the most promising being here: <a href="https://stackoverflow.com/questions/73216077/marking-an-email-as-read-python">Marking an email as read python</a></p> <p>I have tri...
<python><outlook><win32com><office-automation><com-automation>
2023-03-30 14:39:07
1
2,946
John Smith
75,889,275
7,575,172
Cannot link to local script with "console_script" in setup.py
<p>I'm trying to setup the console_script option in setup.py so I can just write the name of a script to execute it from the CLI.</p> <p>My package looks like this:</p> <pre><code>root |--bin |-- C2C (python file to execute) |--setup.py |--(Rest of the package ... ) </code></pre> <p>I have tried to add th...
<python><setuptools>
2023-03-30 14:05:34
0
305
Malte Jensen
75,889,257
17,596,179
depends on a node named 'energy_dbt_model' which was not found
<p>I was trying out to find out how to query my duckdb file. When I run <code>dbt run --select energy_dbt_model</code>. I keep getting the error</p> <blockquote> <p>Model 'model.transform_dbt.first_model' (models\example\first_model.sql) depends on a node named 'energy_dbt_model' which was not found</p> </blockquote> <...
<python><etl><dbt><duckdb>
2023-03-30 14:02:43
0
437
david backx
75,889,106
19,980,284
Pandas value_counts() counting same value more than once
<p>I've taken a pandas column called <code>specialty</code> that looks like this:</p> <pre><code>0 1,5 1 1 2 1 3 1 4 1 5 1,5 6 3 7 3 8 1 9 1,3 10 1 11 1,2,4,6 12 1,5 13 6 14 3 </code></pre>...
<python><pandas><count>
2023-03-30 13:48:10
1
671
hulio_entredas
75,889,083
12,596,824
Passing Sklearn model to a function to set arguments - type error: not callable?
<pre><code>from sklearn.linear_model import LogisticRegression lr = LogisticRegression() def logistic(model): test = model(random_state = 0) return test logistic(lr) </code></pre> <p>I have the above code where I am trying to pass a logistic regression with no arguments and then doing so within the funct...
<python><scikit-learn>
2023-03-30 13:46:02
1
1,937
Eisen
75,888,799
14,386,187
Wikipedia API not searching specified term
<p>I'm using the Wikipedia API wrapper for Python, and for some queries, it's not searching the term I specified. For example, when I execute the function below:</p> <pre><code>import Wikipedia wikipedia.summary('machine learning') </code></pre> <p>I get the error</p> <pre><code>PageError ...
<python><wikipedia-api>
2023-03-30 13:20:22
2
676
monopoly
75,888,782
19,980,284
Identify specific integers in column of mixed ints and strings
<p>I have a column in a pandas df named <code>specialty</code> that looks like this:</p> <pre><code>0 1,5 1 1 2 1,2,4,6 3 2 4 1 5 1,5 6 3 7 3 8 1 9 2,3 </code></pre> <p>I'd like to create a new column called <code>is_1</code> th...
<python><pandas><numpy><integer><object-type>
2023-03-30 13:19:01
2
671
hulio_entredas
75,888,712
14,720,380
How do I convert the projection of a netcdf file to a regular grid of lons and lats?
<p>I need to make an interpolation object where I enter a given longitude and latitude and the object returns the nearest ocean surface current value. The dataset I am using is . You can download the latest forecast by following <a href="https://nomads.ncep.noaa.gov/pub/data/nccf/com/rtofs/prod/" rel="nofollow noreferr...
<python><numpy><weather><map-projections><noaa>
2023-03-30 13:12:01
2
6,623
Tom McLean
75,888,599
7,056,539
Type inference in a IoC container class, return type of the resolve method
<p>I have a simple IoC class implementation:</p> <pre class="lang-py prettyprint-override"><code>Abs = TypeVar('Abs', str, Type) class MyContainer: _bindings: dict = {} _aliases: dict = {} def resolve(abstract: Abs): # something along these lines... abstract = ( self._aliases[a...
<python><dependency-injection><type-inference><ioc-container>
2023-03-30 12:59:29
0
419
Nasa
75,888,532
8,547,163
How to parse command line arguments into an imported module via argparse
<p>I have a python script that uses <code>argparse</code> to parse command line arguments, below is an example from it.</p> <pre><code>#main.py import argparse from my_folder.myscript import foo #...lines of code def main(): parser = argparse.ArgumentParser() parser.add_argument( &quot;--test&quot;, ...
<python><command-line-arguments><argparse>
2023-03-30 12:52:34
1
559
newstudent
75,888,457
10,362,801
how can I remove Label conflict in classification problem?
<p>I have identical samples with different labels and this has occurred due to either mislabeled data, If the data is mislabeled, it can confuse the model and can result in lower performance of the model.</p> <p>It's a binary classification problem. if my input table is somethin like below</p> <p><a href="https://i.sst...
<python><pandas><machine-learning><classification><data-cleaning>
2023-03-30 12:44:58
1
495
Shiv948
75,888,427
14,820,295
Lead function based on value change of column in PySpark
<p>Is there an easy way to do this?</p> <p>Basically, I want to find the first &quot;next date&quot; when my &quot;flag_code&quot; column change status (1 or 0). If I have 3 same status consecutively, I want to track the same first date.</p> <p>Thank u</p> <p><code>Input</code></p> <div class="s-table-container"> <tabl...
<python><apache-spark><pyspark><apache-spark-sql><window>
2023-03-30 12:43:02
1
347
Jresearcher
75,888,406
17,973,259
Space shooter player not becoming inactive while shooting
<p>I have this method that manages the Last Bullet game mode in my game. It keeps track of how many enemies are alive, the number of bullets that every player has available and the number of flying bullets and, if there are no remaining bullets, flying bullets and more than one enemy, the player becomes inactive. But h...
<python><pygame>
2023-03-30 12:41:47
1
878
Alex
75,888,343
4,377,559
How to Pact test a dictionary object
<p>The below test will pass correctly, but if I post a body of <code>{&quot;a different key&quot; : 4.56}</code> it will fail as &quot;key&quot; is expected. In other words, the dictionary key is not flexible, only the float value.</p> <p>How can I define a pact where only the dictionary types matter i.e. keys must be ...
<python><pact><pact-python>
2023-03-30 12:33:55
1
603
Conor
75,888,319
7,692,855
Python 3 SQLAlchemey UnicodeDecodeError: 'ascii' codec can't decode byte
<p>I have some code which I'm finally getting around to updating to Python 3.</p> <p>It runs in Docker using ubuntu:20.04 as the base image.</p> <p>I am using SQLAlchemy query .all() method <code>method sqlalchemy.orm.Query.all()</code></p> <p>The code works with Python 2 however, it fails on Python 3 with the followin...
<python><sqlalchemy>
2023-03-30 12:31:59
1
1,472
user7692855
75,888,196
357,313
Why doesn't restore_best_weights=True update results?
<p>I found that <code>restore_best_weights=True</code> does not actually restore the best behavior. A simplified example with some dummy data:</p> <pre><code>import numpy as np from tensorflow.keras.utils import set_random_seed from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense fro...
<python><keras><tf.keras><early-stopping>
2023-03-30 12:18:25
1
8,135
Michel de Ruiter
75,888,185
128,618
Merge the list of dictionary if there are some condition is match?
<pre><code>input = [ {'date':'2023-03-1', 'item':'i1', 'balance': 11, 'warehouse' : 'W1'}, {'date':'2023-03-2', 'item':'i1', 'balance': 12, 'warehouse' : 'W1'}, {'date':'2023-03-3', 'item':'i1', 'balance': 13, 'warehouse' : 'W1'}, {'date':'2023-04-2', 'item':'i2', 'balance': 11, 'warehouse' : 'W2'}, {'date':'2023-04-3...
<python>
2023-03-30 12:17:47
5
21,977
tree em
75,888,099
20,051,041
how to add subtitles in video with ffmpeg filter?
<p>I am having hard time adding .srt subtitles to the newly creating video. I am using Python.</p> <p>subtitles:</p> <pre><code>f&quot;{PROJECT_PATH}/data/subtitles/final_subtitle_srt/all_slides.srt&quot; </code></pre> <p>I have checked they are correct.</p> <p>pieces of my code that does not work:</p> <pre><code>audio...
<python><ffmpeg><video-subtitles>
2023-03-30 12:10:06
1
580
Mr.Slow
75,887,939
12,297,666
Plotting CV Indices for Multiclass in Sklearn
<p>Following this <a href="https://scikit-learn.org/stable/auto_examples/model_selection/plot_cv_indices.html" rel="nofollow noreferrer">guide</a> from Sklearn, i have modified the code a bit to also show the classes in the legend:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from sklearn.model_sel...
<python><scikit-learn>
2023-03-30 11:54:39
0
679
Murilo
75,887,761
1,150,683
Typing to mark return values of current class type or any of its subclasses
<p>I want to make sure that the <code>from_dict</code> in the following method works well in its subclasses as well. Currently, its typing does not work (mypy error &quot;Incompatible return value type&quot;). I think because the subclass is returning an instance of the subclass and not an instance of the super class.<...
<python><oop><subclass><mypy><python-typing>
2023-03-30 11:38:34
1
28,776
Bram Vanroy
75,887,656
10,155,536
botocore package in lambda python 3.9 runtime return error: "cannot import name "'DEPRECATED_SERVICE_NAMES'" from 'botocore.docs'"
<p>I am using Lambda Python 3.9 runtimes. I also use boto3 and botocore default packages in Lambda.</p> <p>Today, I suddenly got this error: &quot;cannot import name &quot;'DEPRECATED_SERVICE_NAMES'&quot; from 'botocore.docs'&quot;. I only succeeded in fixing it when I added the botocore package to the lambda runtime. ...
<python><lambda><boto3>
2023-03-30 11:29:38
5
401
Elad Hazan
75,887,646
9,859,642
Drop zeroes from xarray DataArray
<p>I have a DataArray with three coordinates and I wanted to drop arrays containing all zeroes from one of the dimensions, but I can't seem to get it right. The data array (old_array) looks as follows, and as you can see there are quite a few arrays that are filled with zeroes.</p> <pre><code>&lt;xarray.DataArray (dim1...
<python><numpy><python-xarray>
2023-03-30 11:28:51
1
632
Anavae
75,887,378
839,497
requests.get connection refuse error (exception) not catched
<p>Im trying to catch connection error when calling http get in a Python script.<br /> I found this <a href="https://stackoverflow.com/questions/55414137/how-can-i-catch-a-connection-refused-error-in-a-proper-way">post</a> descussing the exact same issue</p> <p>For me, in 99% of the calls are going smooth. but every on...
<python><error-handling><python-requests>
2023-03-30 10:59:20
0
818
OJNSim
75,887,280
145,413
Avoiding python ints being truncated to 32 bits when sent through a Qt signal-slot connection
<h2>Issue</h2> <p>I have some <code>QObject</code>s living on different threads that communicate using Qt Signals and Slots. I'm using <em>PyQt5</em> (through <em>qtpy</em>), but I don't think it's specific to that API or version.</p> <p>One of the values being sent is an integer on the order of 2^40, but as the C++ ty...
<python><qt><pyqt5><qt-signals>
2023-03-30 10:51:16
0
396
AI0867
75,887,199
9,468,092
How to optimize a Python script for inserting data into a database and pushing data to an AWS SQS queue with large datasets?
<p>I have a python script which reads data from a CSV and performs 2 tasks for each row:</p> <ol> <li>Inserts the row into a table in PostgreSQL database.</li> <li>Push the row to an AWS SQS queue.</li> </ol> <p>This script performs well when I have a small dataset of ~1-10k records. But as the size of my dataset incre...
<python><amazon-web-services><concurrency>
2023-03-30 10:42:13
1
890
Dipanshu Chaubey
75,886,959
497,517
Installing Plotty on Python
<p>I'm trying to install Plotty in PyCharm. When I try to add it in the 'Python Interpriter' Install section it can only find plottyprint.</p> <p>How can I get Plotty to install?</p> <p>Many thanks for any help.</p>
<python>
2023-03-30 10:20:33
2
7,957
Entropy1024
75,886,674
5,312,965
How to compute sentence level perplexity from hugging face language models?
<p>I have a large collection of documents each consisting of ~ 10 sentences. For each document, I wish to find the sentence that maximises perplexity, or equivalently the loss from a fine-tuned causal LM. I have decided to use Hugging Face and the <code>distilgpt2</code> model for this purpose. I have 2 problems when t...
<python><nlp><huggingface-transformers><large-language-model><huggingface-evaluate>
2023-03-30 09:53:14
1
830
pilu
75,886,663
673,600
Driving a colab python script from Google sheets
<p>Here is what I need to do.</p> <ol> <li>Populate a drop down list from a python function in <code>colab</code>.</li> <li>Allow user to select one item and after hitting go fire another python function.</li> </ol> <p>I can write and read from a Google Sheets from colab, but I have no way to drive python this way. I c...
<python><google-sheets><google-colaboratory>
2023-03-30 09:52:07
0
6,026
disruptive
75,886,387
8,477,952
Python quivalent for a C# Object
<p>We have a python script which can interact with a couple of Bosch Rexroth servo drivers. We can succesfully read data from it's parameters but we cannot write to parameters. We use the Bosch Easy Automation Library (EAL.dll)</p> <pre><code>import clr clr.AddReference(&quot;EAL&quot;) import EAL # imports EAL.dll f...
<python><object>
2023-03-30 09:24:46
0
407
bask185
75,886,385
6,281,366
pydantic - copy object fields to another, while excluding several fields
<p>i have a pydantic class:</p> <pre><code>class SomeData(BaseModel): id: int x: str y: str z: str </code></pre> <p>and lets say i have two object of this class, obj1, obj2.</p> <p>is there any simple way, i can copy obj2, into obj1, while ignoring a subset of fields? for example copy all SomeData field...
<python><pydantic>
2023-03-30 09:24:36
3
827
tamirg
75,886,353
13,518,907
Python - Two different bar charts next to each other
<p>I am using matplotlib to analyze my data. For this I created a dataframe with following structure:</p> <pre><code>merge.set_index('index', inplace=True) print(merge) username mentioned_user index matthiashauer 73 10 derya_tn 67 5 renatekuenast 36 9 ralf_stegner 35 73 mgr...
<python><matplotlib><plot><bar-chart>
2023-03-30 09:21:22
1
565
Maxl Gemeinderat
75,886,320
3,007,402
Extend psycopg2 cursor class' __iter__ method
<p>I am creating server-side cursors at several places during the course of a long ETL process. I want to automatically close the db connection once all rows are fetched from a server-side cursor.</p> <p>Instead of doing that manually at every place the cursor is created, I want to define a custom <code>psycopg2</code>...
<python><psycopg2>
2023-03-30 09:18:03
0
2,868
Shiva
75,886,111
602,117
String manipulation of cell contents in polars
<p>In polars, I am trying to perform selection of rows and create a new content based on string manipulation. However, the python string manipulation commands below don't work. I've seen polars uses regular expressions, but am unsure how to use this to create a number from the option_type column using everything before...
<python><dataframe><python-polars>
2023-03-30 08:57:24
2
1,019
mr_js
75,885,945
14,912,118
How to pass shell script variable to python in databricks
<p>I am currently trying to use shell script variable in python.</p> <p>Below is the code.</p> <pre><code>%sh export MY_VAR=&quot;my_value&quot; echo $MY_VAR </code></pre> <pre><code>%python import os my_var = os.environ.get(&quot;MY_VAR&quot;) print(my_var) </code></pre> <p>Code screenshot</p> <p><a href="https://i.ss...
<python><shell><databricks>
2023-03-30 08:43:20
1
427
Sharma
75,885,793
20,102,061
How to set a tkinter textbox to be in the button right of the window
<p>I am working on a simple UI for my electronics project application, I am using tkinter as my window and want to add a text box that will be used as a logger. My screen size is the window's initial size and I like the textbox to be at the bottom right of the window.</p> <p>this is a test code that I am using to try a...
<python><python-3.x><tkinter>
2023-03-30 08:24:03
1
402
David
75,885,670
18,140,022
Polars: adding a column to an empty dataframe with set schema
<p>I created an empty dataframe with a set schema. The schema sets the columns data types. I want to add a single name-matching column (series) to the empty dataframe. But it seems to not like it.</p> <pre><code># Empty dataframe with a given schema df = pl.DataFrame(schema={&quot;my_string_col&quot;:str, &quot;my_...
<python><python-polars>
2023-03-30 08:13:07
3
405
user18140022
75,885,628
247,696
Can I count on the "python3" executable being available on Python 3 installations? Or "python"?
<p>Let's say I have a Python command that I want to share with people widely. Let's take it as a given that Python 3 is installed. Which binary should I expect users to have, <code>python</code> or <code>python3</code>?</p> <p>For example, which is better, to tell users to run this:</p> <pre><code>python -m http.server...
<python><python-3.x>
2023-03-30 08:08:13
1
153,921
Flimm
75,885,451
9,970,706
How to insert values into a nested python dictionary
<p>I am trying to insert values into a nested python dictionary. The response I am getting is from a postgresql database where the table has four columns:</p> <pre><code>coe, coe_type, count, coe_status Author 1, Open, 10, Published Author 2, Closed, 20, Not-Published etc.... </code></pre> <p>Curr...
<python><postgresql><dictionary>
2023-03-30 07:48:52
1
781
Zubair Amjad
75,885,359
10,197,418
How to convert float to string with specific number of decimal places in Python polars?
<p>I have a polars DataFrame with multiple numeric (float dtype) columns. I want to write some of them to a csv with a certain number of decimal places. The number of decimal places I want is column-specific.</p> <p><code>polars</code> offers <a href="https://pola-rs.github.io/polars/py-polars/html/reference/expression...
<python><format><python-polars><f-string>
2023-03-30 07:37:32
2
26,076
FObersteiner
75,885,162
6,916,032
Patching child TestCase class affects parent TestCase class
<p>I need to test a function which uses feature toggles to turn some functionality on and off. Say, a function like this:</p> <pre><code>def func_to_test(hello_value: str): if toggle_is_active('only_hello_and_hi'): if hello_value not in ('hello', 'hi'): return print(hello_value) </code></pre...
<python><python-unittest><patch><python-unittest.mock>
2023-03-30 07:13:58
1
417
Artem Ilin
75,885,115
16,250,404
Convert Datetime Objects as per Time zones
<p>I have tried two different scenarios:</p> <ol> <li>I fetched Current Datetime of <code>UTC</code> and <code>Europe/Paris</code> and then I just converted in string which shows <code>02 hours</code> of gap which is correct.</li> </ol> <pre><code>from datetime import datetime import datetime as dt import pytz from dat...
<python><datetime><timezone><python-datetime>
2023-03-30 07:09:18
0
933
Hemal Patel
75,885,078
1,780,761
python - split query results into multiple objects based on one column
<p>my program is querying a sqlite database, and thre result is like this (simplified) in the cursor ready to be fetched.</p> <pre><code>connection = sqlite3.connect(IMAGE_LOG_DB_PATH) connection.isolation_level = None cur = connection.cursor() sql_query = &quot;Select date, name, count(*) as sells from sellers group b...
<python><sqlite><object><orm>
2023-03-30 07:04:52
1
4,211
sharkyenergy
75,885,077
6,447,123
Searching for sequence of bits in an integer in Python
<p>I have two integers, lets call them <code>haystack</code> and <code>needle</code>. I need to check that, if the binary representation of <code>needle</code> occurred in <code>haystack</code> [and <strong>OPTIONALLY</strong> find the position of the first occurrence]</p> <h2>Example</h2> <pre class="lang-py prettypri...
<python><algorithm><binding><substring><binary-data>
2023-03-30 07:04:45
2
4,309
A.A
75,885,039
8,868,327
Test Django settings with pytest
<p>I am trying to set some environment variables that drive the configuration of a Django project in some tests so that I can mock some of the values and make assertions easier and explicit.</p> <p>I want to set an environment variable with the name of a file which stores some configuration which is loaded if the varia...
<python><django>
2023-03-30 06:59:37
1
992
EDG956
75,884,946
10,748,412
How to get coordinates of all vertical lines using OpenCV
<p>How can I get the coordinates of all these vertical white lines as a list using OpenCV or any other method.</p> <p><a href="https://i.sstatic.net/EdPhD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EdPhD.png" alt="enter image description here" /></a></p> <p>This is what i did to get these lines</p> ...
<python><opencv><machine-learning><deep-learning>
2023-03-30 06:50:09
1
365
ReaL_HyDRA