# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['pandas_dataclasses', 'pandas_dataclasses.core']

package_data = \
{'': ['*']}

install_requires = \
['morecopy>=0.2,<0.3', 'typing-extensions>=4.1,<5.0']

extras_require = \
{':python_full_version >= "3.7.1" and python_version < "3.8"': ['numpy>=1.20,<1.22',
                                                                'pandas>=1.3,<1.4'],
 ':python_version >= "3.8" and python_version < "3.11"': ['numpy>=1.20,<2.0',
                                                          'pandas>=1.3,<2.0']}

setup_kwargs = {
    'name': 'pandas-dataclasses',
    'version': '0.4.0',
    'description': 'pandas data creation made easy by dataclass',
    'long_description': '# pandas-dataclasses\n\n[![Release](https://img.shields.io/pypi/v/pandas-dataclasses?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/pandas-dataclasses/)\n[![Python](https://img.shields.io/pypi/pyversions/pandas-dataclasses?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/pandas-dataclasses/)\n[![Downloads](https://img.shields.io/pypi/dm/pandas-dataclasses?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/pandas-dataclasses)\n[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5633924-cornflowerblue?style=flat-square)](https://doi.org/10.5281/zenodo.5633924)\n[![Tests](https://img.shields.io/github/workflow/status/astropenguin/pandas-dataclasses/Tests?label=Tests&style=flat-square)](https://github.com/astropenguin/pandas-dataclasses/actions)\n\npandas data creation made easy by dataclass\n\n## Overview\n\npandas-dataclass makes it easy to create [pandas] data (Series and DataFrame) by Python\'s [dataclass] that enables to specify their data types, attributes, and names:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom pandas_dataclasses import AsDataFrame, Data, Index\n```\n</details>\n\n```python\n@dataclass\nclass Weather(AsDataFrame):\n    """Weather information."""\n\n    year: Index[int]\n    month: Index[int]\n    temp: Data[float]\n    humid: Data[float]\n\n\ndf = Weather.new(\n    [2020, 2020, 2021, 2021, 2022],\n    [1, 7, 1, 7, 1],\n    [7.1, 24.3, 5.4, 25.9, 4.9],\n    [65, 89, 57, 83, 52],\n)\n```\n\nwhere `df` will become a DataFrame object like:\n\n```\n            temp  humid\nyear month\n2020 1       7.1   65.0\n     7      24.3   89.0\n2021 1       5.4   57.0\n     7      25.9   83.0\n2022 1       4.9   52.0\n```\n\n### Features\n\n- Type specification of pandas indexes and data\n- Metadata storing in pandas data attributes\n- Support for hierarchical index and columns\n- Support for full [dataclass] features\n- Support for static type check by [Pyright] ([Pylance])\n\n### Installation\n\n```bash\npip install pandas-dataclasses\n```\n\n## How it works\n\npandas-dataclasses provides you the following features:\n\n- Type hints for dataclass fields (`Attr`, `Data`, `Index`, `Name`) to specify index(es), data, attributes, and names of pandas data\n- Mix-in classes for dataclasses (`As`, `AsDataFrame`, `AsSeries`) to create pandas data by a classmethod (`new`) that takes the same arguments as dataclass initialization\n\nWhen you call `new`, it will first create a dataclass object and then create a Series or DataFrame object from the dataclass object according the type hints and values in it.\nIn the example above, `df = Weather.new(...)` is thus equivalent to:\n\n```python\nobj = Weather([2020, ...], [1, ...], [7.1, ...], [65, ...])\ndf = asdataframe(obj)\n```\n\nwhere `asdataframe` is a conversion function.\npandas-dataclasses does not touch the dataclass object creation itself; this allows you to fully customize your dataclass before conversion by the dataclass features (`field`, `__post_init__`, ...).\n\n## Basic usage\n\n### DataFrame creation\n\nAs shown in the example above, a dataclass that has the `AsDataFrame` mix-in will create DataFrame objects:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom pandas_dataclasses import AsDataFrame, Data, Index\n```\n</details>\n\n```python\n@dataclass\nclass Weather(AsDataFrame):\n    """Weather information."""\n\n    year: Index[int]\n    month: Index[int]\n    temp: Data[float]\n    humid: Data[float]\n\n\ndf = Weather.new(...)\n```\n\nwhere fields typed by `Index` are "index fields", each value of which will become an index or a part of a hierarchical index of a DataFrame object.\nFields typed by `Data` are "data fields", each value of which will become a data column of a DataFrame object.\nFields typed by other types are just ignored in the DataFrame creation.\n\nEach data or index will be cast to the data type specified in a type hint like `Index[int]`.\nUse `Any` or `None` (like `Index[Any]`) if you do not want type casting.\nSee [data typing rules](#data-typing-rules) for more examples.\n\nBy default, a field name (i.e. an argument name) is used for the name of corresponding data or index.\nSee [custom data/index naming](#custom-naming) if you want customization.\n\n### Series creation\n\nA dataclass that has the `AsSeries` mix-in will create Series objects:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom pandas_dataclasses import AsSeries, Data, Index\n```\n</details>\n\n```python\n@dataclass\nclass Temperature(AsSeries):\n    """Temperature information."""\n\n    year: Index[int]\n    month: Index[int]\n    temp: Data[float]\n\n\nser = Temperature.new(...)\n```\n\nUnlike `AsDataFrame`, the second and subsequent data fields are ignored in the Series creation.\nOther rules are the same as for the DataFrame creation.\n\n## Advanced usage\n\n### Metadata storing\n\nFields typed by `Attr` are "attribute fields", each value of which will become an item of attributes (`attrs`) of a DataFrame or a Series object:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom pandas_dataclasses import AsDataFrame, Attr, Data, Index\n```\n</details>\n\n```python\n@dataclass\nclass Weather(AsDataFrame):\n    """Weather information."""\n\n    year: Index[int]\n    month: Index[int]\n    temp: Data[float]\n    humid: Data[float]\n    loc: Attr[str] = "Tokyo"\n    lon: Attr[float] = 139.69167\n    lat: Attr[float] = 35.68944\n```\n\nIn this example, `Weather.new(...).attrs` will become like:\n\n```python\n{"loc": "Tokyo", "lon": 139.69167, "lat": 35.68944}\n```\n\n### Custom naming\n\nThe name of data, index, or attribute can be explicitly specified by adding a string annotation to the corresponding type:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom typing import Annotated as Ann\nfrom pandas_dataclasses import AsDataFrame, Attr, Data, Index\n```\n</details>\n\n```python\n@dataclass\nclass Weather(AsDataFrame):\n    """Weather information."""\n\n    year: Ann[Index[int], "Year"]\n    month: Ann[Index[int], "Month"]\n    temp: Ann[Data[float], "Temperature (deg C)"]\n    humid: Ann[Data[float], "Humidity (%)"]\n    loc: Ann[Attr[str], "Location"] = "Tokyo"\n    lon: Ann[Attr[float], "Longitude (deg)"] = 139.69167\n    lat: Ann[Attr[float], "Latitude (deg)"] = 35.68944\n```\n\nIn this example, `Weather.new(...)` and its attributes will become like:\n\n```\n            Temperature (deg C)  Humidity (%)\nYear Month\n2020 1                      7.1          65.0\n     7                     24.3          89.0\n2021 1                      5.4          57.0\n     7                     25.9          83.0\n2022 1                      4.9          52.0\n```\n\n```python\n{"Location": "Tokyo", "Longitude (deg)": 139.69167, "Latitude (deg)": 35.68944}\n```\n\nAdding dictionary annotations to data fields will create DataFrame objects with hierarchical columns, where dictionary keys will become the names of column levels and dictionary values will become the names of columns:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom dataclasses import dataclass\nfrom typing import Annotated as Ann\nfrom pandas_dataclasses import AsDataFrame, Data, Index\n```\n</details>\n\n```python\ndef name(stat: str, cat: str) -> dict[str, str]:\n    return {"Statistic": stat, "Category": cat}\n\n\n@dataclass\nclass Weather(AsDataFrame):\n    """Weather information."""\n\n    year: Ann[Index[int], "Year"]\n    month: Ann[Index[int], "Month"]\n    temp_avg: Ann[Data[float], name("Temperature (degC)", "Average")]\n    temp_max: Ann[Data[float], name("Temperature (degC)", "Maximum")]\n    wind_avg: Ann[Data[float], name("Wind speed (m/s)", "Average")]\n    wind_max: Ann[Data[float], name("Wind speed (m/s)", "Maximum")]\n```\n\nIn this example, `Weather.new(...)` will become like:\n\n```\nStatistic  Temperature (degC)         Wind speed (m/s)\nCategory              Average Maximum          Average Maximum\nYear Month\n2020 1                    7.1    11.1              2.4     8.8\n     7                   24.3    27.7              3.1    10.2\n2021 1                    5.4    10.3              2.3    10.7\n     7                   25.9    30.3              2.4     9.0\n2022 1                    4.9     9.4              2.6     8.8\n```\n\nFor the Series creation, a field typed by `Name` is a "name field", whose value will become the name of a Series object.\nThis is useful for dynamic naming.\nSee also [naming rules](#naming-rules) for more details and examples.\n\n### Custom pandas factory\n\nA custom class can be specified as a factory for the Series or DataFrame creation by `As`, the generic version of `AsDataFrame` and `AsSeries`.\nNote that the custom class must be a subclass of either `pandas.Series` or `pandas.DataFrame`:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nimport pandas as pd\nfrom dataclasses import dataclass\nfrom pandas_dataclasses import As, Data, Index\n```\n</details>\n\n```python\nclass CustomSeries(pd.Series):\n    """Custom pandas Series."""\n\n    pass\n\n\n@dataclass\nclass Temperature(As[CustomSeries]):\n    """Temperature information."""\n\n    year: Index[int]\n    month: Index[int]\n    temp: Data[float]\n\n\nser = Temperature.new(...)\nisinstance(ser, CustomSeries)  # True\n```\n\n## Appendix\n\n### Data typing rules\n\nThe data type (dtype) of data/index is inferred from the first `Data`/`Index` type of the corresponding field.\nThe following table shows how the data type is inferred:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom typing import Any, Annotated as Ann, Literal as L\nfrom pandas_dataclasses import Data\n```\n</details>\n\nType hint | Inferred data type\n--- | ---\n`Data[Any]` | `None` (no type casting)\n`Data[None]` | `None` (no type casting)\n`Data[int]` | `numpy.dtype("i8")`\n`Data[numpy.int32]` | `numpy.dtype("i4")`\n`Data[L["datetime64[ns]"]]` | `numpy.dtype("<M8[ns]")`\n`Data[L["category"]]` | `pandas.CategoricalDtype()`\n`Data[int] \\| str` | `numpy.dtype("i8")`\n`Data[int] \\| Data[float]` | `numpy.dtype("i8")`\n`Ann[Data[int], "spam"]` | `numpy.dtype("i8")`\n`Data[Ann[int, "spam"]]` | `numpy.dtype("i8")`\n\n### Naming rules\n\nThe name of data/index is determined by the following rules:\n\n1. If a name field exists, its value will be preferentially used (Series creation only)\n1. If a data/index field is annotated, the first annotation in the first `Data`/`Index` type will be used\n1. Otherwise, the field name (i.e. argument name) will be used\n\nThe following table shows how the name is inferred in the case of 2 and 3:\n\n<details>\n<summary>Click to see all imports</summary>\n\n```python\nfrom typing import Any, Annotated as Ann\nfrom pandas_dataclasses import Data\n```\n</details>\n\nType hint | Inferred name\n--- | ---\n`Data[Any]` | Field name\n`Ann[Data[Any], "spam"]` | `"spam"`\n`Ann[Data[Any], "spam"]` | `"spam"`\n`Ann[Data[Any], "spam", "ham"]` | `"spam"`\n`Ann[Data[Any], "spam"] \\| Ann[str, "ham"]` | `"spam"`\n`Ann[Data[Any], "spam"] \\| Ann[Data[float], "ham"]` | `"spam"`\n`Ann[Data[Any], {"0": "spam", "1": "ham"}]` | `("spam", "ham")`\n\n### Development roadmap\n\nRelease version | Features\n--- | ---\nv0.4.0 | Support for hierarchical column\nv0.5.0 | Support for dynamic naming of indexes and data\nv1.0.0 | Initial major release (freezing public features until v2.0.0)\n\n<!-- References -->\n[dataclass]: https://docs.python.org/3/library/dataclasses.html\n[NumPy]: https://numpy.org\n[pandas]: https://pandas.pydata.org\n[Pylance]: https://github.com/microsoft/pylance-release\n[Pyright]: https://github.com/microsoft/pyright\n',
    'author': 'Akio Taniguchi',
    'author_email': 'taniguchi@a.phys.nagoya-u.ac.jp',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/astropenguin/pandas-dataclasses/',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'extras_require': extras_require,
    'python_requires': '>=3.7.1,<3.11',
}


setup(**setup_kwargs)
