Skip to content

Commit 9640f13

Browse files
authored
Merge pull request #21 from Zsailer/minimum-pandas-version
Minimum pandas version; infra; lazy loading
2 parents 4cc6cbc + 4d92a6c commit 9640f13

File tree

14 files changed

+311
-80
lines changed

14 files changed

+311
-80
lines changed

.devcontainer/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#-------------------------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4+
#-------------------------------------------------------------------------------------------------------------
5+
6+
FROM condaforge/mambaforge
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
12+
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
13+
# will be updated to match your local UID/GID (when using the dockerFile property).
14+
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
15+
ARG USERNAME=vscode
16+
ARG USER_UID=1000
17+
ARG USER_GID=$USER_UID
18+
19+
# Copy environment.yml (if found) to a temp locaition so we update the environment. Also
20+
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
21+
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
22+
23+
# Configure apt and install packages
24+
RUN apt-get update \
25+
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
26+
#
27+
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
28+
&& apt-get -y install git openssh-client less iproute2 procps iproute2 lsb-release \
29+
#
30+
# Install pylint
31+
&& /opt/conda/bin/pip install pylint \
32+
#
33+
# Update Python environment based on environment.yml (if present)
34+
&& if [ -f "/tmp/conda-tmp/environment.yml" ]; then /opt/conda/bin/mamba env update -n base -f /tmp/conda-tmp/environment.yml; fi \
35+
&& rm -rf /tmp/conda-tmp \
36+
#
37+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
38+
&& groupadd --gid $USER_GID $USERNAME \
39+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
40+
# [Optional] Add sudo support for the non-root user
41+
&& apt-get install -y sudo \
42+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
43+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
44+
# [Additional Customization]
45+
&& apt-get install -y nano vim emacs \
46+
# Clean up
47+
&& apt-get autoremove -y \
48+
&& apt-get clean -y \
49+
&& rm -rf /var/lib/apt/lists/*
50+
51+
# Switch back to dialog for any ad-hoc use of apt-get
52+
ENV DEBIAN_FRONTEND=dialog

.devcontainer/devcontainer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.1/containers/python-3-miniconda
3+
{
4+
"name": "pandas-flavor dev container",
5+
// "context": "..",
6+
// "image": "registry.hub.docker.com/ericmjl/pyjanitor:devcontainer",
7+
"build": {
8+
"dockerfile": "Dockerfile",
9+
"context": ".."
10+
},
11+
// Set *default* container specific settings.json values on container create.
12+
"settings": {
13+
"terminal.integrated.defaultProfile.linux": "bash",
14+
"python.defaultInterpreterPath": "/opt/conda/bin/python",
15+
"python.linting.enabled": true,
16+
"python.linting.pylintEnabled": true,
17+
"python.linting.pylintPath": "/opt/conda/bin/pylint",
18+
"python.formatting.provider": "black",
19+
"python.formatting.blackArgs": [
20+
"--config",
21+
"pyproject.toml",
22+
],
23+
"editor.formatOnSave": true,
24+
"files.insertFinalNewline": true,
25+
"files.trimFinalNewlines": true,
26+
"files.trimTrailingWhitespace": true,
27+
"[python]": {
28+
"editor.formatOnSaveMode": "file",
29+
},
30+
},
31+
// Add the IDs of extensions you want installed when the container is created.
32+
"extensions": [
33+
"ms-python.python",
34+
"ms-python.vscode-pylance",
35+
"ms-vsliveshare.vsliveshare-pack",
36+
"arcticicestudio.nord-visual-studio-code"
37+
],
38+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
39+
"forwardPorts": [
40+
8000
41+
],
42+
// Use 'postCreateCommand' to run commands after the container is created.
43+
"postCreateCommand": "pre-commit install --install-hooks && python setup.py develop"
44+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
45+
// "remoteUser": "vscode"
46+
}

.devcontainer/noop.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is copied into the container along with environment.yml* from the
2+
parent folder. This is done to prevent the Dockerfile COPY instruction from
3+
failing if no environment.yml is found.

.github/workflows/tests.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: pandas-flavor tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
run-tests:
7+
runs-on: ubuntu-latest
8+
name: Run pandas-flavor test suite
9+
10+
# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
11+
defaults:
12+
run:
13+
shell: bash -l {0}
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
18+
19+
# See: https://github.com/marketplace/actions/setup-miniconda
20+
- name: Setup miniconda
21+
uses: conda-incubator/setup-miniconda@v2
22+
with:
23+
auto-update-conda: true
24+
miniforge-variant: Mambaforge
25+
channels: conda-forge
26+
activate-environment: pandas-flavor
27+
environment-file: environment.yml
28+
use-mamba: true
29+
30+
- name: Run unit tests
31+
run: |
32+
conda activate pandas-flavor
33+
python -m pip install -e .
34+
pytest
35+
36+
# # https://github.com/codecov/codecov-action
37+
# - name: Upload code coverage
38+
# uses: codecov/codecov-action@v2
39+
# with:
40+
# # fail_ci_if_error: true # optional (default = false)
41+
# verbose: true # optional (default = false)

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.2.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- repo: https://github.com/psf/black
12+
rev: 22.3.0
13+
hooks:
14+
- id: black
15+
args: [--config, pyproject.toml]
16+
- repo: https://github.com/econchick/interrogate
17+
rev: 1.5.0
18+
hooks:
19+
- id: interrogate
20+
args: [-c, pyproject.toml]
21+
- repo: https://github.com/terrencepreilly/darglint
22+
rev: v1.8.1
23+
hooks:
24+
- id: darglint
25+
args: [-v 2] # this config makes the error messages a bit less cryptic.
26+
- repo: https://github.com/PyCQA/flake8
27+
rev: 4.0.1
28+
hooks:
29+
- id: flake8
30+
args: [--exclude, nbconvert_config.py]

environment.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: pandas-flavor
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python=3.9
6+
- pandas>=0.23
7+
- xarray
8+
- pip
9+
- pre-commit
10+
- pytest
11+
- black
12+
- pip:
13+
- lazy-loader
14+
- tuna

pandas_flavor/__init__.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1-
from .register import (register_series_method,
2-
register_series_accessor,
3-
register_dataframe_method,
4-
register_dataframe_accessor)
5-
from .xarray import (register_xarray_dataarray_method,
6-
register_xarray_dataset_method)
1+
"""Top-level API for pandas-flavor."""
2+
import lazy_loader as lazy
73

4+
__getattr__, __dir__, __all__ = lazy.attach(
5+
__name__,
6+
submod_attrs={
7+
"register": [
8+
"register_series_method",
9+
"register_series_accessor",
10+
"register_dataframe_method",
11+
"register_dataframe_accessor",
12+
],
13+
"xarray": [
14+
"register_xarray_dataarray_method",
15+
"register_xarray_dataset_method",
16+
],
17+
},
18+
)
19+
# from .register import (
20+
# register_series_method,
21+
# register_series_accessor,
22+
# register_dataframe_method,
23+
# register_dataframe_accessor,
24+
# )
25+
# from .xarray import (
26+
# register_xarray_dataarray_method,
27+
# register_xarray_dataset_method,
28+
# )
29+
30+
# __all__ = [
31+
# "register_series_method",
32+
# "register_series_accessor",
33+
# "register_dataframe_method",
34+
# "register_dataframe_accessor",
35+
# "register_xarray_dataarray_method",
36+
# "register_xarray_dataset_method",
37+
# ]

pandas_flavor/__version__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__version__ = '0.2.0'
1+
"""Version number."""
2+
__version__ = "0.2.0"

pandas_flavor/pandas_internals.py

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

pandas_flavor/register.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from functools import wraps
2-
from .pandas_internals import (register_series_accessor,
3-
register_dataframe_accessor)
2+
from pandas.api.extensions import register_series_accessor, register_dataframe_accessor
43

54

65
def register_dataframe_method(method):
@@ -16,11 +15,9 @@ def print_column(df, col):
1615
'''Print the dataframe column given'''
1716
print(df[col])
1817
"""
19-
def inner(*args, **kwargs):
2018

19+
def inner(*args, **kwargs):
2120
class AccessorMethod(object):
22-
23-
2421
def __init__(self, pandas_obj):
2522
self._obj = pandas_obj
2623

@@ -36,10 +33,9 @@ def __call__(self, *args, **kwargs):
3633

3734

3835
def register_series_method(method):
39-
"""Register a function as a method attached to the Pandas Series.
40-
"""
41-
def inner(*args, **kwargs):
36+
"""Register a function as a method attached to the Pandas Series."""
4237

38+
def inner(*args, **kwargs):
4339
class AccessorMethod(object):
4440
__doc__ = method.__doc__
4541

0 commit comments

Comments
 (0)