microdf-python 0.3.0__py3-none-any.whl → 0.4.3__py3-none-any.whl

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/chart_utils.py CHANGED
@@ -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
 
microdf/charts.py CHANGED
@@ -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, use_line_collection=True
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))
microdf/generic.py CHANGED
@@ -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)
@@ -661,7 +662,9 @@ class MicroDataFrame(pd.DataFrame):
661
662
 
662
663
  @get_args_as_micro_series()
663
664
  def groupby(self, by: Union[str, list], *args, **kwargs):
664
- """Returns a GroupBy object with MicroSeriesGroupBy objects for each column
665
+ """
666
+ Returns a GroupBy object with MicroSeriesGroupBy objects for
667
+ each column
665
668
 
666
669
  :param by: column to group by
667
670
  :type by: Union[str, list]
@@ -766,7 +769,9 @@ class MicroDataFrame(pd.DataFrame):
766
769
  income: Union[MicroSeries, str],
767
770
  threshold: Union[MicroSeries, str],
768
771
  ) -> int:
769
- """Calculates the number of entities with income below a poverty threshold.
772
+ """
773
+ Calculates the number of entities with income below a poverty
774
+ threshold.
770
775
 
771
776
  :param income: income array or column name
772
777
  :type income: Union[MicroSeries, str]
microdf/io.py CHANGED
@@ -1,9 +1,15 @@
1
1
  import io
2
2
  import zipfile
3
- from urllib.request import urlopen
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
- with urlopen(url) as request:
23
- data = io.BytesIO(request.read())
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)
microdf/style.py CHANGED
@@ -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
 
@@ -1,20 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: microdf-python
3
- Version: 0.3.0
3
+ Version: 0.4.3
4
4
  Summary: Survey microdata as DataFrames.
5
5
  Home-page: http://github.com/PSLmodels/microdf
6
6
  Author: Max Ghenis
7
7
  Author-email: max@ubicenter.org
8
8
  License: MIT
9
- Platform: UNKNOWN
10
- Requires-Dist: matplotlib
11
- Requires-Dist: matplotlib-label-lines
9
+ License-File: LICENSE
12
10
  Requires-Dist: numpy
13
11
  Requires-Dist: pandas
14
- Requires-Dist: seaborn
12
+ Provides-Extra: charts
13
+ Requires-Dist: seaborn ; extra == 'charts'
14
+ Requires-Dist: matplotlib ; extra == 'charts'
15
+ Requires-Dist: matplotlib-label-lines ; extra == 'charts'
15
16
  Provides-Extra: taxcalc
16
17
  Requires-Dist: taxcalc ; extra == 'taxcalc'
17
18
 
18
- UNKNOWN
19
-
20
-
@@ -1,24 +1,24 @@
1
1
  microdf/__init__.py,sha256=5YubH2TcCDG-e89pM22C0JhcRZHGcHwSnHHFo5GSPrQ,3463
2
2
  microdf/_optional.py,sha256=pZR05BhAsE744HHp2YTydheX_ovqeLA1gvQewLnwXpY,2738
3
3
  microdf/agg.py,sha256=j6CHm-ZgzdZsYk3c2i07DrmF6SS-woiavB-kgsLz3aE,3127
4
- microdf/chart_utils.py,sha256=jV0FzvECI-G9fH7FlJ98NppteQn3bOIb4udulS9YCUg,666
5
- microdf/charts.py,sha256=FvFSDILCXAnBWF1iA9mBiCJVRcSU6WtLtC4gkfiS7-w,1736
4
+ microdf/chart_utils.py,sha256=OK2QWBrUUktSy_oEDKXqHIjwQzRSV00MS4PBvwBK2iw,934
5
+ microdf/charts.py,sha256=MlsZl3TGAOFrTtN4jF4FMDcNQZjFdY6URg_DXNdw3nQ,1997
6
6
  microdf/concat.py,sha256=eIwf-LOTi8CUqh913IKgTbXXg6i1_c3ghfJuSL13S58,886
