Skip to content

Commit 34a415a

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into ci/testing-env
2 parents 9330f43 + 5ebf799 commit 34a415a

File tree

15 files changed

+183
-120
lines changed

15 files changed

+183
-120
lines changed

.github/workflows/docs-preview.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/docs.yml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
name: Build documentation
1+
name: documentation
22

33
on:
44
push:
55
branches:
66
- dev
7+
pull_request:
8+
branches:
9+
- dev
710

811
jobs:
9-
build-docs:
12+
build:
1013
runs-on: ubuntu-latest
11-
name: Build documentation
1214

1315
# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
1416
defaults:
@@ -25,19 +27,43 @@ jobs:
2527
with:
2628
auto-update-conda: true
2729
miniforge-variant: Mambaforge
28-
channels: conda-forge
29-
activate-environment: pyjanitor-dev
3030
environment-file: environment-dev.yml
3131
use-mamba: true
3232

33+
- name: Install pyjanitor
34+
# use editable mode to avoid _pytest.pathlib.ImportPathMismatchError
35+
run: pip install -e .
36+
3337
- name: Build docs
34-
run: |
35-
conda activate pyjanitor-dev
36-
python -m ipykernel install --user --name pyjanitor-dev
37-
pip install -e .
38-
mkdocs build
38+
run: mkdocs build
39+
40+
- uses: actions/upload-artifact@v3
41+
with:
42+
name: website
43+
path: site/
44+
45+
- name: Test docs
46+
run: pytest -m "documentation"
47+
48+
- name: Docs preview
49+
if: ${{ github.event_name == 'pull_request' }}
50+
uses: nwtgck/[email protected]
51+
with:
52+
publish-dir: "./site"
53+
production-deploy: false
54+
github-token: ${{ secrets.GHPAGES_TOKEN }}
55+
deploy-message: "Deploy from GitHub Actions"
56+
enable-pull-request-comment: true
57+
enable-commit-comment: false
58+
overwrites-pull-request-comment: true
59+
alias: deploy-preview-${{ github.event.number }}
60+
env:
61+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
62+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
63+
timeout-minutes: 1
3964

4065
- name: Deploy website
66+
if: ${{ github.event_name == 'push' }}
4167
uses: peaceiris/actions-gh-pages@v3
4268
with:
4369
# https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-set-personal-access-token-personal_token

.requirements/base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ natsort
66
pandas_flavor
77
multipledispatch
88
scipy
9+
lazy_loader

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,4 @@ Contributors
109109
- [@ethompsy](https://github.com/ethompsy) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Aethompsy)
110110
- [@apatao](https://github.com/apatao) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues?q=is%3Aclosed+mentions%3Aapatao)
111111
- [@OdinTech3](https://github.com/OdinTech3) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/pull/1094)
112+
- [@asmirnov69](https://github.com/asmirnov69) | [contributions](https://github.com/pyjanitor-devs/pyjanitor/issues/1059)

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- [ENH] Add lazy imports to speed up the time taken to load pyjanitor (part 2)
56
- [DOC] Updated developer guide docs.
67
- [ENH] Allow column selection/renaming within conditional_join. Issue #1102. Also allow first or last match. Issue #1020 @samukweku.
78
- [ENH] New decorator `deprecated_kwargs` for breaking API. #1103 @Zeroto521
@@ -29,6 +30,7 @@
2930
- [ENH] Add explicit default parameter to `case_when` function. Issue #1159 @samukweku
3031
- [BUG] pandas 1.5.x `_MergeOperation` doesn't have `copy` keyword anymore. Issue #1174 @Zeroto521
3132
- [TST] Compat with macos and window, to fix `FailedHealthCheck` Issue #1181 @Zeroto521
33+
- [INF] Merge two docs CIs (`docs-preview.yml` and `docs.yml`) to one. And add `documentation` pytest mark. PR #1183 @Zeroto521
3234

3335
## [v0.23.1] - 2022-05-03
3436

environment-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ dependencies:
5555
- xorg-libxrender
5656
- pip:
5757
- mknotebooks
58+
- lazy-loader

janitor/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
"""Top-level janitor API lives here."""
2-
try:
3-
import janitor.xarray # noqa: F401
4-
except ImportError:
5-
pass
1+
"""Top-level janitor API lives here.
2+
3+
Lazy loading used here to speed up imports.
4+
"""
5+
import lazy_loader as lazy
66

7+
8+
from .accessors import * # noqa: F403, F401
79
from .functions import * # noqa: F403, F401
810
from .io import * # noqa: F403, F401
911
from .math import * # noqa: F403, F401
1012
from .ml import get_features_targets as _get_features_targets
1113
from .utils import refactored_function
12-
from .accessors import * # noqa: F403, F401
14+
15+
16+
_ = lazy.load("pandas_flavor")
17+
18+
try:
19+
jxr = lazy.load("janitor.xarray") # noqa: F401
20+
except ImportError:
21+
pass
1322

1423

1524
@refactored_function(

janitor/accessors/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
"""Top-level imports for pyjanitor's dataframe accessors."""
2-
from .data_description import DataDescription
1+
"""Miscellaneous mathematical operators.
2+
3+
Lazy loading used here to speed up imports.
4+
"""
5+
6+
import warnings
7+
from typing import Tuple
8+
9+
10+
import lazy_loader as lazy
11+
12+
scipy_special = lazy.load("scipy.special")
13+
ss = lazy.load("scipy.stats")
14+
pf = lazy.load("pandas_flavor")
15+
pd = lazy.load("pandas")
16+
np = lazy.load("numpy")
17+
pdtypes = lazy.load("pandas.api.types")

janitor/accessors/data_description.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import lazy_loader as lazy
12
from typing import Dict, List, Union
2-
import pandas_flavor as pf
3-
import pandas as pd
3+
4+
pf = lazy.load("pandas_flavor")
5+
pd = lazy.load("pandas")
46

57

68
@pf.register_dataframe_accessor("data_description")

janitor/functions/impute.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""Implementation of `impute` function"""
22
from typing import Any, Hashable, Optional
33

4+
import lazy_loader as lazy
45
import numpy as np
56
import pandas_flavor as pf
67
import pandas as pd
7-
from scipy.stats import mode
88

99
from janitor.utils import deprecated_alias
1010

11+
ss = lazy.load("scipy.stats")
12+
1113

1214
@pf.register_dataframe_method
1315
@deprecated_alias(column="column_name")
@@ -100,7 +102,7 @@ def impute(
100102
"mean": np.mean,
101103
"average": np.mean, # aliased
102104
"median": np.median,
103-
"mode": mode,
105+
"mode": ss.mode,
104106
"minimum": np.min,
105107
"min": np.min, # aliased
106108
"maximum": np.max,

0 commit comments

Comments
 (0)