How to use infer_series_statistics method in pandera

Best Python code snippet using pandera_python

test_schema_statistics.py

Source:test_schema_statistics.py Github

copy

Full Screen

...202 ],203)204def test_infer_series_schema_statistics(series, expectation) -> None:205 """Test series statistics are correctly inferred."""206 statistics = schema_statistics.infer_series_statistics(series)207 _test_statistics(statistics, expectation)208@pytest.mark.parametrize(209 "null_index, series, expectation",210 [211 *[212 [213 0,214 pd.Series([1, 2, 3], dtype=str(data_type)),215 {216 # introducing nans to integer arrays upcasts to float217 "dtype": DEFAULT_FLOAT,218 "nullable": True,219 "checks": {220 "greater_than_or_equal_to": 2,221 "less_than_or_equal_to": 3,222 },223 "name": None,224 },225 ]226 for data_type in INTEGER_TYPES227 ],228 [229 # introducing nans to bool arrays upcasts to float except230 # for pandas >= 1.3.0231 0,232 pd.Series([True, False, True, False]),233 {234 "dtype": (235 pandas_engine.Engine.dtype(pa.Object)236 if pa.PANDAS_1_3_0_PLUS237 else DEFAULT_FLOAT238 ),239 "nullable": True,240 "checks": (241 None242 if pa.PANDAS_1_3_0_PLUS243 else {244 "greater_than_or_equal_to": 0,245 "less_than_or_equal_to": 1,246 }247 ),248 "name": None,249 },250 ],251 [252 0,253 pd.Series(["a", "b", "c", "a"], dtype="category"),254 {255 "dtype": pandas_engine.Engine.dtype(pa.Category),256 "nullable": True,257 "checks": {"isin": ["a", "b", "c"]},258 "name": None,259 },260 ],261 [262 0,263 pd.Series(["a", "b", "c", "a"], name="str_series"),264 {265 "dtype": pandas_engine.Engine.dtype(str),266 "nullable": True,267 "checks": None,268 "name": "str_series",269 },270 ],271 [272 2,273 pd.Series(pd.to_datetime(["20180101", "20180102", "20180103"])),274 {275 "dtype": pandas_engine.Engine.dtype(pa.DateTime),276 "nullable": True,277 "checks": {278 "greater_than_or_equal_to": pd.Timestamp("20180101"),279 "less_than_or_equal_to": pd.Timestamp("20180102"),280 },281 "name": None,282 },283 ],284 ],285)286def test_infer_nullable_series_schema_statistics(287 null_index, series, expectation288):289 """Test nullable series statistics are correctly inferred."""290 series.iloc[null_index] = None291 statistics = schema_statistics.infer_series_statistics(series)292 _test_statistics(statistics, expectation)293@pytest.mark.parametrize(294 "null_values, dtype",295 (296 ([pd.NaT, pd.NaT], pandas_engine.Engine.dtype(pa.DateTime)),297 ([np.nan, np.nan], DEFAULT_FLOAT),298 ([None, None], pandas_engine.Engine.dtype(pa.Object)),299 # Mixed 'null' types300 ([pd.NaT, np.nan], pandas_engine.Engine.dtype(pa.DateTime)),301 ([None, pd.NaT], pandas_engine.Engine.dtype(pa.DateTime)),302 ([None, np.nan], DEFAULT_FLOAT),303 ),304)305def test_empty_series_schema_statistics(null_values, dtype):306 """Test 'empty' series statistics are correctly inferred."""307 series = pd.Series(null_values)308 statistics = schema_statistics.infer_series_statistics(series)309 expectation = {310 "dtype": dtype,311 "nullable": True,312 "checks": None,313 "name": None,314 }315 _test_statistics(statistics, expectation)316@pytest.mark.parametrize(317 "index, expectation",318 [319 [320 pd.RangeIndex(20),321 [322 {...

Full Screen

Full Screen

schema_inference.py

Source:schema_inference.py Github

copy

Full Screen

...64 """Infer a SeriesSchema from a pandas DataFrame.65 :param series: Series object to infer.66 :returns: SeriesSchema67 """68 series_statistics = infer_series_statistics(series)69 schema = SeriesSchema(70 dtype=series_statistics["dtype"],71 checks=parse_check_statistics(series_statistics["checks"]),72 nullable=series_statistics["nullable"],73 name=series_statistics["name"],74 coerce=True,75 )76 schema._is_inferred = True...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful