Skip to content

Commit

Permalink
docs: Miscellaneous minor updates/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 6, 2025
1 parent e360e0a commit fdbb9f8
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use polars_error::{polars_bail, PolarsResult};
///
/// # Safety
/// The following invariants hold:
/// * Two consecutives `offsets` casted (`as`) to `usize` are valid slices of `values`.
/// * Two consecutive `offsets` cast (`as`) to `usize` are valid slices of `values`.
/// * `len` is equal to `validity.len()`, when defined.
#[derive(Clone)]
pub struct BinaryArray<O: Offset> {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-arrow/src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub unsafe trait DictionaryKey: NativeType + TryInto<usize> + TryFrom<usize> + H
/// Represents this key as a `usize`.
///
/// # Safety
/// The caller _must_ have checked that the value can be casted to `usize`.
/// The caller _must_ have checked that the value can be cast to `usize`.
#[inline]
unsafe fn as_usize(self) -> usize {
match self.try_into() {
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! * [`ListArray`] and [`MutableListArray`], an array of arrays (e.g. `[[1, 2], None, [], [None]]`)
//! * [`StructArray`] and [`MutableStructArray`], an array of arrays identified by a string (e.g. `{"a": [1, 2], "b": [true, false]}`)
//!
//! All immutable arrays implement the trait object [`Array`] and that can be downcasted
//! All immutable arrays implement the trait object [`Array`] and that can be downcast
//! to a concrete struct based on [`PhysicalType`](crate::datatypes::PhysicalType) available from [`Array::dtype`].
//! All immutable arrays are backed by [`Buffer`](crate::buffer::Buffer) and thus cloning and slicing them is `O(1)`.
//!
Expand Down Expand Up @@ -58,7 +58,7 @@ pub trait Splitable: Sized {
}

/// A trait representing an immutable Arrow array. Arrow arrays are trait objects
/// that are infallibly downcasted to concrete types according to the [`Array::dtype`].
/// that are infallibly downcast to concrete types according to the [`Array::dtype`].
pub trait Array: Send + Sync + dyn_clone::DynClone + 'static {
/// Converts itself to a reference of [`Any`], which enables downcasting to concrete types.
fn as_any(&self) -> &dyn Any;
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl<T: AsRef<str>> AsRef<[u8]> for StrAsBytes<T> {
///
/// # Safety
/// The following invariants hold:
/// * Two consecutives `offsets` casted (`as`) to `usize` are valid slices of `values`.
/// * A slice of `values` taken from two consecutives `offsets` is valid `utf8`.
/// * Two consecutive `offsets` cast (`as`) to `usize` are valid slices of `values`.
/// * A slice of `values` taken from two consecutive `offsets` is valid `utf8`.
/// * `len` is equal to `validity.len()`, when defined.
#[derive(Clone)]
pub struct Utf8Array<O: Offset> {
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-compute/src/cast/decimal_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn decimal_to_decimal_impl<F: Fn(i128) -> Option<i128>>(
.to(ArrowDataType::Decimal(to_precision, to_scale))
}

/// Returns a [`PrimitiveArray<i128>`] with the casted values. Values are `None` on overflow
/// Returns a [`PrimitiveArray<i128>`] with the cast values. Values are `None` on overflow
pub fn decimal_to_decimal(
from: &PrimitiveArray<i128>,
to_precision: usize,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub(super) fn decimal_to_decimal_dyn(
Ok(Box::new(decimal_to_decimal(from, to_precision, to_scale)))
}

/// Returns a [`PrimitiveArray<i128>`] with the casted values. Values are `None` on overflow
/// Returns a [`PrimitiveArray<i128>`] with the cast values. Values are `None` on overflow
pub fn decimal_to_float<T>(from: &PrimitiveArray<i128>) -> PrimitiveArray<T>
where
T: NativeType + Float,
Expand Down Expand Up @@ -110,7 +110,7 @@ where
Ok(Box::new(decimal_to_float::<T>(from)))
}

/// Returns a [`PrimitiveArray<i128>`] with the casted values. Values are `None` on overflow
/// Returns a [`PrimitiveArray<i128>`] with the cast values. Values are `None` on overflow
pub fn decimal_to_integer<T>(from: &PrimitiveArray<i128>) -> PrimitiveArray<T>
where
T: NativeType + NumCast,
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-compute/src/cast/primitive_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where
PrimitiveArray::<O>::from_trusted_len_iter(iter).to(to_type.clone())
}

/// Returns a [`PrimitiveArray<i128>`] with the casted values. Values are `None` on overflow
/// Returns a [`PrimitiveArray<i128>`] with the cast values. Values are `None` on overflow
pub fn integer_to_decimal<T: NativeType + AsPrimitive<i128>>(
from: &PrimitiveArray<T>,
to_precision: usize,
Expand Down Expand Up @@ -213,7 +213,7 @@ where
Ok(Box::new(integer_to_decimal::<T>(from, precision, scale)))
}

/// Returns a [`PrimitiveArray<i128>`] with the casted values. Values are `None` on overflow
/// Returns a [`PrimitiveArray<i128>`] with the cast values. Values are `None` on overflow
pub fn float_to_decimal<T>(
from: &PrimitiveArray<T>,
to_precision: usize,
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ impl ChunkCast for ListChunked {
_ => {
// ensure the inner logical type bubbles up
let (arr, child_type) = cast_list(self, child_type, options)?;
// SAFETY: we just casted so the dtype matches.
// SAFETY: we just cast so the dtype matches.
// we must take this path to correct for physical types.
unsafe {
Ok(Series::from_chunks_and_dtype_unchecked(
Expand All @@ -499,7 +499,7 @@ impl ChunkCast for ListChunked {

// cast to the physical type to avoid logical chunks.
let chunks = cast_chunks(self.chunks(), &physical_type, options)?;
// SAFETY: we just casted so the dtype matches.
// SAFETY: we just cast so the dtype matches.
// we must take this path to correct for physical types.
unsafe {
Ok(Series::from_chunks_and_dtype_unchecked(
Expand Down Expand Up @@ -550,7 +550,7 @@ impl ChunkCast for ArrayChunked {
_ => {
// ensure the inner logical type bubbles up
let (arr, child_type) = cast_fixed_size_list(self, child_type, options)?;
// SAFETY: we just casted so the dtype matches.
// SAFETY: we just cast so the dtype matches.
// we must take this path to correct for physical types.
unsafe {
Ok(Series::from_chunks_and_dtype_unchecked(
Expand All @@ -566,7 +566,7 @@ impl ChunkCast for ArrayChunked {
let physical_type = dtype.to_physical();
// cast to the physical type to avoid logical chunks.
let chunks = cast_chunks(self.chunks(), &physical_type, options)?;
// SAFETY: we just casted so the dtype matches.
// SAFETY: we just cast so the dtype matches.
// we must take this path to correct for physical types.
unsafe {
Ok(Series::from_chunks_and_dtype_unchecked(
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/chunked_array/ndarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ListChunked {

impl DataFrame {
/// Create a 2D [`ndarray::Array`] from this [`DataFrame`]. This requires all columns in the
/// [`DataFrame`] to be non-null and numeric. They will be casted to the same data type
/// [`DataFrame`] to be non-null and numeric. They will be cast to the same data type
/// (if they aren't already).
///
/// For floating point data we implicitly convert `None` to `NaN` without failure.
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-core/src/chunked_array/ops/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<T: PolarsNumericType> ChunkedArray<T> {
S: PolarsNumericType,
{
// if we cast, we create a new arrow buffer
// then we clone the arrays and drop the casted arrays
// then we clone the arrays and drop the cast arrays
// this will ensure we have a single ref count
// and we can mutate in place
let chunks = {
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-io/src/parquet/read/read_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ fn assert_dtypes(dtype: &ArrowDataType) {
use ArrowDataType as D;

match dtype {
// These should all be casted to the BinaryView / Utf8View variants
// These should all be cast to the BinaryView / Utf8View variants
D::Utf8 | D::Binary | D::LargeUtf8 | D::LargeBinary => unreachable!(),

// These should be casted to Float32
// These should be cast to Float32
D::Float16 => unreachable!(),

// This should have been converted to a LargeList
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/conversion/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn resolve_join(

// # Cast lossless
//
// If we do a full join and keys are coalesced, the casted keys must be added up front.
// If we do a full join and keys are coalesced, the cast keys must be added up front.
let key_cols_coalesced =
options.args.should_coalesce() && matches!(&options.args.how, JoinType::Full);
let mut as_with_columns_l = vec![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn try_inline_literal_cast(
Some(av) => av.into(),
}
},
// We generate casted literal datetimes, so ensure we cast upon conversion
// We generate cast literal datetimes, so ensure we cast upon conversion
// to create simpler expr trees.
#[cfg(feature = "dtype-datetime")]
LiteralValue::DateTime(ts, tu, None) if dtype.is_date() => {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-row/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ unsafe fn encode_flat_array(
encode_strs(buffer, array.iter(), opt, offsets);
},

// Lexical ordered Categorical are casted to PrimitiveArray above.
// Lexical ordered Categorical are cast to PrimitiveArray above.
D::Dictionary(_, _, _) => todo!(),

D::FixedSizeBinary(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/_utils/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def __repr__(self) -> str:

def find_stacklevel() -> int:
"""
Find the first place in the stack that is not inside polars.
Find the first place in the stack that is not inside Polars.
Taken from:
https://github.com/pandas-dev/pandas/blob/ab89c53f48df67709a533b6a95ce3d911871a0a8/pandas/util/_exceptions.py#L30-L51
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10356,7 +10356,7 @@ def fold(self, operation: Callable[[Series, Series], Series]) -> Series:
Apply a horizontal reduction on a DataFrame.
This can be used to effectively determine aggregations on a row level, and can
be applied to any DataType that can be supercasted (casted to a similar parent
be applied to any DataType that can be supercast (cast to a similar parent
type).
An example of the supercast rules when applying an arithmetic operation on two
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def is_(self, other: PolarsDataType) -> bool:
Parameters
----------
other
the other polars dtype to compare with.
the other Polars dtype to compare with.
Examples
--------
Expand Down
22 changes: 11 additions & 11 deletions py-polars/polars/expr/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def reinterpret(
self, *, dtype: PolarsDataType, endianness: Endianness = "little"
) -> Expr:
r"""
Interpret a buffer as a numerical polars type.
Interpret a buffer as a numerical Polars type.
Parameters
----------
Expand All @@ -321,19 +321,19 @@ def reinterpret(
--------
>>> df = pl.DataFrame({"data": [b"\x05\x00\x00\x00", b"\x10\x00\x01\x00"]})
>>> df.with_columns( # doctest: +IGNORE_RESULT
... casted=pl.col("data").bin.reinterpret(
... bin2int=pl.col("data").bin.reinterpret(
... dtype=pl.Int32, endianness="little"
... ),
... )
shape: (2, 3)
┌─────────────────────┬────────┐
│ data ┆ caster
│ --- ┆ --- │
│ binary ┆ i32 │
╞═════════════════════╪════════╡
│ b"\x05\x00\x00\x00" ┆ 5 │
│ b"\x10\x00\x01\x00" ┆ 65552 │
└─────────────────────┴────────┘
shape: (2, 2)
┌─────────────────────┬────────
│ data ┆ bin2int
│ --- ┆ ---
│ binary ┆ i32
╞═════════════════════╪════════
│ b"\x05\x00\x00\x00" ┆ 5
│ b"\x10\x00\x01\x00" ┆ 65552
└─────────────────────┴────────
"""
dtype = parse_into_dtype(dtype)

Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/series/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def json_path_match(self, json_path: IntoExprColumn) -> Series:
Extract the first match of json string with provided JSONPath expression.
Throw errors if encounter invalid json strings.
All return value will be casted to String regardless of the original value.
All return value will be cast to String regardless of the original value.
Documentation on JSONPath standard can be found
`here <https://goessner.net/articles/JsonPath/>`_.
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/interchange/test_from_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_from_dataframe_pyarrow_boolean() -> None:
result = pl.from_dataframe(df_pa)
assert_frame_equal(result, df)

with pytest.raises(RuntimeError, match="Boolean column will be casted to uint8"):
with pytest.raises(RuntimeError, match="Boolean column will be cast to uint8"):
pl.from_dataframe(df_pa, allow_copy=False)


Expand Down

0 comments on commit fdbb9f8

Please sign in to comment.