{"id":15043603,"url":"https://github.com/yymao/easyquery","last_synced_at":"2025-04-14T23:10:54.329Z","repository":{"id":45471732,"uuid":"101179501","full_name":"yymao/easyquery","owner":"yymao","description":"Create easy-to-use Query objects that can apply on NumPy structured arrays, astropy Table, and Pandas DataFrame","archived":false,"fork":false,"pushed_at":"2021-12-12T16:32:15.000Z","size":57,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T11:11:39.584Z","etag":null,"topics":["astropy-tables","easyquery","numexpr","pandas-dataframe","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yymao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-23T12:50:42.000Z","updated_at":"2022-07-17T02:03:24.000Z","dependencies_parsed_at":"2022-07-15T03:16:53.574Z","dependency_job_id":null,"html_url":"https://github.com/yymao/easyquery","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Feasyquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Feasyquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Feasyquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yymao%2Feasyquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yymao","download_url":"https://codeload.github.com/yymao/easyquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975316,"owners_count":21192210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astropy-tables","easyquery","numexpr","pandas-dataframe","python"],"created_at":"2024-09-24T20:49:19.775Z","updated_at":"2025-04-14T23:10:54.310Z","avatar_url":"https://github.com/yymao.png","language":"Python","readme":"# easyquery\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/easyquery.svg)](https://anaconda.org/conda-forge/easyquery)\n[![PyPI version](https://img.shields.io/pypi/v/easyquery.svg)](https://pypi.python.org/pypi/easyquery)\n\nCreate easy-to-use Query objects that can apply on NumPy structured arrays, astropy Table, and Pandas DataFrame.\n\nTired of writing lots of brackets and keeping track of variable names when filtering table data? Enter `easyquery`! \n\nBefore `easyquery`:\n```python\nsubtable = table[table[\"population\"] \u003e= 20000]\nsubtable = subtable[subtable[\"population\"] / subtable[\"area\"] \u003e= 1000]\n```\n\nWith `easyquery`\n```python\nsubtable = Query(\"population \u003e= 20000\", \"population / area \u003e= 1000\").filter(table)\n```\n\n## Installation\n\nYou can install `easyquey` from conda-forge:\n\n```bash\nconda install scipy --channel conda-forge\n```\n\nOr from PyPI:\n\n```bash\npip install easyquery\n```\n\n## Usage\n\n### Creating Query objects\n\nThe most important concept that easyquery introduces is a _Query_ object,\nwhich is an object that represents the queries (conditions) that you want to\napply to your table data.\n\nFor most simple cases a Query object can be created with a simple string:\n\n```python\nq1 = Query('population \u003e= 20000')\nq2 = Query('population / area \u003e= 1000')\n```\n\nThe string will be passed to numexpr and you can find a list of supported\noperators and math functions\n[here](https://numexpr.readthedocs.io/en/latest/user_guide.html#supported-operators).\n\nYou can also combine multiple conditions at once:\n\n```python\nq3 = Query('population \u003e= 20000', 'area \u003c 300') # satisfies both\n```\n\nA Query object can also be created with a tuple, where the first element of\nthe tuple should be a callable, and the rest should be the field names that\ncorrespond to the argument list of the callable.\nThis construction allows you to specify more complex queries or to use functions\nthat are not supported by numexpr.\nFor example, `q4` below has the same effect as `q2` above.\n\n```python\nq4 = Query((lambda x, y: x / y \u003e= 1000, 'population', 'area'))\n```\n\nYou can also use `QueryMaker` to create some commonly used conditions that\ncannot be easily written as simple string.\n\n```\n# for string operations\nq5 = QueryMaker.equals('name', 'Paris')\nq6 = QueryMaker.contains('name', 'New')\nq7 = QueryMaker.startswith('name', 'San')\n\n# for checking if the column values are in another list\nq8 = QueryMaker.in1d('id', [1, 3, 6, 7])\n```\n\nQuery objects can be combined with `\u0026` (and), `|` (or), `^` (xor), and cen be\nmodified by `~` (not). Each of these operation returns a new Query object.\n\n```python\nq9 = (~q1 | Query('established_year \u003e 1900'))\n```\n\n### Using Query objects\n\nA Query object has three major methods: `filter`, `count`, and `mask`.\nAll of them can operate on NumPy structured arrays, astropy Tables, and pandas DataFrames:\n\n- `filter` returns a new table that only has entries satisfying the query;\n- `count` returns the number of entries satisfying the query;\n- `mask` returns a bool array for masking the table.\n\n```python\nimport numpy as np\nfrom easyquery import Query\nt = np.array([(1, 5, 4.5), (1, 1, 6.2), (3, 2, 0.5), (5, 5, -3.5)],\n             dtype=np.dtype([('a', '\u003ci8'), ('b', '\u003ci8'), ('c', '\u003cf8')]))\n\nq = Query('a \u003e 3')\nq.filter(t)\nq.count(t)\nq.mask(t)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyymao%2Feasyquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyymao%2Feasyquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyymao%2Feasyquery/lists"}