Skip to content

Commit 6ce772c

Browse files
authored
Add AgeFractional logical type (#1112)
* Add AgeFractional logical type * fix imports * add release note * pr comment * update serialization schema
1 parent b073a8c commit 6ce772c

File tree

11 files changed

+53
-16
lines changed

11 files changed

+53
-16
lines changed

docs/source/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Logical Types
138138

139139
Address
140140
Age
141+
AgeFractional
141142
AgeNullable
142143
Boolean
143144
BooleanNullable

docs/source/guides/logical_types_and_semantic_tags.ipynb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,22 @@
174174
"\n",
175175
"##### Age\n",
176176
"\n",
177-
"Represents Logical Types that contain non-negative numbers indicating a person’s age.\n",
177+
"Represents Logical Types that contain whole numbers indicating a person’s age.\n",
178178
"\n",
179179
"- **physical type**: `int64`\n",
180180
"- **standard tags**: `{'numeric'}`\n",
181181
"\n",
182+
"##### AgeFractional\n",
183+
"\n",
184+
"Represents Logical Types that contain non-negative floating point numbers indicating a person’s age. May contain null values.\n",
185+
"\n",
186+
"- **physical type**: `float64`\n",
187+
"- **standard tags**: `{'numeric'}`\n",
188+
"\n",
189+
"\n",
182190
"##### AgeNullable\n",
183191
"\n",
184-
"Represents Logical Types that contain non-negative numbers indicating a person’s age. May contain null values.\n",
192+
"Represents Logical Types that contain whole numbers indicating a person’s age. May contain null values.\n",
185193
"\n",
186194
"- **physical type**: `Int64`\n",
187195
"- **standard tags**: `{'numeric'}`\n",

docs/source/guides/working_with_types_and_tags.ipynb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
"The standard tags are as follows:\n",
101101
"\n",
102102
"* `'numeric'` - The tag applied to numeric Logical Types.\n",
103+
" * `Age`\n",
104+
" * `AgeFractional`\n",
105+
" * `AgeNullable`\n",
103106
" * `Integer`\n",
104107
" * `IntegerNullable`\n",
105108
" * `Double`\n",

docs/source/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Future Release
99
* Add ``'passthrough'`` and ``'ignore'`` to tags in ``list_semantic_tags`` (:pr:`1094`)
1010
* Add initialize with partial table schema (:pr:`1100`)
1111
* Apply ordering specified by the ``Ordinal`` logical type to underlying series (:pr:`1097`)
12+
* Add ``AgeFractional`` logical type (:pr:`1112`)
1213
* Fixes
1314
* Changes
1415
* Documentation Changes

woodwork/logical_types.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class Address(LogicalType):
7474

7575

7676
class Age(LogicalType):
77-
"""Represents Logical Types that contain non-negative numbers indicating a person's age. Has 'numeric' as a standard tag.
77+
"""Represents Logical Types that contain whole numbers indicating a person's age.
78+
Has 'numeric' as a standard tag.
7879
7980
Examples:
8081
.. code-block:: python
@@ -86,8 +87,23 @@ class Age(LogicalType):
8687
standard_tags = {'numeric'}
8788

8889

90+
class AgeFractional(LogicalType):
91+
"""Represents Logical Types that contain non-negative floating point numbers indicating a person's age.
92+
Has 'numeric' as a standard tag. May also contain null values.
93+
94+
Examples:
95+
.. code-block:: python
96+
97+
[0.34, 24.34, 45.0]
98+
[30.5, 62.82, np.nan]
99+
"""
100+
primary_dtype = 'float64'
101+
standard_tags = {'numeric'}
102+
103+
89104
class AgeNullable(LogicalType):
90-
"""Represents Logical Types that contain non-negative numbers indicating a person's age. Has 'numeric' as a standard tag. May also contain null values.
105+
"""Represents Logical Types that contain whole numbers indicating a person's age.
106+
Has 'numeric' as a standard tag. May also contain null values.
91107
92108
Examples:
93109
.. code-block:: python

woodwork/serialize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616
from woodwork.utils import _is_s3, _is_url
1717

18-
SCHEMA_VERSION = '11.1.0'
18+
SCHEMA_VERSION = '11.1.1'
1919
FORMATS = ['csv', 'pickle', 'parquet', 'arrow', 'feather', 'orc']
2020

2121

woodwork/table_accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def mutual_information_dict(self, num_bins=10, nrows=None, include_index=False,
779779
"""
780780
Calculates mutual information between all pairs of columns in the DataFrame that
781781
support mutual information. Logical Types that support mutual information are as
782-
follows: Age, AgeNullable, Boolean, BooleanNullable, Categorical, CountryCode, Datetime, Double,
782+
follows: Age, AgeFractional, AgeNullable, Boolean, BooleanNullable, Categorical, CountryCode, Datetime, Double,
783783
Integer, IntegerNullable, Ordinal, PostalCode, and SubRegionCode
784784
785785
Args:
@@ -811,7 +811,7 @@ def mutual_information_dict(self, num_bins=10, nrows=None, include_index=False,
811811
def mutual_information(self, num_bins=10, nrows=None, include_index=False, callback=None):
812812
"""Calculates mutual information between all pairs of columns in the DataFrame that
813813
support mutual information. Logical Types that support mutual information are as
814-
follows: Age, AgeNullable, Boolean, BooleanNullable, Categorical, CountryCode, Datetime, Double,
814+
follows: Age, AgeFractional, AgeNullable, Boolean, BooleanNullable, Categorical, CountryCode, Datetime, Double,
815815
Integer, IntegerNullable, Ordinal, PostalCode, and SubRegionCode
816816
817817
Args:

woodwork/tests/accessor/test_statistics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from woodwork.logical_types import (
1111
URL,
1212
Age,
13+
AgeFractional,
1314
AgeNullable,
1415
Boolean,
1516
BooleanNullable,
@@ -291,7 +292,7 @@ def test_describe_accessor_method(describe_df):
291292
datetime_ltypes = [Datetime]
292293
formatted_datetime_ltypes = [Datetime(datetime_format='%Y~%m~%d')]
293294
timedelta_ltypes = [Timedelta]
294-
nullable_numeric_ltypes = [Double, IntegerNullable, AgeNullable]
295+
nullable_numeric_ltypes = [Double, IntegerNullable, AgeNullable, AgeFractional]
295296
non_nullable_numeric_ltypes = [Integer, Age]
296297
natural_language_ltypes = [EmailAddress, Filepath, PersonFullName, IPAddress,
297298
PhoneNumber, URL]

woodwork/tests/accessor/test_table_accessor.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
URL,
2727
Address,
2828
Age,
29+
AgeFractional,
2930
AgeNullable,
3031
Boolean,
3132
BooleanNullable,
@@ -878,16 +879,17 @@ def test_sets_float64_dtype_on_init():
878879
pd.Series([1.1, np.nan, 3], name=column_name),
879880
]
880881

881-
logical_type = Double
882+
logical_types = [Double, AgeFractional]
882883
for series in series_list:
883884
series = series.astype('object')
884-
ltypes = {
885-
column_name: logical_type,
886-
}
887-
df = pd.DataFrame(series)
888-
df.ww.init(logical_types=ltypes)
889-
assert isinstance(df.ww.columns[column_name].logical_type, logical_type)
890-
assert df[column_name].dtype == logical_type.primary_dtype
885+
for logical_type in logical_types:
886+
ltypes = {
887+
column_name: logical_type,
888+
}
889+
df = pd.DataFrame(series)
890+
df.ww.init(logical_types=ltypes)
891+
assert isinstance(df.ww.columns[column_name].logical_type, logical_type)
892+
assert df[column_name].dtype == logical_type.primary_dtype
891893

892894

893895
def test_sets_datetime64_dtype_on_init():

woodwork/tests/utils/test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import woodwork as ww
1010
from woodwork.logical_types import (
1111
Age,
12+
AgeFractional,
1213
AgeNullable,
1314
Boolean,
1415
BooleanNullable,
@@ -383,6 +384,7 @@ def test_get_valid_mi_types():
383384
valid_types = get_valid_mi_types()
384385
expected_types = [
385386
Age,
387+
AgeFractional,
386388
AgeNullable,
387389
Boolean,
388390
BooleanNullable,

0 commit comments

Comments
 (0)