<commit_before>'use strict';

// 
// Base class for series classes.
//

var assert = require('chai').assert; 
var E = require('linq');
var moment = require('moment');
var ArrayIterator = require('./iterators/array');
var validateIterator = require('./iterators/validate');
var SkipIterator = require('./iterators/skip');
var SkipWhileIterator = require('./iterators/skip-while');
var TakeIterator = require('../src/iterators/take');
var TakeWhileIterator = require('../src/iterators/take-while');
var SelectIterator = require('../src/iterators/select');
var SelectManyIterator = require('../src/iterators/select-many');
var PairIterator = require('../src/iterators/pair');
var WhereIterator = require('../src/iterators/where');
var CountIterator = require('../src/iterators/count');
var EmptyIterator = require('../src/iterators/empty');
var extend = require('extend');

//
// Represents a time series.
//
var Series = function (config) {

	var self = this;

	if (!self.Constructor) {
		self.Constructor = Series;
	}

	if (!config) {
		self._indexIterable = function () {
			return new EmptyIterator();
		};
		
		self._valuesIterable = function () {
			return new EmptyIterator();
		};
		return;
	}

	assert.isObject(config, "Expected 'config' parameter to Series constructor to be an object with options for initialisation.");

	if (config.iterable) { //todo: this is expensive.

		assert.isFunction(config.iterable, "Expected 'iterable' field of 'config' parameter to Series constructor to be a function that returns an index/value pairs iterator.");

		var iterable = config.iterable;

		self._indexIterable = function () {
			return new SelectIterator(
				iterable(),
				function (pair) {
					return pair[0];
				}
			);
		};
		
		self._valuesIterable = function () {
			return new SelectIterator(
				iterable(),
				function (pair) {
					return pair[1];
				}
			);
		};

		return;
	}

	if (config.values) {
		if (!Object.isFunction(config.values)) {
			assert.isArray(config.values, "Expected 'values' field of 'config' parameter to Series constructor be an array of values or a function that returns an iterator.");
		}
	}

	if (config.index) {
		if (!Object.isFunction(config.index) && !Object.isArray(config.index)) {
			assert.isObject(config.index, "Expected 'index' field of 'config' parameter to Series constructor to be an array, function or Series object.");
		}
	}

	var index = config.index;
	if (!index) {
		self._indexIterable = function () {
			return new CountIterator();
		};
	}
	else if (Object.isFunction(index)) {
		self._indexIterable = index; //todo: test me!
	}
	else if (Object.isArray(index)) {
		self._indexIterable = function () {
			return new ArrayIterator(index);
		};
	}
	else {
		self._indexIterable = function () {
			return index.getValuesIterator();
		};
	}

	var values = config.values;
	if (!values) {
		self._valuesIterable = function () {
			return new EmptyIterator();
		};
	}
	else if (Object.isFunction(values)) {
		self._valuesIterable = values;
	}
	else {

		self._valuesIterable = function () {
			return new ArrayIterator(values);
		}
	}
};

module.exports = Series;

var concatSeries = require('./concat-series');
var DataFrame = require('./dataframe');
var zipSeries = require('./zip-series');

/**
 * Get an iterator for index & values of the series.
 */
Series.prototype.getIterator = function () {
	var self = this;
	return new PairIterator(
		self.getIndexIterator(),
		self.getValuesIterator()
	);
};

/*
 * Get an iterator for the index.
 */
Series.prototype.getIndexIterator = function () {
	var self = this;
	return self._indexIterable();
};

/*
 * Get an iterator for the values.
 */
Series.prototype.getValuesIterator = function () {
	var self = this;
	return self._valuesIterable();
};

/**
 * Retreive the index of the series.
 */
Series.prototype.getIndex = function () {
	var self = this;
	return new Series({
		values: function () {
			return self.getIndexIterator();
		},
	});
};

/**
 * Apply a new index to the Series.
 * 
 * @param {array|Series} newIndex - The new index to apply to the Series.
 */<commit_msg>Comment.<commit_after>'use strict';

// 
// Base class for series classes.
//

