I’m getting this error when running an optimtization inside a local respository using the ScipyOptimizeDriver and recording the result file. It worked flawlessly, however all of a sudden, I got this error: I didn’t change anything to my code, hence I don’t know where it came from. I also can…
Tag: python
Mocking sqlobject function call for test db
I am trying to mock sqlbuilder.func for test cases with pytest I successfully mocked sqlbuilder.func.TO_BASE64 with correct output but when I tried mocking sqlbuilder.func.FROM_UNIXTIME I didn’t get any error but the resulted output is incorrect with the generated query. Below is the minimal working exa…
Get the list of files inside a folder that have a date inside their name
I have a folder with some files inside called in this way: I would like to get a list containing all the files that have in their name a date in the format ‘YYYYMMDDHHMMSS’. so in this example I would like to get all the files except file_4_20200109999999 because the date in it does not exist. exp…
can you suggest an alternative for platform.login
i recently started experimenting in the RingCentral sandbox environment and facing issues with this part of the code I went to know if there is an alternative to code Answer Looking at your code snippet, I can see that the platform.login() function signature is incorrect as you are passing extra argument. Cor…
only last curve with marker is plotted in for loop – how to plot all markers
I have created a list of markers in which each marker is used to show the max value of that curve. (4 curves -> 4 markers) Somehow I cannot get all the markers to appear in the plot. It seems only the first marker in the for loop is plotted. Answer You can greatly simplify your code, use idxmax directly
How to extend the color palette in matplotlib?
I coded the following function: And then the for-loop: As the for loop iterates over num_columns which has 40 variables, the standard palette only offers 10 colors. However, I want to have every variable its own color. Is there a way to code it also being flexible when it comes to the number of variables? Ans…
Creating a function that works like “zip”
I am trying to make a function that does something similar to “zip”. My problem is that the part doesn’t work. In the case below, it should take every third element from the L4, and append it to a new list, so I ended up with [[1, 4, 7], [2, 5, 8], [3, 6, 9]], but that is not really
Using a column of values to create a counter for a variable sequential number column
I currently have a pandas dataframe with some columns. I’m looking to build a column, Sequential, that lists what iteration is recorded at that part of the cycle. I’m currently doing this using itertools.cycle, and a fixed number of iterations block_cycles, like so: With an output like this: And t…
Validate dataclass field with custom defined method?
While working with dataclasses, type hints are good but what I’m looking also for is a Validation of passed values (such as string of max length 50, int with upper limit of 100 etc) Is there anyway to validate passed value ? For example, Pydantic has these Validators. I’m looking for something nat…
Grouping python dataframe by multiple column name
My goal in to split python dataframe by multiple columns. In the case of one column, data frame can be splitted by column ‘X1’ as below, using the groupby method. However, how to split dataframe according to columns X1 and X2? Answer If pass another column name is necessary select dfs by tuples: I…