_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q267800
DataFrame.add_virtual_columns_spherical_to_cartesian
test
def add_virtual_columns_spherical_to_cartesian(self, alpha, delta, distance, xname="x", yname="y", zname="z", propagate_uncertainties=False, center=[0, 0, 0], center_name="solar_position", radians=False): """Co...
python
{ "resource": "" }
q267801
DataFrame.add_virtual_columns_cartesian_to_spherical
test
def add_virtual_columns_cartesian_to_spherical(self, x="x", y="y", z="z", alpha="l", delta="b", distance="distance", radians=False, center=None, center_name="solar_position"): """Convert cartesian to spherical coordinates. :param x: :param y: :param z: :param alpha: :p...
python
{ "resource": "" }
q267802
DataFrame.add_virtual_column
test
def add_virtual_column(self, name, expression, unique=False): """Add a virtual column to the DataFrame. Example: >>> df.add_virtual_column("r", "sqrt(x**2 + y**2 + z**2)") >>> df.select("r < 10") :param: str name: name of virtual column :param: expression: expression f...
python
{ "resource": "" }
q267803
DataFrame.delete_virtual_column
test
def delete_virtual_column(self, name): """Deletes a virtual column from a DataFrame.""" del self.virtual_columns[name] self.signal_column_changed.emit(self, name, "delete")
python
{ "resource": "" }
q267804
DataFrame.add_variable
test
def add_variable(self, name, expression, overwrite=True, unique=True): """Add a variable to to a DataFrame. A variable may refer to other variables, and virtual columns and expression may refer to variables. Example >>> df.add_variable('center', 0) >>> df.add_virtual_column('x...
python
{ "resource": "" }
q267805
DataFrame.delete_variable
test
def delete_variable(self, name): """Deletes a variable from a DataFrame.""" del self.variables[name] self.signal_variable_changed.emit(self, name, "delete")
python
{ "resource": "" }
q267806
DataFrame.tail
test
def tail(self, n=10): """Return a shallow copy a DataFrame with the last n rows.""" N = len(self) # self.cat(i1=max(0, N-n), i2=min(len(self), N)) return self[max(0, N - n):min(len(self), N)]
python
{ "resource": "" }
q267807
DataFrame.head_and_tail_print
test
def head_and_tail_print(self, n=5): """Display the first and last n elements of a DataFrame.""" from IPython import display display.display(display.HTML(self._head_and_tail_table(n)))
python
{ "resource": "" }
q267808
DataFrame.describe
test
def describe(self, strings=True, virtual=True, selection=None): """Give a description of the DataFrame. >>> import vaex >>> df = vaex.example()[['x', 'y', 'z']] >>> df.describe() x y z dtype float64 float64 float64 co...
python
{ "resource": "" }
q267809
DataFrame.cat
test
def cat(self, i1, i2, format='html'): """Display the DataFrame from row i1 till i2 For format, see https://pypi.org/project/tabulate/ :param int i1: Start row :param int i2: End row. :param str format: Format to use, e.g. 'html', 'plain', 'latex' """ from IPytho...
python
{ "resource": "" }
q267810
DataFrame.set_current_row
test
def set_current_row(self, value): """Set the current row, and emit the signal signal_pick.""" if (value is not None) and ((value < 0) or (value >= len(self))): raise IndexError("index %d out of range [0,%d]" % (value, len(self))) self._current_row = value self.signal_pick.emi...
python
{ "resource": "" }
q267811
DataFrame.get_column_names
test
def get_column_names(self, virtual=True, strings=True, hidden=False, regex=None): """Return a list of column names Example: >>> import vaex >>> df = vaex.from_scalars(x=1, x2=2, y=3, s='string') >>> df['r'] = (df.x**2 + df.y**2)**2 >>> df.get_column_names() ['x'...
python
{ "resource": "" }
q267812
DataFrame.trim
test
def trim(self, inplace=False): '''Return a DataFrame, where all columns are 'trimmed' by the active range. For the returned DataFrame, df.get_active_range() returns (0, df.length_original()). {note_copy} :param inplace: {inplace} :rtype: DataFrame ''' df = self...
python
{ "resource": "" }
q267813
DataFrame.take
test
def take(self, indices): '''Returns a DataFrame containing only rows indexed by indices {note_copy} Example: >>> import vaex, numpy as np >>> df = vaex.from_arrays(s=np.array(['a', 'b', 'c', 'd']), x=np.arange(1,5)) >>> df.take([0,2]) # s x 0 a...
python
{ "resource": "" }
q267814
DataFrame.extract
test
def extract(self): '''Return a DataFrame containing only the filtered rows. {note_copy} The resulting DataFrame may be more efficient to work with when the original DataFrame is heavily filtered (contains just a small number of rows). If no filtering is applied, it returns a t...
python
{ "resource": "" }
q267815
DataFrame.sample
test
def sample(self, n=None, frac=None, replace=False, weights=None, random_state=None): '''Returns a DataFrame with a random set of rows {note_copy} Provide either n or frac. Example: >>> import vaex, numpy as np >>> df = vaex.from_arrays(s=np.array(['a', 'b', 'c', 'd'])...
python
{ "resource": "" }
q267816
DataFrame.split_random
test
def split_random(self, frac, random_state=None): '''Returns a list containing random portions of the DataFrame. {note_copy} Example: >>> import vaex, import numpy as np >>> np.random.seed(111) >>> df = vaex.from_arrays(x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> fo...
python
{ "resource": "" }
q267817
DataFrame.split
test
def split(self, frac): '''Returns a list containing ordered subsets of the DataFrame. {note_copy} Example: >>> import vaex >>> df = vaex.from_arrays(x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> for dfs in df.split(frac=0.3): ... print(dfs.x.values) ... ...
python
{ "resource": "" }
q267818
DataFrame.sort
test
def sort(self, by, ascending=True, kind='quicksort'): '''Return a sorted DataFrame, sorted by the expression 'by' {note_copy} {note_filter} Example: >>> import vaex, numpy as np >>> df = vaex.from_arrays(s=np.array(['a', 'b', 'c', 'd']), x=np.arange(1,5)) >>> ...
python
{ "resource": "" }
q267819
DataFrame.materialize
test
def materialize(self, virtual_column, inplace=False): '''Returns a new DataFrame where the virtual column is turned into an in memory numpy array. Example: >>> x = np.arange(1,4) >>> y = np.arange(2,5) >>> df = vaex.from_arrays(x=x, y=y) >>> df['r'] = (df.x**2 + df.y**2...
python
{ "resource": "" }
q267820
DataFrame.selection_undo
test
def selection_undo(self, name="default", executor=None): """Undo selection, for the name.""" logger.debug("undo") executor = executor or self.executor assert self.selection_can_undo(name=name) selection_history = self.selection_histories[name] index = self.selection_histo...
python
{ "resource": "" }
q267821
DataFrame.selection_redo
test
def selection_redo(self, name="default", executor=None): """Redo selection, for the name.""" logger.debug("redo") executor = executor or self.executor assert self.selection_can_redo(name=name) selection_history = self.selection_histories[name] index = self.selection_histo...
python
{ "resource": "" }
q267822
DataFrame.selection_can_redo
test
def selection_can_redo(self, name="default"): """Can selection name be redone?""" return (self.selection_history_indices[name] + 1) < len(self.selection_histories[name])
python
{ "resource": "" }
q267823
DataFrame.select
test
def select(self, boolean_expression, mode="replace", name="default", executor=None): """Perform a selection, defined by the boolean expression, and combined with the previous selection using the given mode. Selections are recorded in a history tree, per name, undo/redo can be done for them separately. ...
python
{ "resource": "" }
q267824
DataFrame.select_non_missing
test
def select_non_missing(self, drop_nan=True, drop_masked=True, column_names=None, mode="replace", name="default"): """Create a selection that selects rows having non missing values for all columns in column_names. The name reflect Panda's, no rows are really dropped, but a mask is kept to keep track of ...
python
{ "resource": "" }
q267825
DataFrame.dropna
test
def dropna(self, drop_nan=True, drop_masked=True, column_names=None): """Create a shallow copy of a DataFrame, with filtering set using select_non_missing. :param drop_nan: drop rows when there is a NaN in any of the columns (will only affect float values) :param drop_masked: drop rows when the...
python
{ "resource": "" }
q267826
DataFrame.select_rectangle
test
def select_rectangle(self, x, y, limits, mode="replace", name="default"): """Select a 2d rectangular box in the space given by x and y, bounds by limits. Example: >>> df.select_box('x', 'y', [(0, 10), (0, 1)]) :param x: expression for the x space :param y: expression fo the y ...
python
{ "resource": "" }
q267827
DataFrame.select_box
test
def select_box(self, spaces, limits, mode="replace", name="default"): """Select a n-dimensional rectangular box bounded by limits. The following examples are equivalent: >>> df.select_box(['x', 'y'], [(0, 10), (0, 1)]) >>> df.select_rectangle('x', 'y', [(0, 10), (0, 1)]) :para...
python
{ "resource": "" }
q267828
DataFrame.select_circle
test
def select_circle(self, x, y, xc, yc, r, mode="replace", name="default", inclusive=True): """ Select a circular region centred on xc, yc, with a radius of r. Example: >>> df.select_circle('x','y',2,3,1) :param x: expression for the x space :param y: expression for the ...
python
{ "resource": "" }
q267829
DataFrame.select_ellipse
test
def select_ellipse(self, x, y, xc, yc, width, height, angle=0, mode="replace", name="default", radians=False, inclusive=True): """ Select an elliptical region centred on xc, yc, with a certain width, height and angle. Example: >>> df.select_ellipse('x','y', 2, -1, 5,1, 30, name...
python
{ "resource": "" }
q267830
DataFrame.select_lasso
test
def select_lasso(self, expression_x, expression_y, xsequence, ysequence, mode="replace", name="default", executor=None): """For performance reasons, a lasso selection is handled differently. :param str expression_x: Name/expression for the x coordinate :param str expression_y: Name/expression f...
python
{ "resource": "" }
q267831
DataFrame.select_inverse
test
def select_inverse(self, name="default", executor=None): """Invert the selection, i.e. what is selected will not be, and vice versa :param str name: :param executor: :return: """ def create(current): return selections.SelectionInvert(current) self._s...
python
{ "resource": "" }
q267832
DataFrame.set_selection
test
def set_selection(self, selection, name="default", executor=None): """Sets the selection object :param selection: Selection object :param name: selection 'slot' :param executor: :return: """ def create(current): return selection self._selectio...
python
{ "resource": "" }
q267833
DataFrame._selection
test
def _selection(self, create_selection, name, executor=None, execute_fully=False): """select_lasso and select almost share the same code""" selection_history = self.selection_histories[name] previous_index = self.selection_history_indices[name] current = selection_history[previous_index] ...
python
{ "resource": "" }
q267834
DataFrame._find_valid_name
test
def _find_valid_name(self, initial_name): '''Finds a non-colliding name by optional postfixing''' return vaex.utils.find_valid_name(initial_name, used=self.get_column_names(hidden=True))
python
{ "resource": "" }
q267835
DataFrame._root_nodes
test
def _root_nodes(self): """Returns a list of string which are the virtual columns that are not used in any other virtual column.""" # these lists (~used as ordered set) keep track of leafes and root nodes # root nodes root_nodes = [] leafes = [] def walk(node): ...
python
{ "resource": "" }
q267836
DataFrame._graphviz
test
def _graphviz(self, dot=None): """Return a graphviz.Digraph object with a graph of all virtual columns""" from graphviz import Digraph dot = dot or Digraph(comment='whole dataframe') root_nodes = self._root_nodes() for column in root_nodes: self[column]._graphviz(dot=...
python
{ "resource": "" }
q267837
DataFrameLocal.categorize
test
def categorize(self, column, labels=None, check=True): """Mark column as categorical, with given labels, assuming zero indexing""" column = _ensure_string_from_expression(column) if check: vmin, vmax = self.minmax(column) if labels is None: N = int(vmax + ...
python
{ "resource": "" }
q267838
DataFrameLocal.ordinal_encode
test
def ordinal_encode(self, column, values=None, inplace=False): """Encode column as ordinal values and mark it as categorical. The existing column is renamed to a hidden column and replaced by a numerical columns with values between [0, len(values)-1]. """ column = _ensure_string_...
python
{ "resource": "" }
q267839
DataFrameLocal.data
test
def data(self): """Gives direct access to the data as numpy arrays. Convenient when working with IPython in combination with small DataFrames, since this gives tab-completion. Only real columns (i.e. no virtual) columns can be accessed, for getting the data from virtual columns, use Dat...
python
{ "resource": "" }
q267840
DataFrameLocal.length
test
def length(self, selection=False): """Get the length of the DataFrames, for the selection of the whole DataFrame. If selection is False, it returns len(df). TODO: Implement this in DataFrameRemote, and move the method up in :func:`DataFrame.length` :param selection: When True, will re...
python
{ "resource": "" }
q267841
DataFrameLocal._hstack
test
def _hstack(self, other, prefix=None): """Join the columns of the other DataFrame to this one, assuming the ordering is the same""" assert len(self) == len(other), "does not make sense to horizontally stack DataFrames with different lengths" for name in other.get_column_names(): if p...
python
{ "resource": "" }
q267842
DataFrameLocal.concat
test
def concat(self, other): """Concatenates two DataFrames, adding the rows of one the other DataFrame to the current, returned in a new DataFrame. No copy of the data is made. :param other: The other DataFrame that is concatenated with this DataFrame :return: New DataFrame with the rows ...
python
{ "resource": "" }
q267843
DataFrameLocal.export_hdf5
test
def export_hdf5(self, path, column_names=None, byteorder="=", shuffle=False, selection=False, progress=None, virtual=False, sort=None, ascending=True): """Exports the DataFrame to a vaex hdf5 file :param DataFrameLocal df: DataFrame to export :param str path: path for file :param lis[st...
python
{ "resource": "" }
q267844
DataFrameArrays.add_column
test
def add_column(self, name, data): """Add a column to the DataFrame :param str name: name of column :param data: numpy array with the data """ # assert _is_array_type_ok(data), "dtype not supported: %r, %r" % (data.dtype, data.dtype.type) # self._length = len(data) ...
python
{ "resource": "" }
q267845
patch
test
def patch(f): '''Adds method f to the DataFrame class''' name = f.__name__ setattr(DataFrame, name, f) return f
python
{ "resource": "" }
q267846
register_function
test
def register_function(scope=None, as_property=False, name=None): """Decorator to register a new function with vaex. Example: >>> import vaex >>> df = vaex.example() >>> @vaex.register_function() >>> def invert(x): >>> return 1/x >>> df.x.invert() >>> import numpy as np >>...
python
{ "resource": "" }
q267847
fillna
test
def fillna(ar, value, fill_nan=True, fill_masked=True): '''Returns an array where missing values are replaced by value. If the dtype is object, nan values and 'nan' string values are replaced by value when fill_nan==True. ''' ar = ar if not isinstance(ar, column.Column) else ar.to_numpy() if ar...
python
{ "resource": "" }
q267848
dt_dayofweek
test
def dt_dayofweek(x): """Obtain the day of the week with Monday=0 and Sunday=6 :returns: an expression containing the day of week. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.datetime64) ...
python
{ "resource": "" }
q267849
dt_dayofyear
test
def dt_dayofyear(x): """The ordinal day of the year. :returns: an expression containing the ordinal day of the year. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.datetime64) >>> df = vae...
python
{ "resource": "" }
q267850
dt_is_leap_year
test
def dt_is_leap_year(x): """Check whether a year is a leap year. :returns: an expression which evaluates to True if a year is a leap year, and to False otherwise. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:3...
python
{ "resource": "" }
q267851
dt_year
test
def dt_year(x): """Extracts the year out of a datetime sample. :returns: an expression containing the year extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.date...
python
{ "resource": "" }
q267852
dt_month
test
def dt_month(x): """Extracts the month out of a datetime sample. :returns: an expression containing the month extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.d...
python
{ "resource": "" }
q267853
dt_month_name
test
def dt_month_name(x): """Returns the month names of a datetime sample in English. :returns: an expression containing the month names extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12...
python
{ "resource": "" }
q267854
dt_day
test
def dt_day(x): """Extracts the day from a datetime sample. :returns: an expression containing the day extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.datetime6...
python
{ "resource": "" }
q267855
dt_day_name
test
def dt_day_name(x): """Returns the day names of a datetime sample in English. :returns: an expression containing the day names extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34...
python
{ "resource": "" }
q267856
dt_weekofyear
test
def dt_weekofyear(x): """Returns the week ordinal of the year. :returns: an expression containing the week ordinal of the year, extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:3...
python
{ "resource": "" }
q267857
dt_hour
test
def dt_hour(x): """Extracts the hour out of a datetime samples. :returns: an expression containing the hour extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=np.dat...
python
{ "resource": "" }
q267858
dt_minute
test
def dt_minute(x): """Extracts the minute out of a datetime samples. :returns: an expression containing the minute extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=...
python
{ "resource": "" }
q267859
dt_second
test
def dt_second(x): """Extracts the second out of a datetime samples. :returns: an expression containing the second extracted from a datetime column. Example: >>> import vaex >>> import numpy as np >>> date = np.array(['2009-10-12T03:31:00', '2016-02-11T10:17:34', '2015-11-12T11:34:22'], dtype=...
python
{ "resource": "" }
q267860
str_capitalize
test
def str_capitalize(x): """Capitalize the first letter of a string sample. :returns: an expression containing the capitalized strings. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >>> df = vaex.from_arrays(text=text) >>> df # text ...
python
{ "resource": "" }
q267861
str_cat
test
def str_cat(x, other): """Concatenate two string columns on a row-by-row basis. :param expression other: The expression of the other column to be concatenated. :returns: an expression containing the concatenated columns. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is com...
python
{ "resource": "" }
q267862
str_contains
test
def str_contains(x, pattern, regex=True): """Check if a string pattern or regex is contained within a sample of a string column. :param str pattern: A string or regex pattern :param bool regex: If True, :returns: an expression which is evaluated to True if the pattern is found in a given sample, and it...
python
{ "resource": "" }
q267863
str_count
test
def str_count(x, pat, regex=False): """Count the occurences of a pattern in sample of a string column. :param str pat: A string or regex pattern :param bool regex: If True, :returns: an expression containing the number of times a pattern is found in each sample. Example: >>> import vaex >...
python
{ "resource": "" }
q267864
str_find
test
def str_find(x, sub, start=0, end=None): """Returns the lowest indices in each string in a column, where the provided substring is fully contained between within a sample. If the substring is not found, -1 is returned. :param str sub: A substring to be found in the samples :param int start: :param ...
python
{ "resource": "" }
q267865
str_get
test
def str_get(x, i): """Extract a character from each sample at the specified position from a string column. Note that if the specified position is out of bound of the string sample, this method returns '', while pandas retunrs nan. :param int i: The index location, at which to extract the character. :re...
python
{ "resource": "" }
q267866
str_index
test
def str_index(x, sub, start=0, end=None): """Returns the lowest indices in each string in a column, where the provided substring is fully contained between within a sample. If the substring is not found, -1 is returned. It is the same as `str.find`. :param str sub: A substring to be found in the samples ...
python
{ "resource": "" }
q267867
str_lower
test
def str_lower(x): """Converts string samples to lower case. :returns: an expression containing the converted strings. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >>> df = vaex.from_arrays(text=text) >>> df # text 0 Something ...
python
{ "resource": "" }
q267868
str_lstrip
test
def str_lstrip(x, to_strip=None): """Remove leading characters from a string sample. :param str to_strip: The string to be removed :returns: an expression containing the modified string column. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >>...
python
{ "resource": "" }
q267869
str_pad
test
def str_pad(x, width, side='left', fillchar=' '): """Pad strings in a given column. :param int width: The total width of the string :param str side: If 'left' than pad on the left, if 'right' than pad on the right side the string. :param str fillchar: The character used for padding. :returns: an ex...
python
{ "resource": "" }
q267870
str_repeat
test
def str_repeat(x, repeats): """Duplicate each string in a column. :param int repeats: number of times each string sample is to be duplicated. :returns: an expression containing the duplicated strings Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] ...
python
{ "resource": "" }
q267871
str_rfind
test
def str_rfind(x, sub, start=0, end=None): """Returns the highest indices in each string in a column, where the provided substring is fully contained between within a sample. If the substring is not found, -1 is returned. :param str sub: A substring to be found in the samples :param int start: :para...
python
{ "resource": "" }
q267872
str_rindex
test
def str_rindex(x, sub, start=0, end=None): """Returns the highest indices in each string in a column, where the provided substring is fully contained between within a sample. If the substring is not found, -1 is returned. Same as `str.rfind`. :param str sub: A substring to be found in the samples :para...
python
{ "resource": "" }
q267873
str_rjust
test
def str_rjust(x, width, fillchar=' '): """Fills the left side of string samples with a specified character such that the strings are left-hand justified. :param int width: The minimal width of the strings. :param str fillchar: The character used for filling. :returns: an expression containing the fille...
python
{ "resource": "" }
q267874
str_rstrip
test
def str_rstrip(x, to_strip=None): """Remove trailing characters from a string sample. :param str to_strip: The string to be removed :returns: an expression containing the modified string column. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >...
python
{ "resource": "" }
q267875
str_slice
test
def str_slice(x, start=0, stop=None): # TODO: support n """Slice substrings from each string element in a column. :param int start: The start position for the slice operation. :param int end: The stop position for the slice operation. :returns: an expression containing the sliced substrings. Exam...
python
{ "resource": "" }
q267876
str_strip
test
def str_strip(x, to_strip=None): """Removes leading and trailing characters. Strips whitespaces (including new lines), or a set of specified characters from each string saple in a column, both from the left right sides. :param str to_strip: The characters to be removed. All combinations of the cha...
python
{ "resource": "" }
q267877
str_title
test
def str_title(x): """Converts all string samples to titlecase. :returns: an expression containing the converted strings. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >>> df = vaex.from_arrays(text=text) >>> df # text 0 Somethin...
python
{ "resource": "" }
q267878
str_upper
test
def str_upper(x): """Converts all strings in a column to uppercase. :returns: an expression containing the converted strings. Example: >>> import vaex >>> text = ['Something', 'very pretty', 'is coming', 'our', 'way.'] >>> df = vaex.from_arrays(text=text) >>> df # text 0 Som...
python
{ "resource": "" }
q267879
get_autotype
test
def get_autotype(arr): """ Attempts to return a numpy array converted to the most sensible dtype Value errors will be caught and simply return the original array Tries to make dtype int, then float, then no change """ try: narr = arr.astype('float') if (narr < sys.maxsize).all() ...
python
{ "resource": "" }
q267880
Struct.as_recarray
test
def as_recarray(self): """ Convert into numpy recordarray """ dtype = [(k,v.dtype) for k,v in self.__dict__.iteritems()] R = numpy.recarray(len(self.__dict__[k]),dtype=dtype) for key in self.__dict__: R[key] = self.__dict__[key] return R
python
{ "resource": "" }
q267881
store_properties
test
def store_properties(fh, props, comment=None, timestamp=True): """ Writes properties to the file in Java properties format. :param fh: a writable file-like object :param props: a mapping (dict) or iterable of key/value pairs :param comment: comment to write to the beginning of the file :param tim...
python
{ "resource": "" }
q267882
write_comment
test
def write_comment(fh, comment): """ Writes a comment to the file in Java properties format. Newlines in the comment text are automatically turned into a continuation of the comment by adding a "#" to the beginning of each line. :param fh: a writable file-like object :param comment: comment strin...
python
{ "resource": "" }
q267883
write_property
test
def write_property(fh, key, value): """ Write a single property to the file in Java properties format. :param fh: a writable file-like object :param key: the key to write :param value: the value to write """ if key is COMMENT: write_comment(fh, value) return _require_string(key, 'keys'...
python
{ "resource": "" }
q267884
iter_properties
test
def iter_properties(fh, comments=False): """ Incrementally read properties from a Java .properties file. Yields tuples of key/value pairs. If ``comments`` is `True`, comments will be included with ``jprops.COMMENT`` in place of the key. :param fh: a readable file-like object :param comments...
python
{ "resource": "" }
q267885
_universal_newlines
test
def _universal_newlines(fp): """ Wrap a file to convert newlines regardless of whether the file was opened with the "universal newlines" option or not. """ # if file was opened with universal newline support we don't need to convert if 'U' in getattr(fp, 'mode', ''): for line in fp: yield line...
python
{ "resource": "" }
q267886
show_versions
test
def show_versions(): '''Return the version information for all librosa dependencies.''' core_deps = ['audioread', 'numpy', 'scipy', 'sklearn', 'joblib', 'decorator', 'six', 'soundfile', ...
python
{ "resource": "" }
q267887
rename_kw
test
def rename_kw(old_name, old_value, new_name, new_value, version_deprecated, version_removed): '''Handle renamed arguments. Parameters ---------- old_name : str old_value The name and value of the old argument new_name : str new_value The name and value of the ...
python
{ "resource": "" }
q267888
set_fftlib
test
def set_fftlib(lib=None): '''Set the FFT library used by librosa. Parameters ---------- lib : None or module Must implement an interface compatible with `numpy.fft`. If `None`, reverts to `numpy.fft`. Examples -------- Use `pyfftw`: >>> import pyfftw >>> librosa.se...
python
{ "resource": "" }
q267889
beat_track
test
def beat_track(input_file, output_csv): '''Beat tracking function :parameters: - input_file : str Path to input audio file (wav, mp3, m4a, flac, etc.) - output_file : str Path to save beat event timestamps as a CSV file ''' print('Loading ', input_file) y, sr = lib...
python
{ "resource": "" }
q267890
adjust_tuning
test
def adjust_tuning(input_file, output_file): '''Load audio, estimate tuning, apply pitch correction, and save.''' print('Loading ', input_file) y, sr = librosa.load(input_file) print('Separating harmonic component ... ') y_harm = librosa.effects.harmonic(y) print('Estimating tuning ... ') #...
python
{ "resource": "" }
q267891
frames_to_samples
test
def frames_to_samples(frames, hop_length=512, n_fft=None): """Converts frame indices to audio sample indices. Parameters ---------- frames : number or np.ndarray [shape=(n,)] frame index or vector of frame indices hop_length : int > 0 [scalar] number of samples between successi...
python
{ "resource": "" }
q267892
samples_to_frames
test
def samples_to_frames(samples, hop_length=512, n_fft=None): """Converts sample indices into STFT frames. Examples -------- >>> # Get the frame numbers for every 256 samples >>> librosa.samples_to_frames(np.arange(0, 22050, 256)) array([ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, ...
python
{ "resource": "" }
q267893
time_to_frames
test
def time_to_frames(times, sr=22050, hop_length=512, n_fft=None): """Converts time stamps into STFT frames. Parameters ---------- times : np.ndarray [shape=(n,)] time (in seconds) or vector of time values sr : number > 0 [scalar] audio sampling rate hop_length : int > 0 [scalar...
python
{ "resource": "" }
q267894
midi_to_note
test
def midi_to_note(midi, octave=True, cents=False): '''Convert one or more MIDI numbers to note strings. MIDI numbers will be rounded to the nearest integer. Notes will be of the format 'C0', 'C#0', 'D0', ... Examples -------- >>> librosa.midi_to_note(0) 'C-1' >>> librosa.midi_to_note(3...
python
{ "resource": "" }
q267895
hz_to_mel
test
def hz_to_mel(frequencies, htk=False): """Convert Hz to Mels Examples -------- >>> librosa.hz_to_mel(60) 0.9 >>> librosa.hz_to_mel([110, 220, 440]) array([ 1.65, 3.3 , 6.6 ]) Parameters ---------- frequencies : number or np.ndarray [shape=(n,)] , float scalar or arr...
python
{ "resource": "" }
q267896
mel_to_hz
test
def mel_to_hz(mels, htk=False): """Convert mel bin numbers to frequencies Examples -------- >>> librosa.mel_to_hz(3) 200. >>> librosa.mel_to_hz([1,2,3,4,5]) array([ 66.667, 133.333, 200. , 266.667, 333.333]) Parameters ---------- mels : np.ndarray [shape=(n,)],...
python
{ "resource": "" }
q267897
fft_frequencies
test
def fft_frequencies(sr=22050, n_fft=2048): '''Alternative implementation of `np.fft.fftfreq` Parameters ---------- sr : number > 0 [scalar] Audio sampling rate n_fft : int > 0 [scalar] FFT window size Returns ------- freqs : np.ndarray [shape=(1 + n_fft/2,)] F...
python
{ "resource": "" }
q267898
cqt_frequencies
test
def cqt_frequencies(n_bins, fmin, bins_per_octave=12, tuning=0.0): """Compute the center frequencies of Constant-Q bins. Examples -------- >>> # Get the CQT frequencies for 24 notes, starting at C2 >>> librosa.cqt_frequencies(24, fmin=librosa.note_to_hz('C2')) array([ 65.406, 69.296, 73.41...
python
{ "resource": "" }
q267899
mel_frequencies
test
def mel_frequencies(n_mels=128, fmin=0.0, fmax=11025.0, htk=False): """Compute an array of acoustic frequencies tuned to the mel scale. The mel scale is a quasi-logarithmic function of acoustic frequency designed such that perceptually similar pitch intervals (e.g. octaves) appear equal in width over t...
python
{ "resource": "" }