{ "info": { "author": "V\u00edctor Zabalza", "author_email": "vzabalza@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# marshmallow-numerical\n\n[![Build Status](https://travis-ci.org/zblz/marshmallow-numerical.svg?branch=master)](https://travis-ci.org/zblz/marshmallow-numerical)\n[![PyPI](https://img.shields.io/pypi/v/marshmallow-numerical.svg)](https://pypi.org/project/marshmallow-numerical/)\n[![License](https://img.shields.io/github/license/zblz/marshmallow-numerical.svg)](https://github.com/zblz/marshmallow-numerical/blob/master/LICENSE)\n\n`marshmallow-numerical` is a library that helps you generate\n[marshmallow](https://marshmallow.readthedocs.io/) Schemas for Pandas and Numpy\ndata structures.\n\n# Usage\n\nLet's start by creating an example dataframe for which we want to create a\n`Schema`. This dataframe has four columns: two of them are of string type, one\nis a float, and the last one is an integer.\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom marshmallow_numerical import SplitDataFrameSchema\n\nanimal_df = pd.DataFrame(\n [\n (\"falcon\", \"bird\", 389.0, 2),\n (\"parrot\", \"bird\", 24.0, 2),\n (\"lion\", \"mammal\", 80.5, 4),\n (\"monkey\", \"mammal\", np.nan, 4),\n ],\n columns=[\"name\", \"class\", \"max_speed\", \"num_legs\"],\n)\n```\n\nYou can then create a marshmallow schema that will validate and load dataframes\nthat follow the same structure as the one above and that have been serialized\nwith `DataFrame.to_json` with the [`orient=split`\nformat](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_json.html#pandas.DataFrame.to_json):\n\n```python\nclass AnimalSchema(SplitDataFrameSchema):\n \"\"\"Automatically generated schema for animal dataframe\"\"\"\n\n dtypes = animal_df.dtypes\n```\n\nWhen passing a valid payload for a new animal, this schema will validate it and\nbuild a dataframe:\n\n```python\nanimal_schema = AnimalSchema()\n\nnew_animal = {\n \"data\": [(\"leopard\", \"mammal\", 58.0, 4), (\"ant\", \"insect\", 0.288, 6)],\n \"columns\": [\"name\", \"class\", \"max_speed\", \"num_legs\"],\n \"index\": [0, 1],\n}\n\nnew_animal_df = animal_schema.load(new_animal)\n\nprint(type(new_animal_df))\n# \nprint(new_animal_df)\n# name class max_speed num_legs\n# 0 leopard mammal 58.000 4\n# 1 ant insect 0.288 6\n```\n\nHowever, if we pass a payload that doesn't conform to the schema, it will raise\na marshmallow `ValidationError` exception with informative message about errors:\n\n```python\ninvalid_animal = {\n \"data\": [(\"leopard\", \"mammal\", 58.0, \"four\")], # num_legs is not an int\n \"columns\": [\"name\", \"class\", \"num_legs\"], # missing max_speed column\n \"index\": [0],\n}\n\nanimal_schema.load(invalid_animal)\n\n# Raises:\n# marshmallow.exceptions.ValidationError: {'columns': [\"Must be equal to ['name', 'class', 'max_speed', 'num_legs'].\"], 'data': {0: {3: ['Not a valid integer.']}}}\n```\n\n`marshmallow_numerical` can also generate Schemas for the `orient=records`\nformat by following the above steps but using\n`marshmallow_numerical.RecordsDataFrameSchema` as the superclass for\n`AnimalSchema`.\n\n# Installation\n\nmarshmallow-numerical requires Python >= 3.6 and marshmallow >= 3.0. You can\ninstall it with pip:\n\n```\npip install marshmallow-numerical\n```\n\n# Contributing\n\nContributions are welcome!\n\nYou can report a problem or feature request in the [issue\ntracker](https://github.com/zblz/marshmallow-numerical/issues). If you feel that\nyou can fix it or implement it, please submit a pull request referencing the\nissues it solves.\n\nUnit tests written using the [`pytest`](https://pytest.org) framework are in the\n`tests` directory, and are run using\n[tox](https://tox.readthedocs.io/en/latest/) on Python 3.6 and 3.7. You can run\nthe tests by installing tox:\n```\npip install tox\n```\nand running the linters and tests for all Python versions by running `tox`, or\nfor a specific Python version by running:\n```\ntox -e py36\n```\n\nWe format the code with [black](https://github.com/python/black), and you can\nformat your checkout of the code before commiting it by running:\n```\ntox -e black -- .\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/zblz/marshmallow-numerical", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "marshmallow-numerical", "package_url": "https://pypi.org/project/marshmallow-numerical/", "platform": "", "project_url": "https://pypi.org/project/marshmallow-numerical/", "project_urls": { "Homepage": "https://github.com/zblz/marshmallow-numerical" }, "release_url": "https://pypi.org/project/marshmallow-numerical/0.0.2/", "requires_dist": [ "marshmallow[reco] (==3.0.0rc4)", "pandas", "numpy" ], "requires_python": ">=3.6", "summary": "Marshmallow Schema generator for pandas and numpy", "version": "0.0.2" }, "last_serial": 5237756, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "47a124a4229a78d21bea3b32bf826ee3", "sha256": "47cfa0e11134aa994b9915783c67f49015f603146efcf4378c2dafad44922a05" }, "downloads": -1, "filename": "marshmallow_numerical-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "47a124a4229a78d21bea3b32bf826ee3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 4190, "upload_time": "2019-03-18T09:29:15", "url": "https://files.pythonhosted.org/packages/d4/3c/1d07e04895e862beef332065d4bc545c7f963e2abdd1fbcb3f3307836a65/marshmallow_numerical-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7be025121f9264ea880a5bb794745d61", "sha256": "62a55e271e194c8021e24fc7378a0788307cd0c896c396ef1131405c042c188d" }, "downloads": -1, "filename": "marshmallow-numerical-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7be025121f9264ea880a5bb794745d61", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 6391, "upload_time": "2019-03-18T09:29:16", "url": "https://files.pythonhosted.org/packages/32/ca/c792681acabb5103b8b3e02ddecf601aa1b41c85f1da6d4e902716f2c39a/marshmallow-numerical-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "83de9bb12a02443f3d2e0844f36ef2e6", "sha256": "c2cad836752d8f0e95c902499628a57c82407d6e38778d49eaa87077c38ec38b" }, "downloads": -1, "filename": "marshmallow_numerical-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "83de9bb12a02443f3d2e0844f36ef2e6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5835, "upload_time": "2019-05-07T11:19:17", "url": "https://files.pythonhosted.org/packages/4b/15/6e2012a856cc21f1970d905cb19f4dd3dc6c7a80b2caa714e4c705908159/marshmallow_numerical-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "42c6a175304cec5fd8c678dcc3a60b42", "sha256": "df64edb5ca342c769bbd1e98350cd6b16dcc07ea37e0d9609a0b2808f2694f2d" }, "downloads": -1, "filename": "marshmallow-numerical-0.0.2.tar.gz", "has_sig": false, "md5_digest": "42c6a175304cec5fd8c678dcc3a60b42", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8670, "upload_time": "2019-05-07T11:19:19", "url": "https://files.pythonhosted.org/packages/10/88/3527264d9d6e9ff122dab809c89d386c92a2df4345182992a4183a01bbe0/marshmallow-numerical-0.0.2.tar.gz" } ], "0.0.post3": [ { "comment_text": "", "digests": { "md5": "c22910df8db3a8d73f7ad0f73bfd4d29", "sha256": "6582e42295c8dd9d8620b3189f7a949435f8e70d84fdf24e0cd6bb1255643df5" }, "downloads": -1, "filename": "marshmallow-numerical-0.0.post3.tar.gz", "has_sig": false, "md5_digest": "c22910df8db3a8d73f7ad0f73bfd4d29", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 2398, "upload_time": "2019-02-08T11:50:46", "url": "https://files.pythonhosted.org/packages/46/19/7cd2cc1637045a0ab7ec12cefd6368860898b621c5946c1abb13d5c5b796/marshmallow-numerical-0.0.post3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "83de9bb12a02443f3d2e0844f36ef2e6", "sha256": "c2cad836752d8f0e95c902499628a57c82407d6e38778d49eaa87077c38ec38b" }, "downloads": -1, "filename": "marshmallow_numerical-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "83de9bb12a02443f3d2e0844f36ef2e6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5835, "upload_time": "2019-05-07T11:19:17", "url": "https://files.pythonhosted.org/packages/4b/15/6e2012a856cc21f1970d905cb19f4dd3dc6c7a80b2caa714e4c705908159/marshmallow_numerical-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "42c6a175304cec5fd8c678dcc3a60b42", "sha256": "df64edb5ca342c769bbd1e98350cd6b16dcc07ea37e0d9609a0b2808f2694f2d" }, "downloads": -1, "filename": "marshmallow-numerical-0.0.2.tar.gz", "has_sig": false, "md5_digest": "42c6a175304cec5fd8c678dcc3a60b42", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8670, "upload_time": "2019-05-07T11:19:19", "url": "https://files.pythonhosted.org/packages/10/88/3527264d9d6e9ff122dab809c89d386c92a2df4345182992a4183a01bbe0/marshmallow-numerical-0.0.2.tar.gz" } ] }