{ "info": { "author": "Faculty", "author_email": "opensource@faculty.ai", "bugtrack_url": null, "classifiers": [], "description": "# marshmallow-dataframe\n\n[![Build Status](https://travis-ci.org/facultyai/marshmallow-dataframe.svg?branch=master)](https://travis-ci.org/facultyai/marshmallow-dataframe)\n[![PyPI](https://img.shields.io/pypi/v/marshmallow-dataframe.svg)](https://pypi.org/project/marshmallow-dataframe/)\n[![License](https://img.shields.io/github/license/facultyai/marshmallow-dataframe.svg)](https://github.com/facultyai/marshmallow-dataframe/blob/master/LICENSE)\n\n`marshmallow-dataframe` is a library that helps you generate\n[marshmallow](https://marshmallow.readthedocs.io/) Schemas for Pandas\nDataFrames.\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_dataframe 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).\nThe `dtypes` attribute of the `Meta` class is required, and other [`marshmallow`\nSchema\noptions](https://marshmallow.readthedocs.io/en/latest/api_reference.html#marshmallow.Schema.Meta)\ncan also be passed as attributes of `Meta`:\n\n```python\nclass AnimalSchema(SplitDataFrameSchema):\n \"\"\"Automatically generated schema for animal dataframe\"\"\"\n\n class Meta:\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: {\n# 'columns': [\"Must be equal to ['name', 'class', 'max_speed', 'num_legs'].\"],\n# 'data': {0: {3: ['Not a valid integer.']}}\n# }\n```\n\n`marshmallow_dataframe` can also generate Schemas for the `orient=records`\nformat by following the above steps but using\n`marshmallow_dataframe.RecordsDataFrameSchema` as the superclass for\n`AnimalSchema`.\n\n# Installation\n\nmarshmallow-dataframe requires Python >= 3.6 and marshmallow >= 3.0. You can\ninstall it with pip:\n\n```\npip install marshmallow-dataframe\n```\n\n# Contributing\n\nContributions are welcome!\n\nYou can report a problem or feature request in the [issue\ntracker](https://github.com/facultyai/marshmallow-dataframe/issues). If you feel\nthat you can fix it or implement it, please submit a pull request referencing\nthe issues 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/facultyai/marshmallow-dataframe", "keywords": "", "license": "Apache Software License", "maintainer": "", "maintainer_email": "", "name": "marshmallow-dataframe", "package_url": "https://pypi.org/project/marshmallow-dataframe/", "platform": "", "project_url": "https://pypi.org/project/marshmallow-dataframe/", "project_urls": { "Homepage": "https://github.com/facultyai/marshmallow-dataframe" }, "release_url": "https://pypi.org/project/marshmallow-dataframe/0.1.4/", "requires_dist": [ "marshmallow (>=3.0.1)", "pandas", "numpy" ], "requires_python": ">=3.6", "summary": "Marshmallow Schema generator for pandas dataframes", "version": "0.1.4" }, "last_serial": 5760793, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "b3420bc0d92f85d9449685db045e400c", "sha256": "3348372d4849df89123c96b141412b6978f0862f435d598c6f67b9503dec8ac0" }, "downloads": -1, "filename": "marshmallow_dataframe-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "b3420bc0d92f85d9449685db045e400c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 8760, "upload_time": "2019-05-10T11:26:26", "url": "https://files.pythonhosted.org/packages/a8/15/84402b24f833508ccf66c85b227c9b136857c6236d33832836c8d2741d5c/marshmallow_dataframe-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5bd8c5df596bb207319917053ddf3965", "sha256": "10789550eec10af4ec42dc56b7dcdddc777124b714241f23e00b1ba446b0ec35" }, "downloads": -1, "filename": "marshmallow-dataframe-0.0.3.tar.gz", "has_sig": false, "md5_digest": "5bd8c5df596bb207319917053ddf3965", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 11556, "upload_time": "2019-05-10T11:26:28", "url": "https://files.pythonhosted.org/packages/89/a0/f000443d7f40a0ccc78055ff49f5bd100f1f6458796b7f4823919f629c91/marshmallow-dataframe-0.0.3.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "4fac928e9993dacddfab6727c233a091", "sha256": "fce2c9a723e0e6d71cb2828ef12714a73c6b5353da66921b1327dc5739ac9edf" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4fac928e9993dacddfab6727c233a091", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9163, "upload_time": "2019-05-10T14:30:46", "url": "https://files.pythonhosted.org/packages/48/e1/bd3de99624c1b35b0256bed64a57aef335130765b0ee369aa87b4f74dcd2/marshmallow_dataframe-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "97efca97081d684650cc19ef2715f8e5", "sha256": "faac07cb5cf18280ef4f5f86ef446cc95b6c90943c60e2a18677d34e21df7b39" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.0.tar.gz", "has_sig": false, "md5_digest": "97efca97081d684650cc19ef2715f8e5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 12015, "upload_time": "2019-05-10T14:30:47", "url": "https://files.pythonhosted.org/packages/18/e8/bc53fb3ab915e05864fe51713183abacded1925b921fde37fec95e5cff7a/marshmallow-dataframe-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3989967ec7416ac540828fe37dce6788", "sha256": "49053227c459ffef67ed8bd056768ee35a88b84effbed052b3de6a0981279ea3" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "3989967ec7416ac540828fe37dce6788", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9161, "upload_time": "2019-05-10T14:36:09", "url": "https://files.pythonhosted.org/packages/08/96/213e28fe5f4254a64a4a53184d4cfa60656d350c71ccc33ffa2862cb9e8f/marshmallow_dataframe-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "51f0988cf5c27bf7587b20954a7a0777", "sha256": "d5635dc91a7cf6d13e5198a6e40314e3fb08cc0eea00b11dbff9e032442c1fb1" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.1.tar.gz", "has_sig": false, "md5_digest": "51f0988cf5c27bf7587b20954a7a0777", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 11998, "upload_time": "2019-05-10T14:36:11", "url": "https://files.pythonhosted.org/packages/4d/93/c15e1023d52c6d4e8b668b834b1ad249f808b13dfd766ca9428a424e9eec/marshmallow-dataframe-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "16c6aaa63f2802d90ffdeeea2ea798cf", "sha256": "d84c1e1975ff1815f08519438dd35771bbd5c424065a953a258f5527917b27be" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "16c6aaa63f2802d90ffdeeea2ea798cf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 10676, "upload_time": "2019-05-24T10:11:02", "url": "https://files.pythonhosted.org/packages/83/b5/8327bf7877918e98d8745577f98c2e5c4b1fff58e83ad2b1f1d28698e0b2/marshmallow_dataframe-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "495fa9b050736de7984b87ca6fd9a79e", "sha256": "f399993f89ffd4b4cb4e6a28568f90368ce7cc31abef1acbdd8c99376dfc0916" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.2.tar.gz", "has_sig": false, "md5_digest": "495fa9b050736de7984b87ca6fd9a79e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 12742, "upload_time": "2019-05-24T10:11:03", "url": "https://files.pythonhosted.org/packages/d3/97/7f64c680f3befc7c812c35299f64b63db6358022586b7bf8d933dea93108/marshmallow-dataframe-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "0c600784fcde4b0e517ab5de6cd4ca92", "sha256": "283331eef3dbbabb0ba9eb249f3f4dbb1e3af759b42edeedb637a55bbcde961a" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "0c600784fcde4b0e517ab5de6cd4ca92", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 10681, "upload_time": "2019-08-22T14:22:34", "url": "https://files.pythonhosted.org/packages/85/71/f6f078a95806b15c0db70e235e475da68d3fc3ad12c350fb45448da50264/marshmallow_dataframe-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ff3837cb19289ada27656c84c41b0f3a", "sha256": "d0ac145c7591f1cacb271b22c2ed77514cdc3e80a92160ef119fca8860c9be9e" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.3.tar.gz", "has_sig": false, "md5_digest": "ff3837cb19289ada27656c84c41b0f3a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 12748, "upload_time": "2019-08-22T14:22:35", "url": "https://files.pythonhosted.org/packages/2f/75/92507229b09b4bc94c2e7c70abe591f926b9486d9b30f34d037912757466/marshmallow-dataframe-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "93aa094c3b61a3fc8f405ffd0a9d70ef", "sha256": "3aa5180eeb6867c0b608b425e5776e1a969cb3f9dfbac751fa405fc2766552bd" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "93aa094c3b61a3fc8f405ffd0a9d70ef", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 10717, "upload_time": "2019-08-30T15:10:47", "url": "https://files.pythonhosted.org/packages/97/30/5a4e81e718f2e371dc5c231728ccc2ebeab24a3c5b0a3d15dbe794f18b58/marshmallow_dataframe-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "689077a8dbf54528b87cd0703efc3cd5", "sha256": "a18f47b2646d16236d89e07e295eecd37d7d52d6dd5b25ee00a80d5d6e04bb58" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.4.tar.gz", "has_sig": false, "md5_digest": "689077a8dbf54528b87cd0703efc3cd5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14738, "upload_time": "2019-08-30T15:10:48", "url": "https://files.pythonhosted.org/packages/e7/74/66808782f001791444c9969fea42da80473192fcdacbc049c7fc890b3b12/marshmallow-dataframe-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "93aa094c3b61a3fc8f405ffd0a9d70ef", "sha256": "3aa5180eeb6867c0b608b425e5776e1a969cb3f9dfbac751fa405fc2766552bd" }, "downloads": -1, "filename": "marshmallow_dataframe-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "93aa094c3b61a3fc8f405ffd0a9d70ef", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 10717, "upload_time": "2019-08-30T15:10:47", "url": "https://files.pythonhosted.org/packages/97/30/5a4e81e718f2e371dc5c231728ccc2ebeab24a3c5b0a3d15dbe794f18b58/marshmallow_dataframe-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "689077a8dbf54528b87cd0703efc3cd5", "sha256": "a18f47b2646d16236d89e07e295eecd37d7d52d6dd5b25ee00a80d5d6e04bb58" }, "downloads": -1, "filename": "marshmallow-dataframe-0.1.4.tar.gz", "has_sig": false, "md5_digest": "689077a8dbf54528b87cd0703efc3cd5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14738, "upload_time": "2019-08-30T15:10:48", "url": "https://files.pythonhosted.org/packages/e7/74/66808782f001791444c9969fea42da80473192fcdacbc049c7fc890b3b12/marshmallow-dataframe-0.1.4.tar.gz" } ] }