Skip to content

Commit

Permalink
Add black to pre-commit and requirements.
Browse files Browse the repository at this point in the history
Follow on PR to reformat existing files
  • Loading branch information
caneff committed Oct 19, 2023
1 parent 293a0ab commit 316c43f
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 132 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Lint with black
run: black --check .
- name: Lint with flake8
run: |
flake8
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ repos:
entry: mypy
language: system
types: [python]
- id: black
name: black
description: "Black: The uncompromising Python code formatter"
entry: black
language: system
require_serial: true
files: \.(py|ipynb)$
- id: pytest
name: pytest
entry: coverage run -m pytest --typeguard-packages=strictly_typed_pandas,tests
Expand Down
36 changes: 23 additions & 13 deletions docs/source/advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"%autoreload 2\n",
"\n",
"import sys\n",
"\n",
"sys.path.append(\"../\")"
]
},
Expand All @@ -37,19 +38,22 @@
"source": [
"from strictly_typed_pandas import DataSet\n",
"\n",
"\n",
"class SchemaA:\n",
" name: str\n",
"\n",
"\n",
"class SchemaB(SchemaA):\n",
" id: int\n",
"\n",
"\n",
"df = DataSet[SchemaA]({\"name\": [\"John\", \"Jane\", \"Jack\"]})\n",
"\n",
"\n",
"def foo(df: DataSet[SchemaA]) -> DataSet[SchemaB]:\n",
" return (\n",
" df.assign(id=lambda df: range(df.shape[0]))\n",
" .pipe(DataSet[SchemaB])\n",
" )"
" return df.assign(\n",
" id=lambda df: range(df.shape[0]),\n",
" ).pipe(DataSet[SchemaB])"
]
},
{
Expand All @@ -69,19 +73,19 @@
" id: int\n",
" name: str\n",
"\n",
"\n",
"class SchemaB:\n",
" id: int\n",
" job: str\n",
"\n",
"\n",
"class SchemaAB(SchemaA, SchemaB):\n",
" pass\n",
"\n",
"\n",
"df1 = DataSet[SchemaA]({\"id\": [1, 2, 3], \"name\": [\"John\", \"Jane\", \"Jack\"]})\n",
"df2 = DataSet[SchemaB]({\"id\": [1, 2, 3], \"job\": \"Data Scientist\"})\n",
"(\n",
" df1.merge(df2, on=\"id\")\n",
" .pipe(DataSet[SchemaAB])\n",
")"
"df1.merge(df2, on=\"id\").pipe(DataSet[SchemaAB])"
]
},
{
Expand All @@ -102,6 +106,7 @@
" id: int\n",
" name: str\n",
"\n",
"\n",
"DataSet[Schema]()"
]
},
Expand All @@ -123,18 +128,20 @@
"import pandas as pd\n",
"from typing import Any\n",
"\n",
"\n",
"class Schema:\n",
" name: pd.StringDtype\n",
" money: np.float64\n",
" eggs: np.int64\n",
" potatoes: Any\n",
"\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"name\": pd.Series([\"John\", \"Jane\", \"Jack\"], dtype=\"string\"),\n",
" \"money\": pd.Series([100.50, 1000.23, 123.45], dtype=np.float64),\n",
" \"eggs\": pd.Series([1, 2, 3], dtype=np.int64),\n",
" \"potatoes\": [\"1\", 0, np.nan]\n",
" \"potatoes\": [\"1\", 0, np.nan],\n",
" }\n",
")\n",
"\n",
Expand All @@ -158,13 +165,16 @@
"source": [
"from strictly_typed_pandas import IndexedDataSet\n",
"\n",
"\n",
"class IndexSchema:\n",
" id: int\n",
" job: str\n",
"\n",
"\n",
"class DataSchema:\n",
" name: str\n",
"\n",
"\n",
"df = (\n",
" pd.DataFrame({\"id\": [1, 2, 3], \"name\": [\"John\", \"Jane\", \"Jack\"], \"job\": \"Data Scientist\"})\n",
" .set_index([\"id\", \"job\"])\n",
Expand All @@ -189,14 +199,14 @@
"class SchemaA:\n",
" name: str\n",
"\n",
"\n",
"class SchemaB(SchemaA):\n",
" id: int\n",
"\n",
"\n",
"def foo(df: DataSet[SchemaA]) -> DataSet[SchemaB]:\n",
" return (\n",
" df.assign(id=1)\n",
" .pipe(DataSet[SchemaB])\n",
" )\n",
" return df.assign(id=1).pipe(DataSet[SchemaB])\n",
"\n",
"\n",
"df = DataSet[SchemaA]({\"name\": [\"John\", \"Jane\", \"Jack\"]})\n",
"df = foo(df)\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

# -- Project information -----------------------------------------------------

project = 'Strictly Typed Pandas'
copyright = '2021, Nanne Aben'
author = 'Nanne Aben'
project = "Strictly Typed Pandas"
copyright = "2021, Nanne Aben"
author = "Nanne Aben"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx_rtd_theme', 'nbsphinx']
extensions = ["sphinx.ext.autodoc", "sphinx_rtd_theme", "nbsphinx"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -45,9 +45,9 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
47 changes: 21 additions & 26 deletions docs/source/deepdive_into_dtypes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"%autoreload 2\n",
"\n",
"import sys\n",
"\n",
"sys.path.append(\"../\")\n",
"\n",
"import pandas as pd\n",
Expand Down Expand Up @@ -45,7 +46,7 @@
" {\n",
" \"a\": pd.Series([1, 2, 3], dtype=int),\n",
" \"b\": pd.Series([1.0, 2.0, 3.0], dtype=float),\n",
" \"c\": pd.Series([True, False, True], dtype=bool)\n",
" \"c\": pd.Series([True, False, True], dtype=bool),\n",
" }\n",
")\n",
"\n",
Expand Down Expand Up @@ -106,6 +107,7 @@
" b: float\n",
" c: bool\n",
"\n",
"\n",
"df = DataSet[Schema]()\n",
"df.dtypes"
]
Expand All @@ -121,6 +123,7 @@
" b: np.float64\n",
" c: np.bool_\n",
"\n",
"\n",
"df = DataSet[Schema]()\n",
"df.dtypes"
]
Expand All @@ -142,11 +145,9 @@
" a: np.integer\n",
" b: np.float_\n",
"\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"a\": pd.Series([1, 2, 3], dtype=np.int64),\n",
" \"b\": pd.Series([1.0, 2.0, 3.0], dtype=np.float64)\n",
" }\n",
" {\"a\": pd.Series([1, 2, 3], dtype=np.int64), \"b\": pd.Series([1.0, 2.0, 3.0], dtype=np.float64)}\n",
")\n",
"df.dtypes"
]
Expand All @@ -169,6 +170,7 @@
" a: np.datetime64\n",
" b: np.timedelta64\n",
"\n",
"\n",
"df = DataSet[Schema]()\n",
"df.dtypes"
]
Expand Down Expand Up @@ -202,6 +204,7 @@
" f: pd.Int64Dtype\n",
" h: pd.BooleanDtype\n",
"\n",
"\n",
"df = DataSet[Schema]()\n",
"df.dtypes"
]
Expand All @@ -224,14 +227,13 @@
"class SchemaA:\n",
" a: pd.Int64Dtype\n",
"\n",
"\n",
"class SchemaB:\n",
" a: np.int64\n",
"\n",
"\n",
"try:\n",
" (\n",
" DataSet[SchemaA]()\n",
" .pipe(DataSet[SchemaB])\n",
" )\n",
" (DataSet[SchemaA]().pipe(DataSet[SchemaB]))\n",
"except TypeError as e:\n",
" print(e)"
]
Expand All @@ -254,10 +256,11 @@
" a: str\n",
" b: pd.StringDtype\n",
"\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"a\": pd.Series([\"a\", \"b\", \"c\"], dtype=\"string\"),\n",
" \"b\": pd.Series([\"a\", \"b\", \"c\"], dtype=\"string\")\n",
" \"b\": pd.Series([\"a\", \"b\", \"c\"], dtype=\"string\"),\n",
" }\n",
")\n",
"df.dtypes"
Expand Down Expand Up @@ -296,6 +299,7 @@
"class Schema:\n",
" a: str\n",
"\n",
"\n",
"df = DataSet[Schema]({\"a\": [\"a\", \"b\", \"c\"]})\n",
"df.dtypes"
]
Expand All @@ -316,11 +320,8 @@
"class Schema:\n",
" a: str\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"a\": [None, 42, lambda x: x]\n",
" }\n",
")\n",
"\n",
"df = DataSet[Schema]({\"a\": [None, 42, lambda x: x]})\n",
"df.dtypes"
]
},
Expand All @@ -340,11 +341,8 @@
"class Schema:\n",
" a: pd.StringDtype\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"a\": pd.Series([\"a\", \"b\", \"c\"], dtype=\"string\")\n",
" }\n",
")"
"\n",
"df = DataSet[Schema]({\"a\": pd.Series([\"a\", \"b\", \"c\"], dtype=\"string\")})"
]
},
{
Expand All @@ -354,11 +352,7 @@
"outputs": [],
"source": [
"try:\n",
" DataSet[Schema](\n",
" {\n",
" \"a\": [None, 42, lambda x: x]\n",
" }\n",
" )\n",
" DataSet[Schema]({\"a\": [None, 42, lambda x: x]})\n",
"except TypeError as e:\n",
" print(e)"
]
Expand All @@ -382,10 +376,11 @@
" a: Any\n",
" b: Any\n",
"\n",
"\n",
"df = DataSet[Schema](\n",
" {\n",
" \"a\": [1, 2, 3],\n",
" \"b\": [\"1\", 2, None]\n",
" \"b\": [\"1\", 2, None],\n",
" }\n",
")\n",
"df.dtypes"
Expand Down
Loading

0 comments on commit 316c43f

Please sign in to comment.