var assert = require('chai').assert; 
var E = require('linq');
var moment = require('moment');
var ArrayIterator = require('./iterators/array');
var validateIterator = require('./iterators/validate');
var SkipIterator = require('./iterators/skip');
var SkipWhileIterator = require('./iterators/skip-while');
var TakeIterator = require('../src/iterators/take');
var TakeWhileIterator = require('../src/iterators/take-while');
var SelectIterator = require('../src/iterators/select');
var SelectManyIterator = require('../src/iterators/select-many');
var PairIterator = require('../src/iterators/pair');
var WhereIterator = require('../src/iterators/where');
var CountIterator = require('../src/iterators/count');
var EmptyIterator = require('../src/iterators/empty');
var extend = require('extend');

//
// Represents a time series.
//
var Series = function (config) {

	var self = this;

	if (!self.Constructor) {
		self.Constructor = Series;
	}

	if (!config) {
		self._indexIterable = function () {
			return new EmptyIterator();
		};
		
		self._valuesIterable = function () {
			return new EmptyIterator();
		};
		return;
	}

	assert.isObject(config, "Expected 'config' parameter to Series constructor to be an object with options for initialisation.");

	if (config.iterable) { //todo: this is expensive.

		assert.isFunction(config.iterable, "Expected 'iterable' field of 'config' parameter to Series constructor to be a function that returns an index/value pairs iterator.");

		var iterable = config.iterable;

		self._indexIterable = function () {
			return new SelectIterator(
				iterable(),
				function (pair) {
					return pair[0];
				}
			);
		};
		
		self._valuesIterable = function () {
			return new SelectIterator(
				iterable(),
				function (pair) {
					return pair[1];
				}
			);
		};

		return;
	}

	if (config.values) {
		if (!Object.isFunction(config.values)) {
			assert.isArray(config.values, "Expected 'values' field of 'config' parameter to Series constructor be an array of values or a function that returns an iterator.");
		}
	}

	if (config.index) {
		if (!Object.isFunction(config.index) && !Object.isArray(config.index)) {
			assert.isObject(config.index, "Expected 'index' field of 'config' parameter to Series constructor to be an array, function or Series object.");
		}
	}

	var index = config.index;
	if (!index) {
		self._indexIterable = function () {
			return new CountIterator();
		};
	}
	else if (Object.isFunction(index)) {
		self._indexIterable = index; //todo: test me!
	}
	else if (Object.isArray(index)) {
		self._indexIterable = function () {
			return new ArrayIterator(index);
		};
	}
	else {
		self._indexIterable = function () {
			return index.getValuesIterator();
		};
	}

	var values = config.values;
	if (!values) {
		self._valuesIterable = function () {
			return new EmptyIterator();
		};
	}
	else if (Object.isFunction(values)) {
		self._valuesIterable = values;
	}
	else {

		self._valuesIterable = function () {
			return new ArrayIterator(values);
		}
	}
};

module.exports = Series;

var concatSeries = require('./concat-series');
var DataFrame = require('./dataframe');
var zipSeries = require('./zip-series');

/**
 * Get an iterator for index & values of the series.
 */
Series.prototype.getIterator = function () {
	var self = this;
	return new PairIterator(
		self.getIndexIterator(),
		self.getValuesIterator()
	);
};

/*
 * Get an iterator for the index.
 */
Series.prototype.getIndexIterator = function () {
	var self = this;
	return self._indexIterable();
};

/*
 * Get an iterator for the values.
 */
Series.prototype.getValuesIterator = function () {
	var self = this;
	return self._valuesIterable();
};

/**
 * Retreive the index of the series.
 */
Series.prototype.getIndex = function () { //todo: Do I need to move this to '__iterable'?
	var self = this;
	return new Series({
		values: function () {
			return self.getIndexIterator();
		},
	});
};

/**
 * Apply a new index to the Series.
 * 
 * @param {array|Series} newIndex - The new index to apply to the Series.
 */
{'fraction_non_alphanumeric': 0.14661150991604818, 'fraction_numerical': 0.000486677211339579, 'mean_word_length': 3.6837606837606836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1145472', 'n_tokens_mistral': 2678, 'n_tokens_neox': 2454, 'n_words': 691}