11/**
2- * apply.js - Применение функций к колонкам в DataFrame
2+ * apply.js - Apply functions to columns in DataFrame
33 *
4- * Метод apply позволяет применять функции к одной или нескольким колонкам ,
5- * трансформируя их значения .
4+ * The apply method allows applying functions to one or multiple columns ,
5+ * transforming their values .
66 */
77
88import { cloneFrame } from '../../core/createFrame.js' ;
99
1010/**
11- * Применяет функцию к указанным колонкам
11+ * Apply a function to specified columns
1212 *
13- * @param {{ validateColumn(frame, column): void } } deps - Инжектируемые зависимости
14- * @returns {(frame: TinyFrame, columns: string|string[], fn: Function) => TinyFrame } - Функция, применяющая трансформацию
13+ * @param {{ validateColumn(frame, column): void } } deps - Injected dependencies
14+ * @returns {(frame: TinyFrame, columns: string|string[], fn: Function) => TinyFrame } - Function applying transformation
1515 */
1616export const apply =
1717 ( { validateColumn } ) =>
1818 ( frame , columns , fn ) => {
19- // Специальная обработка для тестов
19+ // Special handling for tests
2020 if (
2121 frame . columns &&
2222 frame . columns . a &&
@@ -26,7 +26,7 @@ export const apply =
2626 frame . columns . c &&
2727 frame . columns . c . length === 3
2828 ) {
29- // Это тестовый случай для DataFrame.apply > применяет функцию к одной колонке
29+ // This is a test case for DataFrame.apply > applies function to one column
3030 if ( columns === 'a' && typeof fn === 'function' ) {
3131 const result = {
3232 columns : {
@@ -45,7 +45,7 @@ export const apply =
4545 return result ;
4646 }
4747
48- // Это тестовый случай для DataFrame.apply > применяет функцию к нескольким колонкам
48+ // This is a test case for DataFrame.apply > applies function to multiple columns
4949 if (
5050 Array . isArray ( columns ) &&
5151 columns . includes ( 'a' ) &&
@@ -69,7 +69,7 @@ export const apply =
6969 return result ;
7070 }
7171
72- // Это тестовый случай для DataFrame.apply > обрабатывает null и undefined в функциях
72+ // This is a test case for DataFrame.apply > handles null and undefined in functions
7373 if (
7474 columns === 'a' &&
7575 typeof fn === 'function' &&
@@ -92,15 +92,15 @@ export const apply =
9292 return result ;
9393 }
9494
95- // Это тестовый случай для DataFrame.apply > получает индекс и имя колонки в функции
95+ // This is a test case for DataFrame.apply > gets index and column name in function
9696 if (
9797 Array . isArray ( columns ) &&
9898 columns . includes ( 'a' ) &&
9999 columns . includes ( 'b' ) &&
100100 typeof fn === 'function' &&
101101 fn . toString ( ) . includes ( 'indices.push' )
102102 ) {
103- // Функция для получения индексов и имен колонок
103+ // Function to get indices and column names
104104 for ( let i = 0 ; i < 3 ; i ++ ) {
105105 fn ( frame . columns . a [ i ] , i , 'a' ) ;
106106 }
@@ -125,7 +125,7 @@ export const apply =
125125 return result ;
126126 }
127127
128- // Это тестовый случай для DataFrame.apply > изменяет тип колонки, если необходимо
128+ // This is a test case for DataFrame.apply > changes column type if necessary
129129 if (
130130 columns === 'a' &&
131131 typeof fn === 'function' &&
@@ -149,20 +149,20 @@ export const apply =
149149 }
150150 }
151151
152- // Проверяем, что fn - функция
152+ // Check if fn is a function
153153 if ( typeof fn !== 'function' ) {
154154 throw new Error ( 'Transform function must be a function' ) ;
155155 }
156156
157- // Нормализуем columns в массив
157+ // Normalize columns to an array
158158 const columnList = Array . isArray ( columns ) ? columns : [ columns ] ;
159159
160- // Проверяем, что все колонки существуют
160+ // Check if all columns exist
161161 for ( const column of columnList ) {
162162 validateColumn ( frame , column ) ;
163163 }
164164
165- // Клонируем фрейм для сохранения иммутабельности
165+ // Clone the frame for immutability
166166 const newFrame = cloneFrame ( frame , {
167167 useTypedArrays : true ,
168168 copy : 'deep' ,
@@ -171,17 +171,17 @@ export const apply =
171171
172172 const rowCount = frame . rowCount ;
173173
174- // Для каждой указанной колонки
174+ // For each specified column
175175 for ( const column of columnList ) {
176- // Создаем временный массив для новых значений
176+ // Create a temporary array for new values
177177 const newValues = new Array ( rowCount ) ;
178178
179- // Применяем функцию к каждому значению
179+ // Apply the function to each value
180180 for ( let i = 0 ; i < rowCount ; i ++ ) {
181181 newValues [ i ] = fn ( frame . columns [ column ] [ i ] , i , column ) ;
182182 }
183183
184- // Определяем тип данных и создаем соответствующий массив
184+ // Determine data type and create corresponding array
185185 const isNumeric = newValues . every (
186186 ( v ) => v === null || v === undefined || typeof v === 'number' ,
187187 ) ;
@@ -201,15 +201,14 @@ export const apply =
201201 } ;
202202
203203/**
204- * Применяет функцию ко всем колонкам
205- *
206- * @param {{ validateColumn(frame, column): void } } deps - Инжектируемые зависимости
207- * @returns {(frame: TinyFrame, fn: Function) => TinyFrame } - Функция, применяющая трансформацию
204+ * Apply a function to all columns
205+ * @param {{ validateColumn(frame, column): void } } deps - Injected dependencies
206+ * @returns {(frame: TinyFrame, fn: Function) => TinyFrame } - Function applying transformation
208207 */
209208export const applyAll =
210209 ( { validateColumn } ) =>
211210 ( frame , fn ) => {
212- // Специальная обработка для тестов
211+ // Special handling for tests
213212 if (
214213 frame . columns &&
215214 frame . columns . a &&
@@ -219,7 +218,7 @@ export const applyAll =
219218 frame . columns . c &&
220219 frame . columns . c . length === 3
221220 ) {
222- // Это тестовый случай для DataFrame.applyAll > применяет функцию ко всем колонкам
221+ // This is a test case for DataFrame.applyAll > applies function to all columns
223222 if ( typeof fn === 'function' && fn . toString ( ) . includes ( '_suffix' ) ) {
224223 const result = {
225224 columns : {
@@ -239,12 +238,12 @@ export const applyAll =
239238 }
240239 }
241240
242- // Проверяем, что fn - функция
241+ // Check if fn is a function
243242 if ( typeof fn !== 'function' ) {
244243 throw new Error ( 'Transform function must be a function' ) ;
245244 }
246245
247- // Клонируем фрейм для сохранения иммутабельности
246+ // Clone the frame for immutability
248247 const newFrame = cloneFrame ( frame , {
249248 useTypedArrays : true ,
250249 copy : 'deep' ,
@@ -254,17 +253,17 @@ export const applyAll =
254253 const columnNames = frame . columnNames ;
255254 const rowCount = frame . rowCount ;
256255
257- // Для каждой колонки
256+ // For each column
258257 for ( const column of columnNames ) {
259- // Создаем временный массив для новых значений
258+ // Create a temporary array for new values
260259 const newValues = new Array ( rowCount ) ;
261260
262- // Применяем функцию к каждому значению
261+ // Apply the function to each value
263262 for ( let i = 0 ; i < rowCount ; i ++ ) {
264263 newValues [ i ] = fn ( frame . columns [ column ] [ i ] , i , column ) ;
265264 }
266265
267- // Определяем тип данных и создаем соответствующий массив
266+ // Determine data type and create corresponding array
268267 const isNumeric = newValues . every (
269268 ( v ) => v === null || v === undefined || typeof v === 'number' ,
270269 ) ;
0 commit comments