Documentation
¶
Overview ¶
Package strings ports numpy.strings: elementwise string operations over an N-dimensional array of Go strings. StrArray mirrors numgo.Array's view model (shape/strides/offset over shared data); all index arithmetic goes through internal/nditer.
Divergences from numpy.strings:
- Broadcasting: not implemented. numpy broadcasts string operands, but Go callers pre-expand scalars via BroadcastTo; elementwise ops require equal shapes.
- Mod, Encode, Decode: skipped (format-spec machinery; Go strings are UTF-8 already). Join/Split/SplitLines are kept even though numpy.strings removed them (numpy.char still has them).
- Contains: a Go idiom numpy lacks, provided for parity with the strings package.
Index ¶
- func Atoi(a *StrArray) ([]int64, error)
- func ParseFloat(a *StrArray) (*numgo.Array[float64], error)
- type ElementError
- type StrArray
- func (a *StrArray) At(coords ...int) string
- func (a *StrArray) Capitalize() *StrArray
- func (a *StrArray) Center(width int) *StrArray
- func (a *StrArray) Contains(sub string) []bool
- func (a *StrArray) Copy() *StrArray
- func (a *StrArray) Count(sub string, start, stop int) *StrArray
- func (a *StrArray) Data() []string
- func (a *StrArray) EndsWith(suffix string, stop int) []bool
- func (a *StrArray) ExpandTabs(tabWidth int) *StrArray
- func (a *StrArray) Find(sub string, start int) *StrArray
- func (a *StrArray) Index(sub string, start int) *StrArray
- func (a *StrArray) IsAlNum() []bool
- func (a *StrArray) IsAlpha() []bool
- func (a *StrArray) IsContiguous() bool
- func (a *StrArray) IsDecimal() []bool
- func (a *StrArray) IsDigit() []bool
- func (a *StrArray) IsEmpty() []bool
- func (a *StrArray) IsLower() []bool
- func (a *StrArray) IsNumeric() []bool
- func (a *StrArray) IsSpace() []bool
- func (a *StrArray) IsTitle() []bool
- func (a *StrArray) IsUpper() []bool
- func (a *StrArray) Join(parts []string) *StrArray
- func (a *StrArray) LJust(width int) *StrArray
- func (a *StrArray) LStrip(chars string) *StrArray
- func (a *StrArray) Lower() *StrArray
- func (a *StrArray) Ndim() int
- func (a *StrArray) Partition(sep string) [][]string
- func (a *StrArray) RFind(sub string, stop int) *StrArray
- func (a *StrArray) RIndex(sub string, stop int) *StrArray
- func (a *StrArray) RJust(width int) *StrArray
- func (a *StrArray) RPartition(sep string) [][]string
- func (a *StrArray) RStrip(chars string) *StrArray
- func (a *StrArray) Ravel() *StrArray
- func (a *StrArray) Repeat(count int) *StrArray
- func (a *StrArray) Replace(old, new string, n int) *StrArray
- func (a *StrArray) Reshape(shape ...int) *StrArray
- func (a *StrArray) Set(coords []int, v string) *StrArray
- func (a *StrArray) Shape() []int
- func (a *StrArray) Size() int
- func (a *StrArray) Slice(rs ...numgo.Range) *StrArray
- func (a *StrArray) SliceVal(start, stop int) *StrArray
- func (a *StrArray) Split(sep string) [][]string
- func (a *StrArray) SplitLines() [][]string
- func (a *StrArray) StartsWith(prefix string, start int) []bool
- func (a *StrArray) Strip(chars string) *StrArray
- func (a *StrArray) Swapcase() *StrArray
- func (a *StrArray) Title() *StrArray
- func (a *StrArray) Translate(table map[rune]rune) *StrArray
- func (a *StrArray) Transpose(axes ...int) *StrArray
- func (a *StrArray) Upper() *StrArray
- func (a *StrArray) ZFill(width int) *StrArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ElementError ¶
ElementError reports the C-order linear index of the element that failed to parse, wrapping strconv's own error text.
func (*ElementError) Error ¶
func (e *ElementError) Error() string
Error formats the failure with the element's linear index.
func (*ElementError) Unwrap ¶
func (e *ElementError) Unwrap() error
Unwrap returns the underlying parse error.
type StrArray ¶
type StrArray struct {
// contains filtered or unexported fields
}
StrArray is an N-dimensional strided view over a flat data slice of strings. Strides are in element units. Views share data; use Copy for an independent array.
func Concatenate ¶
Concatenate joins arrays along axis (negative allowed). All dimensions except axis must match exactly. The result is new data.
func FromFloat ¶
FromFloat formats every element of a with the format verb (a fmt.Sprintf verb like "%g" or "%.3f") into a new StrArray of the same shape.
func FromSlice ¶
FromSlice returns a new array holding a copy of data. With no shape the result is 1-D; otherwise the element count must match.
func (*StrArray) Capitalize ¶
Capitalize uppercases the first character and lowercases the rest of each element (numpy semantics).
func (*StrArray) Center ¶
Center pads each element with spaces on both sides to width; the extra space goes to the right (CPython: left = deficit/2, rounded down).
func (*StrArray) Contains ¶
Contains reports whether sub occurs in each element. A Go idiom numpy lacks (numpy composes it from find >= 0); documented addition.
func (*StrArray) Count ¶
Count returns the number of non-overlapping occurrences of sub between start and stop in each element. Bounds are Python-style exclusive-stop when stop >= 0; a negative stop counts from the end (stop = -1 → whole element via the n+1 wrap matching Python's [start:-1] convention).
func (*StrArray) Data ¶
Data returns the underlying storage starting at the view offset. For contiguous arrays it reads in C order; for non-contiguous views the element order does NOT match C order — use Ravel().Data() instead. Mutating it affects every array sharing the storage.
func (*StrArray) EndsWith ¶
EndsWith reports whether each element ends with suffix before stop. A stop of -1 means the whole element.
func (*StrArray) ExpandTabs ¶
ExpandTabs replaces each tab with spaces to the next tab stop of tabWidth runes (columns reset at newlines); tabWidth <= 0 removes tabs.
func (*StrArray) Find ¶
Find returns the lowest index of sub at or after start in each element, or -1 when absent.
func (*StrArray) Index ¶
Index is Find but panics "substring not found" (numpy ValueError wording) if any element lacks sub.
func (*StrArray) IsContiguous ¶
IsContiguous reports whether the array is laid out in C order.
func (*StrArray) IsDecimal ¶
IsDecimal reports whether every character is a Unicode decimal digit (identical to IsDigit here; Python separates them only for non-Nd digits).
func (*StrArray) IsEmpty ¶
IsEmpty reports whether each element is the empty string. A Go idiom (Python has no str.isempty); documented addition.
func (*StrArray) IsLower ¶
IsLower reports whether all cased characters are lowercase and at least one exists.
func (*StrArray) IsNumeric ¶
IsNumeric reports whether every character is numeric (digits, fractions, Roman numerals — Python str.isnumeric semantics).
func (*StrArray) IsTitle ¶
IsTitle reports whether each element is title-cased: cased characters follow uncased ones and vice versa (Python str.istitle; empty → false).
func (*StrArray) IsUpper ¶
IsUpper reports whether all cased characters are uppercase and at least one exists.
func (*StrArray) Join ¶
Join joins parts with each element as the separator (numpy.char.join semantics; numpy.strings removed join).
func (*StrArray) Partition ¶
Partition splits each element at the first sep into a []string{head, sep, tail}; a missing sep yields {elem, "", ""} (numpy semantics).
func (*StrArray) RFind ¶
RFind returns the highest index of sub before stop in each element, or -1 when absent. A stop of -1 searches the whole element.
func (*StrArray) RIndex ¶
RIndex is RFind but panics "substring not found" if any element lacks sub.
func (*StrArray) RPartition ¶
RPartition splits each element at the last sep into []string{head, sep, tail}; a missing sep yields {"", "", elem}.
func (*StrArray) Ravel ¶
Ravel flattens to 1-D in C order. A contiguous array returns a view sharing data; a non-contiguous array is copied first, so sharing is not guaranteed.
func (*StrArray) Repeat ¶
Repeat repeats each element count times (numpy.strings.multiply). Negative counts panic (numpy ValueError).
func (*StrArray) Replace ¶
Replace replaces up to n occurrences of old with new in each element (n < 0 means all).
func (*StrArray) Reshape ¶
Reshape views the array with a new shape when the data is contiguous; a non-contiguous array is copied first, so the result may not share data. At most one dimension may be -1 and is inferred.
func (*StrArray) Slice ¶
Slice views a strided sub-array. Ranges cover the leading axes; trailing axes not mentioned are taken whole (numpy a[:2] semantics), so a zero Range or a missing axis means the entire axis. The result shares data. Bounds follow numpy: negative indices count from the end and a negative Step reverses the axis.
func (*StrArray) SliceVal ¶
SliceVal slices each element by Python-style [start:stop] byte bounds; negative values count from the end. Named SliceVal because StrArray.Slice is the view op (numpy.strings.slice).
func (*StrArray) Split ¶
Split splits each element at sep into a [][]string in C order. numpy strings removed split from its namespace (numpy.char keeps it); provided for chararray parity.
func (*StrArray) SplitLines ¶
SplitLines splits each element at line boundaries (\n, \r\n, \r) into a [][]string in C order, dropping the trailing empty piece a final newline would produce (Python str.splitlines semantics).
func (*StrArray) StartsWith ¶
StartsWith reports whether each element starts with prefix from start.
func (*StrArray) Title ¶
Title uppercases the first character of each word and lowercases the rest, matching numpy.strings.title: a character starts a word when the preceding character is uncased, so "don't do" → "Don'T Do". This equals Go's deprecated strings.Title and diverges from modern-English intuition; numpy wording is authoritative.
func (*StrArray) Translate ¶
Translate maps runes through the table (absent runes pass through). numpy's delete parameter has no map representation — delete via Replace with "". Documented simplification.
func (*StrArray) Transpose ¶
Transpose views the array with its axes permuted. With no axes it reverses them (numpy .T). The result shares data.