Skip to content

Commit

Permalink
Merge pull request #19 from jmenglund/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jmenglund authored May 27, 2019
2 parents dd64f23 + abac1ce commit 5523c09
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Tracking changes in pandas-validation between versions.
See also https://github.com/jmenglund/pandas-validation/releases.


## 0.4.0 ##

This is a minor release with the following changes:

* Non-NumPy numeric dtypes should now be supported.
* The ValidationWarning is now issued att stack level 2. This makes it possible to
trace the line of code that called the function that raised the warning.

Released: 2019-05-27

[View commits](https://github.com/jmenglund/pandas-validation/compare/v0.3.2...v0.4.0)


## 0.3.2 ##

This is a patch release that fixes an issue with validating numbers with `min_value=0`
Expand Down
30 changes: 16 additions & 14 deletions docs/source/pandas-validation/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ know more, I suggest that you have a look at the :ref:`API reference<api>`.

The code examples below assume that you first do the following imports:

.. code-block:: python
.. code-block:: pycon
import numpy as np
import pandas as pd
import pandasvalidation as pv
>>> import numpy as np
>>> import pandas as pd
>>> import pandasvalidation as pv
.. _validate-dates:
Expand All @@ -36,18 +36,19 @@ user that some values are invalid. If `return_type` is set to ``values``, a
pandas Series will be returned with only the valid datetime values.


.. code-block:: python
.. code-block:: pycon
s1 = pd.Series(
>>> s1 = pd.Series(
['2014', '2014-01-07', '2014-02-28', np.nan],
name='My dates')
pv.validate_datetime(
>>> pv.validate_datetime(
s1,
nullable=False,
unique=True,
min_datetime='2014-01-05',
max_datetime='2014-02-15',
return_type=None)
ValidationWarning: 'My dates': NaT value(s); date(s) too early; date(s) too late.
.. _validate-numbers:
Expand All @@ -60,20 +61,20 @@ Like in the example above, warnings will indicate invalid values to the user.
If `return_type` is set to ``values``, a pandas Series will be returned with
only the valid numeric values.

.. code-block:: python
.. code-block:: pycon
s2 = pd.Series(
>>> s2 = pd.Series(
[1, '1', '2.3', np.nan],
name='My numeric values')
pv.validate_numeric(
>>> pv.validate_numeric(
s2,
nullable=False,
unique=True,
integer=True,
min_value=2,
max_value=2,
return_type=None)
ValidationWarning: 'My numeric values': NaN value(s); duplicates; non-integer(s); value(s) too low; values(s) too high.
.. _validate-strings:

Expand All @@ -86,12 +87,12 @@ warnings then issued if there are invalid values. If `return_type` is
set to ``values``, a pandas Series will be returned with only the valid
strings.

.. code-block:: python
.. code-block:: pycon
s3 = pd.Series(
>>> s3 = pd.Series(
[1, 1, 'ab\n', 'a b', 'Ab', 'AB', np.nan],
name='My strings')
pv.validate_string(
>>> pv.validate_string(
s3,
nullable=False,
unique=True,
Expand All @@ -102,3 +103,4 @@ strings.
trailing_whitespace=False,
whitespace=False,
return_type=None)
ValidationWarning: 'My strings': NaN value(s); duplicates; string(s) too short; string(s) too long; wrong case letter(s); newline character(s); trailing whitespace; whitespace.
18 changes: 9 additions & 9 deletions pandasvalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__author__ = 'Markus Englund'
__license__ = 'MIT'
__version__ = '0.3.2'
__version__ = '0.4.0'


class ValidationWarning(Warning):
Expand Down Expand Up @@ -157,11 +157,11 @@ def to_datetime(
if isinstance(arg, pandas.Series):
warnings.warn(
'{}: value(s) not converted to datetime set as NaT'
.format(repr(arg.name)), ValidationWarning)
.format(repr(arg.name)), ValidationWarning, stacklevel=2)
else: # pragma: no cover
warnings.warn(
'Value(s) not converted to datetime set as NaT',
ValidationWarning)
ValidationWarning, stacklevel=2)
return converted


Expand All @@ -180,11 +180,11 @@ def to_numeric(arg):
if isinstance(arg, pandas.Series):
warnings.warn(
'{}: value(s) not converted to numeric set as NaN'
.format(repr(arg.name)), ValidationWarning)
.format(repr(arg.name)), ValidationWarning, stacklevel=2)
else: # pragma: no cover
warnings.warn(
'Value(s) not converted to numeric set as NaN',
ValidationWarning)
ValidationWarning, stacklevel=2)
return converted


Expand Down Expand Up @@ -261,7 +261,7 @@ def validate_datetime(

if len(msg_list) > 0:
msg = repr(series.name) + ': ' + '; '.join(msg_list) + '.'
warnings.warn(msg, ValidationWarning)
warnings.warn(msg, ValidationWarning, stacklevel=2)

if return_type is not None:
return _get_return_object(masks, converted, return_type)
Expand Down Expand Up @@ -299,7 +299,7 @@ def validate_numeric(
'too_low': 'value(s) too low',
'too_high': 'values(s) too high'}

if not numpy.issubdtype(series.dtype, numpy.number):
if not pandas.api.types.is_numeric_dtype(series.dtype):
converted = pandas.to_numeric(series, errors='coerce')
else:
converted = series.copy()
Expand All @@ -323,7 +323,7 @@ def validate_numeric(

if len(msg_list) > 0:
msg = repr(series.name) + ': ' + '; '.join(msg_list) + '.'
warnings.warn(msg, ValidationWarning)
warnings.warn(msg, ValidationWarning, stacklevel=2)

if return_type is not None:
return _get_return_object(masks, converted, return_type)
Expand Down Expand Up @@ -436,7 +436,7 @@ def validate_string(

if len(msg_list) > 0:
msg = repr(series.name) + ': ' + '; '.join(msg_list) + '.'
warnings.warn(msg, ValidationWarning)
warnings.warn(msg, ValidationWarning, stacklevel=2)

if return_type is not None:
return _get_return_object(masks, converted, return_type)
2 changes: 1 addition & 1 deletion release-checklist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Things to remember when making a new release of pandas-validation.
#. Create pull request(s) with changes for the new release.

#. Create distributions and upload the files to
`PyPI <https://pypi.python.org/pypi>`_ with
`PyPI <https://pypi.org>`_ with
`twine <https://github.com/pypa/twine>`_.

.. code-block:: none
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='pandas-validation',
version='0.3.2',
version='0.4.0',
description=(
'A Python package for validating data with pandas'),
long_description=open(
Expand Down

0 comments on commit 5523c09

Please sign in to comment.