Skip to content

Commit

Permalink
chore: run ruff (#316)
Browse files Browse the repository at this point in the history
* run ruff

* add init file

* fixup
  • Loading branch information
MarcoGorelli authored Nov 10, 2023
1 parent 4d4654b commit e310573
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 411 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
~\AppData\Local\pip\Cache
key: ${{ runner.os }}-build-${{ matrix.python-version }}
- name: install-reqs
run: python -m pip install --upgrade mypy==1.4.0 typing-extensions
run: python -m pip install --upgrade mypy typing-extensions ruff
- name: run mypy
run: cd spec/API_specification && mypy dataframe_api && mypy examples
- name: run ruff
run: cd spec/API_specification && ruff format dataframe_api examples && ruff dataframe_api examples
94 changes: 58 additions & 36 deletions spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# mypy: disable-error-code="empty-body"
"""
Function stubs and API documentation for the DataFrame API standard.
"""
"""Function stubs and API documentation for the DataFrame API standard."""
from __future__ import annotations

from typing import Dict, Sequence, Any, TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from .column_object import *
from .column_object import Column
from .dataframe_object import DataFrame
from .groupby_object import *
from .dtypes import *
from .dtypes import (
Bool,
Date,
Datetime,
Duration,
Float32,
Float64,
Int8,
Int16,
Int32,
Int64,
String,
UInt8,
UInt16,
UInt32,
UInt64,
)
from .groupby_object import Aggregation, GroupBy

if TYPE_CHECKING:
from collections.abc import Sequence

from .typing import DType, Scalar

__all__ = [
"GroupBy",
"Aggregation",
"Bool",
"Column",
"DataFrame",
"Date",
"Datetime",
"Duration",
Expand All @@ -33,6 +48,8 @@
"UInt32",
"UInt64",
"UInt8",
"Column",
"DataFrame",
"__dataframe_api_version__",
"column_from_1d_array",
"column_from_sequence",
Expand All @@ -53,9 +70,9 @@
implementation of the dataframe API standard.
"""


def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
"""
Concatenate DataFrames vertically.
"""Concatenate DataFrames vertically.
Parameters
----------
Expand All @@ -71,9 +88,14 @@ def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
"""
...

def column_from_sequence(sequence: Sequence[Any], *, dtype: DType, name: str = '') -> Column:
"""
Construct Column from sequence of elements.

def column_from_sequence(
sequence: Sequence[Any],
*,
dtype: DType,
name: str = "",
) -> Column:
"""Construct Column from sequence of elements.
Parameters
----------
Expand All @@ -92,9 +114,9 @@ def column_from_sequence(sequence: Sequence[Any], *, dtype: DType, name: str = '
"""
...


def dataframe_from_columns(*columns: Column) -> DataFrame:
"""
Construct DataFrame from sequence of Columns.
"""Construct DataFrame from sequence of Columns.
Parameters
----------
Expand All @@ -110,9 +132,8 @@ def dataframe_from_columns(*columns: Column) -> DataFrame:
...


def column_from_1d_array(array: Any, *, name: str = '') -> Column:
"""
Construct Column from 1D array.
def column_from_1d_array(array: Any, *, name: str = "") -> Column:
"""Construct Column from 1D array.
See `dataframe_from_2d_array` for related 2D function.
Expand Down Expand Up @@ -148,9 +169,9 @@ def column_from_1d_array(array: Any, *, name: str = '') -> Column:
"""
...

def dataframe_from_2d_array(array: Any, *, schema: Dict[str, DType]) -> DataFrame:
"""
Construct DataFrame from 2D array.

def dataframe_from_2d_array(array: Any, *, schema: dict[str, DType]) -> DataFrame:
"""Construct DataFrame from 2D array.
See `column_from_1d_array` for related 1D function.
Expand All @@ -172,9 +193,9 @@ def dataframe_from_2d_array(array: Any, *, schema: Dict[str, DType]) -> DataFram
"""
...

class null:
"""
A `null` object to represent missing data.

class null: # noqa: N801
"""A `null` object to represent missing data.
``null`` is a scalar, and may be used when constructing a `Column` from a
Python sequence with `column_from_sequence`. It does not support ``is``,
Expand All @@ -198,11 +219,10 @@ class null:
used to check if an object *is* the ``null`` object.
"""
...


def is_null(value: object, /) -> bool:
"""
Check if an object is a `null` scalar.
"""Check if an object is a `null` scalar.
Parameters
----------
Expand All @@ -217,9 +237,9 @@ def is_null(value: object, /) -> bool:
"""
...


def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool:
"""
Returns a boolean indicating whether a provided dtype is of a specified data type “kind”.
"""Indicate whether a provided dtype is of a specified data type "kind".
Parameters
----------
Expand All @@ -233,9 +253,11 @@ def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool:
- 'bool': boolean data type (Bool).
- 'signed integer': signed integer data types (Int8, Int16, Int32, Int64).
- 'unsigned integer': unsigned integer data types (UInt8, UInt16, UInt32, UInt64).
- 'unsigned integer': unsigned integer data types
(UInt8, UInt16, UInt32, UInt64).
- 'floating': floating-point data types (Float32, Float64).
- 'integral': integer data types. Shorthand for ('signed integer', 'unsigned integer').
- 'integral': integer data types. Shorthand for
('signed integer', 'unsigned integer').
- 'numeric': numeric data types. Shorthand for ('integral', 'floating').
If kind is a tuple, the tuple specifies a union of dtypes and/or kinds,
Expand All @@ -249,11 +271,12 @@ def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool:
"""
...


def date(year: int, month: int, day: int) -> Scalar:
"""
Create date object which can be used for filtering.
"""Create date object which can be used for filtering.
The full 32-bit signed integer range of days since epoch should be supported (between -5877641-06-23 and 5881580-07-11 inclusive).
The full 32-bit signed integer range of days since epoch should be supported
(between -5877641-06-23 and 5881580-07-11 inclusive).
Examples
--------
Expand All @@ -265,4 +288,3 @@ def date(year: int, month: int, day: int) -> Scalar:
... )
>>> df.filter(mask)
"""

Loading

0 comments on commit e310573

Please sign in to comment.