<file_sep>import pandas as pd


def load_sample():
    df = pd.read_csv(
        "https://gist.githubusercontent.com/rgbkrk/a7984a8788a73e2afb8fd4b89c8ec6de/raw/db8d1db9f878ed448c3cac3eb3c9c0dc5e80891e/2015.csv"
    )
    return df.set_index("Country")
<file_sep># dx Design Concepts

## Use cases

- Store a chart view
- Load a stored chart into a notebook
- Save chart settings as a template
- Programmatic creation of a chart

## JSON Schema for data-explorer

Update the current schema files for data-explorer as they currently fail
when trying to convert to a Python model

## Convert JSON Schema to Python model

- Check for valid JSON Schema doc before generating Python code
- Use **datamodel-code-generator** to convert JSON, JSON Schema or OpenAPI to
Python model.
## Store the Python model for programmatic use

## Workflow

- Create a notebook
- Display a chart
- Save the notebook
- Extract the chart cell's metadata
- Create a second notebook for programmatic execution
- Pass the cell's metadata converted to Python code
- Render the chart from the Python code in a notebook
<file_sep>dataclasses-json
datamodel-code-generator
jsonschema
jupyter
marshmallow
nteract_on_jupyter
pandas
pydantic
<file_sep># CONTRIBUTING

We use flit to package this project for PyPI.<file_sep>"""Generate python pydantic models from JSON Schema files."""
from pathlib import Path
from tempfile import TemporaryDirectory

from datamodel_code_generator import InputFileType, generate


# TODO convert to file later
json_schema: str = """{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    },
    "friends": {
      "type": "array"
    },
    "comment": {
      "type": "null"
    }
  }
}
"""

with TemporaryDirectory() as temporary_directory_name:
    temporary_directory = Path(temporary_directory_name)
    output = Path(temporary_directory / 'model.py')
    generate(
        json_schema,
        input_file_type=InputFileType.JsonSchema,
        input_filename="example.json",
        output=output,
    )
    model: str = output.read_text()
print(model)


<file_sep>black
flit
isort
pytest
tox
<file_sep># dx

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/nteract/dx/main?urlpath=nteract/tree/examples)

A Pythonic Data Explorer.

## Install

For Python 3.8+:

```
pip install dx
```

## Usage

The `dx` library contains a simple helper function also called `dx`.

```python
from dx import dx
```

`dx()` takes one positional argument, a `dataframe`.

```python
dx(dataframe)
```

The `dx(dataframe)` function will display the dataframe in
[data explorer](https://github.com/nteract/data-explorer) mode:

![dx in action](https://user-images.githubusercontent.com/836375/44104304-651a2560-9fa3-11e8-9852-76db43270188.png)

Today, a Pandas `DataFrame` may be passed. In the future, other dataframe types
may be supported.

### Example

```python
import pandas as pd
from dx import dx


# Get happiness data and create a pandas dataframe
df = pd.read_csv('examples/data/2019.csv')

# Open data explorer with the happiness dataframe
dx(df)
```

If you only wish to display a certain number of rows from the dataframe, use
a context and specify the max rows (if set to None, all rows are used):

```python
# To use the first 13 rows for visualization with dx
with pd.option_context('display.max_rows', 13):
  dx(df)
```

## FAQ

Q: What about Spark?

A: Spark support would be highly welcome!

See [improved-spark-viz](https://github.com/nteract/improved-spark-viz) for
the current effort. There's a format that pandas handles for us that we could
create in spark land.

## Develop

```
git clone https://github.com/nteract/dx
cd dx
pip install -e .
```

We currently install jupyter and jupyter_on_nteract packages for ease of running
examples.

To run nteract on jupyter:

```
jupyter nteract
```



## Code of Conduct

We follow the nteract.io code of conduct.

## LICENSE

See [LICENSE.md](LICENSE.md).
<file_sep>"""A Pythonic Data Explorer"""

__version__ = '0.3.0.dev0'


import pandas as pd

from .datasets import load_sample


def dx(dataframe, sampled=None):
    """Create dx from a dataframe"""
    # All the metadata keys that we'll apply for just the data explorer media
    # type, `application/vnd.dataresource+json`
    scoped_metadata = {}

    if sampled:
        scoped_metadata["sampled"] = sampled

    metadata = {"application/vnd.dataresource+json": scoped_metadata}

    with pd.option_context('display.html.table_schema', True):
        display(dataframe, metadata=metadata)


def enable():
    """Enable html table display"""
    pd.options.display.html.table_schema = True


def disable():
    """Disable html table display"""
    pd.options.display.html.table_schema = False
<file_sep>[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "dx"
author = "nteract"
author-email = "<EMAIL>"
home-page = "https://github.com/nteract/dx"
description-file = "README.md"
requires = [
    "datamodel-code-generator",
    "dataclasses-json",
    "jsonschema",
    "jupyter",
    "marshmallow",
    "nteract_on_jupyter",
    "pandas",
    "pydantic"
]
classifiers = [
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9"
]
dist-name = "dx"

[tool.flit.metadata.requires-extra]
dev = [
    "black",
    "flit",
    "isort",
    "pre-commit",
    "pytest",
    "tox"
]
test = [
    "pytest >=2.7.3",
    "pytest-cov",
]
doc = ["sphinx"]


[tool.black]
line-length = 88
target-version = ['py38']
include = '\.pyi?$'
extend-exclude = '''
# A regex preceded with ^/ will apply only to files and directories
# in the root of the project.
^/foo.py  # exclude a file named foo.py in the root of the project (in addition to the defaults)
'''

[tool.isort]
profile = "black"
multi_line_output = 3
<file_sep>[tox]
envlist = testenv, py39
isolated_build = true

[testenv]
basepython = python3.9
command = pytest -vv . 

[testenv:py39]
basepython = python3.9
<file_sep>import pytest


def test_load_sample():
    pass

def test_load_sample_fails():
    pass
