673 questions
-1
votes
1
answer
45
views
How can I access the ${orderId} and ${payment} which is present in the method chaining of the promise to my last block of promise? [duplicate]
const cart = ["shoes","shirts","boxers","pants"]
function creatOrder(cart){
return new Promise((resolve,reject)=>{
if(!ValidateCart(cart)){
...
0
votes
0
answers
20
views
Is there a good way to add columns calculated using a window partition within pandas chaining
My background is in SQL and I was wondering what was the most efficient/readable way of creating multiple columns using the same window partition within a pandas chain.
Suppose I have the following ...
2
votes
2
answers
108
views
Is it possible to create groups/layers in method chaining in Python?
I am aware that I can use method chaining by simply having methods return self, e.g.
object.routine1().routine2().routine3()
But is it possible to organize methods into layers or groups when applying ...
0
votes
0
answers
47
views
How to track access to class variables in a custom ORM using Python descriptors?
I'm building my own ORM in Python and ran into an issue. I want to track the access to class variables in order to know which ForeignKey is being used in each part of my code.
class IQuery(ABC):
&...
0
votes
2
answers
187
views
How to chain operations in pandas entirely in-line?
I often want to both manipulate and display a dataframe during a sequence of chained operations, for which I would use*:
df = (
df
#Modify the dataframe:
.assign(new_column=...)
#View result ...
2
votes
0
answers
68
views
Filter series in method chain
What is the preferred syntax to filter a polars Series without referencing the Series explicitly? I.e. something that works with method chaining. I thought pipe would be an option but it is not ...
1
vote
0
answers
107
views
VSCode: Incorrect indentation after method chaining?
After I've concluded a block with method chaining, VSCode keeps the indentation until I format on save.
Example:
$orders = Order::paid()
->notShipped()
->get();
dd($orders); // <-...
0
votes
1
answer
52
views
Is there a short syntax in javascript for a call chain containing synchronous and asynchronous methods of the same class?
I know of 2 ways that are not very convenient and look inelegant:
Via then:
(new TestClass).syncMethod().asyncMethod().then(self => self.anotherSyncMethod())
Via await:
(await (new TestClass)....
1
vote
4
answers
223
views
C# fluent pattern for nested if conditions
I am working in C#. And I have a scenario as shown here:
var response1 = service.AddSchool(object model, string a);
if (response1.StatusCode == HttpStatusCode.OK)
{
var response2 = service....
0
votes
1
answer
58
views
Optimizing Memory and Performance for Immutable Chain Method Classes Handling Large NumPy Arrays
I'm working on a Python project that involves processing large numpy arrays using a chain of transformations. I've implemented two classes: Sample for individual arrays and SampleCollection for ...
3
votes
2
answers
284
views
How do I compose or chain multiple function in Python
When writing a program, I often want to perform a series of steps on a piece of data (usually a list or string). For example I might want to call a function which returns a string, convert it to a ...
1
vote
4
answers
132
views
Can't I insert an element at the start of array with a chained method without using map?
I have a chain of methods that treat an array. Then I was trying to do a simple thing: add an element at the start of the array in a method chain. Initially I tried:
console.log(
[1, 2, 3]
...
1
vote
1
answer
414
views
Alternative to df.rename(columns=str.replace(" ", "_"))
I noticed that it's possible to use df.rename(columns=str.lower), but not df.rename(columns=str.replace(" ", "_")).
Is this because it is allowed to use the variable which stores ...
1
vote
2
answers
279
views
Fluent interfaces with pipelining or method chaining in Python
I am coming to Python from F# and Elixir, and I am struggling heavily in terms of cleanly coding data transformations. Every language I have ever used has had a concept of a pipeline operator and/or ...
2
votes
5
answers
85
views
How to Select First N Key-ordered Values of column within a grouping variable in Pandas DataFrame
I have a dataset:
import pandas as pd
data = [
('A', 'X'),
('A', 'X'),
('A', 'Y'),
('A', 'Z'),
('B', 1),
('B', 1),
('B', 2),
('B', 2),
('B', 3),
('B', 3),
(...
1
vote
2
answers
114
views
Chain method grouping and calculating differences in a Pandas DataFrame
I have a Pandas DataFrame with the following structure:
import pandas as pd
data = {
'glob_order': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
'trans': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', '...
0
votes
1
answer
70
views
Is it necessary to return the same object in methods with fluent interface
in some sources such as the original article of Martin Fowler aren't written that methods would return the same object, and methods in examples return different objects but in some sources(newer) such ...
1
vote
1
answer
119
views
The different between fluent interface and method cascading implemented by method chaining [duplicate]
When I read about it on Wikipedia, it seemed to me that these two are almost the same, but the same article says that they differ not only in the use of DSL.
Note that a "fluent interface" ...
2
votes
3
answers
238
views
copy a dataframe to new variable with method chaining
Is it possible to copy a dataframe in the middle of a method chain to a new variable?
Something like:
import pandas as pd
df = (pd.DataFrame([[2, 4, 6],
[8, 10, 12],
...
-1
votes
2
answers
158
views
Data Wrangling in Python in Chaining Style from R
I'm new to Python and I come from the R environment. One thing that I love in R is the ability to write down code that will make some many transformations on the data in one readable chunk of code
But ...
2
votes
1
answer
378
views
Equivalent of pandas .append() method, which allows method chaining
Now that append() is removed in pandas 2.0, what is a short alternative to append() allowing method chaining?
The "What’s new in 2.0.0" section of pandas says:
Removed deprecated Series....
1
vote
3
answers
108
views
pandas: assign a column values by slice with method chaining
In the following toy example, i'm trying to add a status column based on the outer merge results. The challenge is to preserve the chaining method as best described in tom's blog. The commented out ...
0
votes
0
answers
51
views
In a chaining call, is copy assignment called? [duplicate]
I would like to understand when a copy constructor or assignment is called. Assume the following:
class Foo {
public:
Foo()
{
cout << "foo constructor " << this <&...
1
vote
1
answer
218
views
Python convention indicating whether method chaining is method cascading?
I am spinning up on Python and Spark. I noticed that Python uses a
lot of chaining of methods and/or properties. A lot of what I found
online about this for Python describes method cascading, even ...
0
votes
1
answer
181
views
How do you efficiently chain array methods in Ruby
So let's say I have this MWE code:
# see below for full code - not important here
class RealEstate; attr_accessor :name; attr_accessor :living_space; attr_accessor :devices; def initialize(name, ...
-2
votes
1
answer
82
views
How to simplify this code in Javascript via function chaining?
I would to know how to simplify theses function calls by chaining them. Is there a way to chain forEach, push, destructuring array and map.
let selectorsForLoader = ['a', 'b'];
let loadingElements = ...
3
votes
2
answers
722
views
pandas chaining and the use of "inplace" parameter
For pandas DataFrames in python, multiple member methods have an inplace parameter which purportedly allow you to NOT create a copy of the object, but rather to directly modify the original object*.
[*...
2
votes
1
answer
955
views
Python, Gradio, promise chains, .then(), understanding passed and operated data
Ok I'm really struggling to find clear documentation to help me understand what's going on here.
gen_events.append(shared.gradio['Generate'].click(
ui.gather_interface_values, [shared.gradio[k] for ...
0
votes
0
answers
807
views
add Map method to a generic slice in go [duplicate]
I can't create a Map method for a generic stlice in go for fluent style programming (method chaining).
For example look at the code snippet I've created for the Filter method:
package main
import &...
1
vote
1
answer
121
views
Is it possible to know when a Ruby class has finished chaining methods?
I'm trying to determine if it is possible in Ruby to determine when a chain of methods has finished being called.
Consider that I have a class which retrieves information from a database. I often just ...
0
votes
1
answer
183
views
Chain methods for ClockTriggerBuilder
I have a GAS time based trigger that I would like to run at intervals of some combination of hours and minutes (i.e. the triggered function would run every 2 hours and 30 minutes, or every 4 hours and ...
0
votes
0
answers
110
views
How to add methods to managed attributes in Python Class
Currently I have a python class function where
class Data:
def __init__(self, data=None, target=None):
self._data = None
self._target = None
self.X = data
...
1
vote
1
answer
134
views
How to do method chaining for an interface?
I would like to do something like obj.WithX().WithY().WithZ(). obj can have different types, which is why I am using an interface.
Unfortunately obj can also be nil. In that case my method chaining ...
0
votes
1
answer
174
views
Chaining a post request after another post request in javascript using fetch
I am trying to perform a post request, obtain the ids set as the primary key back, and use these to populate a different table through a different API.
I have read this and this SO posts, as well as ...
0
votes
2
answers
85
views
How to drop a row in pandas which has a certain column value using method chaining?
I have a notebook that I am converting using chaining in pandas. Minimally, it looks like this:
df = (pd.read_csv("../data/stones_raw.csv", index_col=[0])
.drop(['date', 'id'], axis=1)
...
0
votes
3
answers
283
views
Replace values for multiple columns in pandas
I have the following data frame.
col1 col2 col3
1 1 1
2 2 2
3 1 2
3 3 3
I want to replace numerical values based on the following mappings
col1: {1: dog, 2: cat, 3: bird}
col2:...
1
vote
2
answers
90
views
Method chaining df. duplicate every row 3 times
I have the following data frame:
Data Frame:
id animal
1 dog
2 cat
3 rabbit
4 horse
5 fox
I want to replicate each id 3 times. How can I do this in pandas using method chaining?
Expected output:
...
4
votes
2
answers
186
views
C++ Paramater pack expansion over chained function calls
It is common for libraries to have types which return instances of themselves from member functions to encourage chaining calls. For example, nlohmann json:
auto my_data = my_json_object["first ...
0
votes
1
answer
379
views
Call an object method once the chained methods are resolved
I would like to create a custom api service that will work similarly to the supabase-js library. Example:
const { data, error } = await supabase
.from('cities')
.select('name, countries(*)')
.eq(...
1
vote
3
answers
279
views
How do I replace a string-value in a specific column using method chaining?
I have a pandas data frame, where some string values are "NA". I want to replace these values in a specific column (i.e. the 'strCol' in the example below) using method chaining.
How do I do ...
1
vote
3
answers
136
views
Assign column adding columns in pandas dynamically (method chaining in python)
I want to create a new column named total which adds all the year columns (everything in these columns are integers). I want to do it dynamically because as each year passes there will be a new column ...
1
vote
1
answer
42
views
Assign operator method chaining str.join()
I have the following method chaining code and want to create a new column. but i'm getting an error when doing the following.
(
pd.pivot(test, index = ['file_path'], columns = 'year', values = '...
0
votes
3
answers
473
views
c# how to make a conditional method chaining in fluent interface?
I'm developing .NET core app that using selenium, so I've designed the logic using fluent interface that make the code more readable and maintained.
I have a problem which is how to make a conditional ...
2
votes
2
answers
4k
views
Chaining methods in Rust
I have recently tried to create a simple builder pattern that allows for chaining methods together.
The API for it should look similar to this:
let chained = MethodChainer::new()
....
1
vote
3
answers
600
views
Performing operations on column with nan's without removing them
I currently have a data frame like so:
treated
control
9.5
9.6
10
5
6
0
6
6
I want to apply get a log 2 ratio between treated and control i.e log2(treated/control). However, the math.log2() ratio ...
-2
votes
1
answer
49
views
How method chaining works in this case in JQuery
method chaining requires every method to return the jquery object but,
when we use:
$("div").click(function(){ //some code }).css("backgroundColor","blue").
how does the ...
-4
votes
1
answer
83
views
How to use chain for several transformations, including creating new column? [closed]
Edited to comply with the rules:
How can I chain the following code? I cannot seem to be able to add new column with chain.
Input columns of Dataset:
ORDER, ITEM_SERIAL, DATE
%%time
df = Dataset....
1
vote
1
answer
286
views
How to method chaining in pandas to aggregate a DataFrame?
I want to aggregate a pandas DataFrame using method chaining. I don't know how to start with the DataFrame and just refer to it when aggregating (using method chaining). Consider the following example ...
2
votes
3
answers
173
views
How to method-chain `ffill(axis=1)` in a dataframe
I would like to fill column b of a dataframe with values from a in case b is nan, and I would like to do it in a method chain, but I cannot figure out how to do this.
The following works
import numpy ...
0
votes
1
answer
153
views
Can I use method chaining to delete rows with a if-else condition?
Right now my df looks like this (I shorten it cause there are 20 rows).
import pandas as pd
df=pd.DataFrame({'Country': ["Uruguay", "Italy", "France"], 'Winner': ["...