microdf-python 0.3.0__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- microdf_python-0.4.4/LICENSE +21 -0
- microdf_python-0.4.4/PKG-INFO +25 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/chart_utils.py +8 -3
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/charts.py +12 -4
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/generic.py +53 -6
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/io.py +10 -4
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/style.py +10 -5
- microdf_python-0.4.4/microdf_python.egg-info/PKG-INFO +25 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf_python.egg-info/SOURCES.txt +1 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf_python.egg-info/requires.txt +4 -2
- {microdf-python-0.3.0 → microdf_python-0.4.4}/setup.py +9 -5
- microdf-python-0.3.0/PKG-INFO +0 -11
- microdf-python-0.3.0/microdf_python.egg-info/PKG-INFO +0 -11
- {microdf-python-0.3.0 → microdf_python-0.4.4}/README.md +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/__init__.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/_optional.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/agg.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/concat.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/constants.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/custom_taxes.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/income_measures.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/inequality.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/poverty.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/tax.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/taxcalc.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/ubi.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/utils.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf/weighted.py +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf_python.egg-info/dependency_links.txt +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf_python.egg-info/not-zip-safe +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/microdf_python.egg-info/top_level.txt +0 -0
- {microdf-python-0.3.0 → microdf_python-0.4.4}/setup.cfg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Max Ghenis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microdf-python
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: Survey microdata as DataFrames.
|
|
5
|
+
Home-page: http://github.com/PSLmodels/microdf
|
|
6
|
+
Author: Max Ghenis
|
|
7
|
+
Author-email: max@ubicenter.org
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Provides-Extra: taxcalc
|
|
13
|
+
Requires-Dist: taxcalc; extra == "taxcalc"
|
|
14
|
+
Provides-Extra: charts
|
|
15
|
+
Requires-Dist: seaborn; extra == "charts"
|
|
16
|
+
Requires-Dist: matplotlib; extra == "charts"
|
|
17
|
+
Requires-Dist: matplotlib-label-lines; extra == "charts"
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: provides-extra
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: summary
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import matplotlib as mpl
|
|
2
|
-
|
|
3
|
-
|
|
4
1
|
def dollar_format(suffix=""):
|
|
5
2
|
"""Dollar formatter for matplotlib.
|
|
6
3
|
|
|
@@ -19,6 +16,14 @@ def currency_format(currency="USD", suffix=""):
|
|
|
19
16
|
:returns: FuncFormatter.
|
|
20
17
|
|
|
21
18
|
"""
|
|
19
|
+
try:
|
|
20
|
+
import matplotlib as mpl
|
|
21
|
+
except ImportError:
|
|
22
|
+
raise ImportError(
|
|
23
|
+
"The function you've called requires extra dependencies. " +
|
|
24
|
+
"Please install microdf with the 'charts' extra by running " +
|
|
25
|
+
"'pip install microdf[charts]'"
|
|
26
|
+
)
|
|
22
27
|
|
|
23
28
|
prefix = {"USD": "$", "GBP": "£"}[currency]
|
|
24
29
|
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import matplotlib as mpl
|
|
2
|
-
import matplotlib.pyplot as plt
|
|
3
1
|
import numpy as np
|
|
4
|
-
import seaborn as sns
|
|
5
2
|
|
|
6
3
|
import microdf as mdf
|
|
7
4
|
|
|
@@ -19,6 +16,17 @@ def quantile_pct_chg_plot(df1, df2, col1, col2, w1=None, w2=None, q=None):
|
|
|
19
16
|
:returns: Axis.
|
|
20
17
|
|
|
21
18
|
"""
|
|
19
|
+
try:
|
|
20
|
+
import seaborn as sns
|
|
21
|
+
import matplotlib as mpl
|
|
22
|
+
import matplotlib.pyplot as plt
|
|
23
|
+
except ImportError:
|
|
24
|
+
raise ImportError(
|
|
25
|
+
"The function you've called requires extra dependencies. " +
|
|
26
|
+
"Please install microdf with the 'charts' extra by running " +
|
|
27
|
+
"'pip install microdf[charts]'"
|
|
28
|
+
)
|
|
29
|
+
|
|
22
30
|
if q is None:
|
|
23
31
|
q = np.arange(0.1, 1, 0.1)
|
|
24
32
|
# Calculate weighted quantiles.
|
|
@@ -34,7 +42,7 @@ def quantile_pct_chg_plot(df1, df2, col1, col2, w1=None, w2=None, q=None):
|
|
|
34
42
|
# Plot.
|
|
35
43
|
fig, ax = plt.subplots()
|
|
36
44
|
markerline, stemlines, baseline = ax.stem(
|
|
37
|
-
df.index_newline, df.pct_chg
|
|
45
|
+
df.index_newline, df.pct_chg
|
|
38
46
|
)
|
|
39
47
|
plt.setp(baseline, color="gray", linewidth=0)
|
|
40
48
|
ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))
|
|
@@ -251,23 +251,24 @@ class MicroSeries(pd.Series):
|
|
|
251
251
|
ranks = np.array(self.weights.values)[order].cumsum()[inverse_order]
|
|
252
252
|
if pct:
|
|
253
253
|
ranks /= self.weights.values.sum()
|
|
254
|
+
np.where(ranks > 1.0, 1.0, ranks)
|
|
254
255
|
return pd.Series(ranks, index=self.index)
|
|
255
256
|
|
|
256
257
|
@vector_function
|
|
257
258
|
def decile_rank(self):
|
|
258
|
-
return MicroSeries(np.ceil(self.rank(pct=True) * 10))
|
|
259
|
+
return MicroSeries(np.minimum(np.ceil(self.rank(pct=True) * 10), 10))
|
|
259
260
|
|
|
260
261
|
@vector_function
|
|
261
262
|
def quintile_rank(self):
|
|
262
|
-
return MicroSeries(np.ceil(self.rank(pct=True) * 5))
|
|
263
|
+
return MicroSeries(np.minimum(np.ceil(self.rank(pct=True) * 5), 5))
|
|
263
264
|
|
|
264
265
|
@vector_function
|
|
265
266
|
def quartile_rank(self):
|
|
266
|
-
return MicroSeries(np.ceil(self.rank(pct=True) * 4))
|
|
267
|
+
return MicroSeries(np.minimum(np.ceil(self.rank(pct=True) * 4), 4))
|
|
267
268
|
|
|
268
269
|
@vector_function
|
|
269
270
|
def percentile_rank(self):
|
|
270
|
-
return MicroSeries(np.ceil(self.rank(pct=True) * 100))
|
|
271
|
+
return MicroSeries(np.minimum(np.ceil(self.rank(pct=True) * 100), 100))
|
|
271
272
|
|
|
272
273
|
def groupby(self, *args, **kwargs):
|
|
273
274
|
gb = super().groupby(*args, **kwargs)
|
|
@@ -319,6 +320,48 @@ class MicroSeries(pd.Series):
|
|
|
319
320
|
def __pow__(self, other):
|
|
320
321
|
return MicroSeries(super().__pow__(other), weights=self.weights)
|
|
321
322
|
|
|
323
|
+
def __xor__(self, other):
|
|
324
|
+
return MicroSeries(super().__xor__(other), weights=self.weights)
|
|
325
|
+
|
|
326
|
+
def __and__(self, other):
|
|
327
|
+
return MicroSeries(super().__and__(other), weights=self.weights)
|
|
328
|
+
|
|
329
|
+
def __or__(self, other):
|
|
330
|
+
return MicroSeries(super().__or__(other), weights=self.weights)
|
|
331
|
+
|
|
332
|
+
def __invert__(self):
|
|
333
|
+
return MicroSeries(super().__invert__(), weights=self.weights)
|
|
334
|
+
|
|
335
|
+
def __radd__(self, other):
|
|
336
|
+
return MicroSeries(super().__radd__(other), weights=self.weights)
|
|
337
|
+
|
|
338
|
+
def __rsub__(self, other):
|
|
339
|
+
return MicroSeries(super().__rsub__(other), weights=self.weights)
|
|
340
|
+
|
|
341
|
+
def __rmul__(self, other):
|
|
342
|
+
return MicroSeries(super().__rmul__(other), weights=self.weights)
|
|
343
|
+
|
|
344
|
+
def __rfloordiv__(self, other):
|
|
345
|
+
return MicroSeries(super().__rfloordiv__(other), weights=self.weights)
|
|
346
|
+
|
|
347
|
+
def __rtruediv__(self, other):
|
|
348
|
+
return MicroSeries(super().__rtruediv__(other), weights=self.weights)
|
|
349
|
+
|
|
350
|
+
def __rmod__(self, other):
|
|
351
|
+
return MicroSeries(super().__rmod__(other), weights=self.weights)
|
|
352
|
+
|
|
353
|
+
def __rpow__(self, other):
|
|
354
|
+
return MicroSeries(super().__rpow__(other), weights=self.weights)
|
|
355
|
+
|
|
356
|
+
def __rand__(self, other):
|
|
357
|
+
return MicroSeries(super().__rand__(other), weights=self.weights)
|
|
358
|
+
|
|
359
|
+
def __ror__(self, other):
|
|
360
|
+
return MicroSeries(super().__ror__(other), weights=self.weights)
|
|
361
|
+
|
|
362
|
+
def __rxor__(self, other):
|
|
363
|
+
return MicroSeries(super().__rxor__(other), weights=self.weights)
|
|
364
|
+
|
|
322
365
|
# comparators
|
|
323
366
|
|
|
324
367
|
def __lt__(self, other):
|
|
@@ -661,7 +704,9 @@ class MicroDataFrame(pd.DataFrame):
|
|
|
661
704
|
|
|
662
705
|
@get_args_as_micro_series()
|
|
663
706
|
def groupby(self, by: Union[str, list], *args, **kwargs):
|
|
664
|
-
"""
|
|
707
|
+
"""
|
|
708
|
+
Returns a GroupBy object with MicroSeriesGroupBy objects for
|
|
709
|
+
each column
|
|
665
710
|
|
|
666
711
|
:param by: column to group by
|
|
667
712
|
:type by: Union[str, list]
|
|
@@ -766,7 +811,9 @@ class MicroDataFrame(pd.DataFrame):
|
|
|
766
811
|
income: Union[MicroSeries, str],
|
|
767
812
|
threshold: Union[MicroSeries, str],
|
|
768
813
|
) -> int:
|
|
769
|
-
"""
|
|
814
|
+
"""
|
|
815
|
+
Calculates the number of entities with income below a poverty
|
|
816
|
+
threshold.
|
|
770
817
|
|
|
771
818
|
:param income: income array or column name
|
|
772
819
|
:type income: Union[MicroSeries, str]
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import io
|
|
2
2
|
import zipfile
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import requests
|
|
5
4
|
import pandas as pd
|
|
6
5
|
|
|
6
|
+
HEADER = {
|
|
7
|
+
"User-Agent":
|
|
8
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) " +
|
|
9
|
+
"AppleWebKit/537.36 (KHTML, like Gecko) " +
|
|
10
|
+
"Chrome/50.0.2661.102 Safari/537.36"
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
|
|
8
14
|
def read_stata_zip(url: str, **kwargs) -> pd.DataFrame:
|
|
9
15
|
"""Reads zipped Stata file by URL.
|
|
@@ -19,8 +25,8 @@ def read_stata_zip(url: str, **kwargs) -> pd.DataFrame:
|
|
|
19
25
|
:returns: DataFrame.
|
|
20
26
|
|
|
21
27
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
r = requests.get(url, headers=HEADER)
|
|
29
|
+
data = io.BytesIO(r.content)
|
|
24
30
|
with zipfile.ZipFile(data) as archive:
|
|
25
31
|
with archive.open(archive.namelist()[0]) as stata:
|
|
26
32
|
return pd.read_stata(stata, **kwargs)
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import matplotlib as mpl
|
|
2
|
-
import matplotlib.font_manager as fm
|
|
3
|
-
import seaborn as sns
|
|
4
|
-
|
|
5
|
-
|
|
6
1
|
TITLE_COLOR = "#212121"
|
|
7
2
|
AXIS_COLOR = "#757575"
|
|
8
3
|
GRID_COLOR = "#eeeeee" # Previously lighter #f5f5f5.
|
|
@@ -16,6 +11,16 @@ def set_plot_style(dpi: int = DPI):
|
|
|
16
11
|
(200).
|
|
17
12
|
:type dpi: int, optional
|
|
18
13
|
"""
|
|
14
|
+
try:
|
|
15
|
+
import seaborn as sns
|
|
16
|
+
import matplotlib as mpl
|
|
17
|
+
import matplotlib.font_manager as fm
|
|
18
|
+
except ImportError:
|
|
19
|
+
raise ImportError(
|
|
20
|
+
"The function you've called requires extra dependencies. " +
|
|
21
|
+
"Please install microdf with the 'charts' extra by running " +
|
|
22
|
+
"'pip install microdf[charts]'"
|
|
23
|
+
)
|
|
19
24
|
|
|
20
25
|
sns.set_style("white")
|
|
21
26
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microdf-python
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: Survey microdata as DataFrames.
|
|
5
|
+
Home-page: http://github.com/PSLmodels/microdf
|
|
6
|
+
Author: Max Ghenis
|
|
7
|
+
Author-email: max@ubicenter.org
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Provides-Extra: taxcalc
|
|
13
|
+
Requires-Dist: taxcalc; extra == "taxcalc"
|
|
14
|
+
Provides-Extra: charts
|
|
15
|
+
Requires-Dist: seaborn; extra == "charts"
|
|
16
|
+
Requires-Dist: matplotlib; extra == "charts"
|
|
17
|
+
Requires-Dist: matplotlib-label-lines; extra == "charts"
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: author-email
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: provides-extra
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: summary
|
|
@@ -2,7 +2,7 @@ from setuptools import setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="microdf-python",
|
|
5
|
-
version="0.
|
|
5
|
+
version="0.4.4",
|
|
6
6
|
description="Survey microdata as DataFrames.",
|
|
7
7
|
url="http://github.com/PSLmodels/microdf",
|
|
8
8
|
author="Max Ghenis",
|
|
@@ -10,12 +10,16 @@ setup(
|
|
|
10
10
|
license="MIT",
|
|
11
11
|
packages=["microdf"],
|
|
12
12
|
install_requires=[
|
|
13
|
-
"matplotlib",
|
|
14
|
-
"matplotlib-label-lines",
|
|
15
13
|
"numpy",
|
|
16
14
|
"pandas",
|
|
17
|
-
"seaborn",
|
|
18
15
|
],
|
|
19
|
-
extras_require={
|
|
16
|
+
extras_require={
|
|
17
|
+
"taxcalc": ["taxcalc"],
|
|
18
|
+
"charts": [
|
|
19
|
+
"seaborn",
|
|
20
|
+
"matplotlib",
|
|
21
|
+
"matplotlib-label-lines"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
20
24
|
zip_safe=False,
|
|
21
25
|
)
|
microdf-python-0.3.0/PKG-INFO
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: microdf-python
|
|
3
|
-
Version: 0.3.0
|
|
4
|
-
Summary: Survey microdata as DataFrames.
|
|
5
|
-
Home-page: http://github.com/PSLmodels/microdf
|
|
6
|
-
Author: Max Ghenis
|
|
7
|
-
Author-email: max@ubicenter.org
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Provides-Extra: taxcalc
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: microdf-python
|
|
3
|
-
Version: 0.3.0
|
|
4
|
-
Summary: Survey microdata as DataFrames.
|
|
5
|
-
Home-page: http://github.com/PSLmodels/microdf
|
|
6
|
-
Author: Max Ghenis
|
|
7
|
-
Author-email: max@ubicenter.org
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: UNKNOWN
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Provides-Extra: taxcalc
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|