Skip to content

Commit

Permalink
feature/142: drop support for python3.5 (#272)
Browse files Browse the repository at this point in the history
* drop support and ci for python=3.5

* update environment.yml and requirements.txt

* update travis config

* update travis config

* update travis config

* remove autopep8

* fix pylint error, remove io import in __init__

* add test for DataFrameSchema.to_script

* fix to_script tests

* ignore test on windows
  • Loading branch information
cosmicBboy committed Sep 24, 2020
1 parent 038876d commit 91e21a2
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 313 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ os:
- windows

env:
- JOB="3.5" ENV_FILE="ci/deps/env_35.yml"
- JOB="3.6" ENV_FILE="ci/deps/env_36.yml"
- JOB="3.7" ENV_FILE="ci/deps/env_37.yml"
- JOB="3.8" ENV_FILE="ci/deps/env_38.yml"
- JOB="latest" ENV_FILE="ci/deps/env_latest.yml"
- PYTHON_VERSION=3.6
- PYTHON_VERSION=3.7
- PYTHON_VERSION=3.8

before_install:
- |
Expand Down Expand Up @@ -70,7 +68,8 @@ install:
conda info -a || exit 1
# Setup Conda Env
- |
conda env create -n hosts -f $ENV_FILE || exit 1
conda create -n hosts python=$PYTHON_VERSION || exit 1
conda env update -n hosts -f environment.yml
source activate hosts
python setup.py install
Expand Down
34 changes: 0 additions & 34 deletions ci/deps/env_35.yml

This file was deleted.

34 changes: 0 additions & 34 deletions ci/deps/env_36.yml

This file was deleted.

34 changes: 0 additions & 34 deletions ci/deps/env_37.yml

This file was deleted.

34 changes: 0 additions & 34 deletions ci/deps/env_38.yml

This file was deleted.

34 changes: 0 additions & 34 deletions ci/deps/env_latest.yml

This file was deleted.

4 changes: 1 addition & 3 deletions docs/source/schema_inference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ You can also write your schema to a python script with :py:func:`io.to_script`:
.. testcode:: infer_dataframe_schema
:skipif: SKIP

from pandera import io

# supply a file-like object, Path, or str to write to a file. If not
# specified, to_script will output the code as a string.
schema_script = io.to_script(schema)
schema_script = schema.to_script()
print(schema_script)

.. testoutput:: infer_dataframe_schema
Expand Down
9 changes: 3 additions & 6 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: pandera-dev-latest
name: pandera-dev
channels:
- defaults
- conda-forge
dependencies:
# required
- python

# environment management
- pip

Expand All @@ -27,7 +24,7 @@ dependencies:
- asv

# optional
- pre-commit
- pre_commit

# pandera dependencies
- black
Expand All @@ -38,4 +35,4 @@ dependencies:
- pyyaml

- pip:
- sphinx_autodoc_typehints==1.10.3
- sphinx_autodoc_typehints
3 changes: 1 addition & 2 deletions pandera/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""A flexible and expressive pandas validation library."""

from . import errors, constants, io
from . import errors, constants
from .checks import Check
from .hypotheses import Hypothesis
from .decorators import check_input, check_output
Expand All @@ -11,7 +11,6 @@
from .version import __version__


# pylint: disable=invalid-name
Bool = PandasDtype.Bool
DateTime = PandasDtype.DateTime
Category = PandasDtype.Category
Expand Down
3 changes: 1 addition & 2 deletions pandera/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ def statistics(self, statistics):
"""Set check statistics."""
self._statistics = statistics

@staticmethod
def _format_groupby_input(
self,
groupby_obj: GroupbyObject,
groups: Optional[List[str]],
) -> Union[Dict[str, Union[pd.Series, pd.DataFrame]]]:
# pylint: disable=no-self-use
"""Format groupby object into dict of groups to Series or DataFrame.
:param groupby_obj: a pandas groupby object.
Expand Down
2 changes: 1 addition & 1 deletion pandera/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def from_python_type(cls, python_type: type) -> "PandasDtype":
return pandas_dtype

def __eq__(self, other):
# pylint: disable=comparison-with-callable,too-many-return-statements
# pylint: disable=comparison-with-callable
# see https://github.com/PyCQA/pylint/issues/2306
if other is None:
return False
Expand Down
42 changes: 9 additions & 33 deletions pandera/io.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Module for reading and writing schema objects."""

import yaml
from functools import partial
from pathlib import Path

import pandas as pd
import yaml

from .dtypes import PandasDtype
from .schema_statistics import get_dataframe_schema_statistics
Expand Down Expand Up @@ -65,7 +65,7 @@ def _serialize_component_stats(component_stats):

def _serialize_schema(dataframe_schema):
"""Serialize dataframe schema into into json/yaml-compatible format."""
from pandera import __version__ # pylint: disable-all
from pandera import __version__ # pylint: disable=import-outside-toplevel

statistics = get_dataframe_schema_statistics(dataframe_schema)

Expand Down Expand Up @@ -114,8 +114,7 @@ def handle_stat_dtype(stat):


def _deserialize_component_stats(serialized_component_stats):
# pylint: disable-all
from pandera import Check
from pandera import Check # pylint: disable=import-outside-toplevel

pandas_dtype = PandasDtype.from_str_alias(
serialized_component_stats["pandas_dtype"]
Expand All @@ -142,7 +141,7 @@ def _deserialize_component_stats(serialized_component_stats):


def _deserialize_schema(serialized_schema):
# pylint: disable-all
# pylint: disable=import-outside-toplevel
from pandera import DataFrameSchema, Column, Index, MultiIndex

columns, index = None, None
Expand All @@ -168,10 +167,7 @@ def _deserialize_schema(serialized_schema):
])

return DataFrameSchema(
columns={
col_name: column
for col_name, column in columns.items()
},
columns=columns,
index=index,
coerce=serialized_schema["coerce"],
strict=serialized_schema["strict"],
Expand Down Expand Up @@ -290,18 +286,10 @@ def _format_index(index_statistics):


def _format_script(script):
try:
import black
formatter = partial(
black.format_str, mode=black.FileMode(line_length=80)
)
except ImportError:
# use autopep8 for python3.5
import autopep8
formatter = partial(
autopep8.fix_code, options={"aggressive": 1}
)

import black # pylint: disable=import-outside-toplevel
formatter = partial(
black.format_str, mode=black.FileMode(line_length=80)
)
return formatter(script)


Expand Down Expand Up @@ -356,15 +344,3 @@ def to_script(dataframe_schema, path_or_buf=None):

with Path(path_or_buf).open("w") as f:
f.write(formatted_script)

def _write_script(obj, stream):
try:
return yaml.safe_dump(obj, stream=stream, sort_keys=False)
except TypeError:
return yaml.safe_dump(obj, stream=stream)

try:
with Path(path_or_buf).open("w") as f:
_write_script(formatted_script, f)
except (TypeError, OSError):
return _write_script(formatted_script, path_or_buf)
Loading

0 comments on commit 91e21a2

Please sign in to comment.