7
7
  microdf/constants.py,sha256=CJ1kRSvYQmxkEf-4-Oxk5Y4ZqGPegpk8HfoF_LR6qSI,960
8
8
  microdf/custom_taxes.py,sha256=2tOfIMP-vtaBnvwYhk8K-BZohoRLyPWKqhjErLujc7s,6049
9
- microdf/generic.py,sha256=veDc-cccU9JUtpVOzR25vTSmaqr_lUx5slfcncDWnfU,26544
9
+ microdf/generic.py,sha256=_iJ604ciIsOO9P3y1YK7eMCvqZ-fthZvKUOROiXa8QA,26687
10
10
  microdf/income_measures.py,sha256=ya2iAGDdJmrUMHRN2wd8MhE7hFoyFa8QDZPYaKgdv_w,2045
11
11
  microdf/inequality.py,sha256=M4SBe5V7YwHO-63VQk0CU81VB4rZz0u0waW0oE5nfA0,5910
12
- microdf/io.py,sha256=RkBXUuTxnx8nebAa_w0QaytRfQDIoBzGXtujyOtnovo,727
12
+ microdf/io.py,sha256=8jBVUqQ7kzOhgHDhHDYY7WK6t6okYc5LoloJxh8JSA0,888
13
13
  microdf/poverty.py,sha256=GDCTM7doJSFd4jJvSSX5BLVUh6Sd7NGNUgXWKS69M6A,4615
14
- microdf/style.py,sha256=7sX_0arQHdjDqo_9qzKscdS1JrDAUXRMYhMKU6bdZUI,1434
14
+ microdf/style.py,sha256=O5ebjIWNsq35UbOclOj4tzY_Evy2S-SZQapqcTfEo2o,1718
15
15
  microdf/tax.py,sha256=sErlnCQLTPTTDL61T3kDYGYEytIxJFf-m64-b-K2R5w,3129
16
16
  microdf/taxcalc.py,sha256=5Ixl_hTfz8iQXKRnRuj5HZm2Elun6TgU-o3mZMgjPkw,5056
17
17
  microdf/ubi.py,sha256=QG9gs6rOnHCIPeSArwemVe4uDsd5oswnJ3wmo4MxDGI,1581
18
18
  microdf/utils.py,sha256=9QFu7pZd9y09RvCebERM4SN_DedBogEE2oK-KG2YxFc,1795
19
19
  microdf/weighted.py,sha256=hekD_BitDTK9Q6HqzbWKhZQPFpfCfvQxcOntqdejycw,7246
20
- microdf_python-0.3.0.dist-info/LICENSE,sha256=uPs-ASYnzlldpf2z8jeRgQFeEH3FLhSuX0rw0OKWoDU,1067
21
- microdf_python-0.3.0.dist-info/METADATA,sha256=hFgPBXl7QvWhaUKHjdR3p6w3U44rMH_jybFMLSeYOz0,437
22
- microdf_python-0.3.0.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
23
- microdf_python-0.3.0.dist-info/top_level.txt,sha256=T2WFPTygQQMdS3GF8YpZ12DKfMGrspbZ3r7z-e3KfiM,8
24
- microdf_python-0.3.0.dist-info/RECORD,,
20
+ microdf_python-0.4.3.dist-info/LICENSE,sha256=uPs-ASYnzlldpf2z8jeRgQFeEH3FLhSuX0rw0OKWoDU,1067
21
+ microdf_python-0.4.3.dist-info/METADATA,sha256=OZcOwOjbO29W80NUjPS3f7-vlPK_LDnbx5ZtomVjL0Q,514
22
+ microdf_python-0.4.3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
23
+ microdf_python-0.4.3.dist-info/top_level.txt,sha256=T2WFPTygQQMdS3GF8YpZ12DKfMGrspbZ3r7z-e3KfiM,8
24
+ microdf_python-0.4.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.36.2)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5